Skip to content

Clean up Locale.matches in fluent-langneg #337

Closed

Description

@zbraniecki

Understanding this method is important for understanding the whole algorithm and I'm not fond of adding two boolean arguments to it. It's hard to follow what they mean when the method is called. In fact, I think I largely preferred the old code which used an explicit * to represent ranges.

A few suggestions on how to improve this code. I'm not saying all of them need to be applied at the same time, but I'd like to see this method improved somehow.

  • Remove the thisRange param as it is always true across all callsites, or start using it for exact matching.
  • Use an options dictionary: locale.matches(other, {thisRange: true, otherRange: true}).
  • Separate this code into multiple methods: exactMatches, matchesThisRange, matchesRanges.
  • Add a flag to Locale called undefinedAsRange and a method called toRange() which returns a new Locale instance based on the one the method was called on. match would inspect the value of the flag for both this and other and act accordingly.

Now, I understand that this code is based on the existing C++/Rust code. With that in mind, I think this can be moved to a follow-up. Please file it if you agree.

Originally posted by @stasm in #335

Activity

  1. eemeli commented on Jan 10, 2026

    @eemeli
    Member

    Done in #605.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions