Skip to content

chore: Improve locale affinity logic with LanguageUtils#19

Merged
ericfjosne merged 1 commit intomainfrom
chore-Improve-locale-affinity-logic
Jun 11, 2025
Merged

chore: Improve locale affinity logic with LanguageUtils#19
ericfjosne merged 1 commit intomainfrom
chore-Improve-locale-affinity-logic

Conversation

@ericfjosne
Copy link
Copy Markdown
Collaborator

@ericfjosne ericfjosne commented Jun 11, 2025

We can improve and optimize the locale affinity logic by making use of the newly introduced LanguageUtils class.

Instead of relying on a score-based affinity only, we first calculate a "same language" affinity by testing for corresponding spoken language.

This actually has improved the results for several locales:

  • Locales for which the language code is sufficient to identity a language are now matched with an affinity SAME_OR_INTERCHANGEABLE. The score based implementation enforces script matching, which was not a good fit for the affinity logic. For instance: hr (Croatian) and bs (Bosnian) are now matched with each other with an affinity SAME_OR_INTERCHANGEABLE, whether Bosnian is written in Latin or Cyrillic script, which is a more accurate outcome.
  • nn (Norwegian Nynorsk) is now matched with nb (Norwegian Bokmål) with an affinity SAME_OR_INTERCHANGEABLE instead of LOW which is a more accurate outcome.

It is also a nice logic optimization, as we won't systematically be calculating maximized locales (which is a costly operation).

Copy link
Copy Markdown

@RichardNysater RichardNysater left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice optimization

@ericfjosne ericfjosne merged commit 3b0a9b2 into main Jun 11, 2025
1 check passed
@ericfjosne ericfjosne deleted the chore-Improve-locale-affinity-logic branch June 23, 2025 09:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants