Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up locale fallback code #101

Merged
merged 1 commit into from
Dec 13, 2021
Merged

Clean up locale fallback code #101

merged 1 commit into from
Dec 13, 2021

Conversation

movermeyer
Copy link
Collaborator

@movermeyer movermeyer commented Dec 9, 2021

What are you trying to accomplish?

Locales with more than two segments (e.g., zh-Hant-HK) were getting an incorrect fallback chain.

What approach did you choose and why?

I changed the code to use parents.first instead of self_and_parents.last.

Beyond that, I pulled out the fallback code into its own file, and structured it in a similar fashion as ruby-i18n's I18n::Locale::Fallbacks.

I also changed the keys and values in ParentLocales to be symbols, which simplifies the code (less conversions).

What should reviewers focus on?

It's still not fully correct for locales that contain scripts (e.g., ff-Adlm-GH), see #103.
But that will be a separate PR.

The impact of these changes

Fixes #102

Testing

...

@movermeyer movermeyer force-pushed the movermeyer/fix_fallbacks branch 3 times, most recently from 53f8ae2 to 9eb64d5 Compare December 9, 2021 16:52
It was breaking on locales with more than two segments (e.g., `zh-Hant-HK`)

Beyond that, I pulled out the fallback code and exposed it so that downstream consumers can use it too.
I structured it in a similar manner as `ruby-i18n`'s [`I18n::Locale::Fallbacks`](https://github.com/ruby-i18n/i18n/blob/535459ad1201e7cc97a071bd5d9f0e1d5406069e/lib/i18n/locale/fallbacks.rb).

I also changed the keys and values in `ParentLocales` to be symbols, which simplifies the code.

It's still not fully correct for locales that contain scripts (e.g., `ff-Adlm-GH`).
That will be a different commit.
@movermeyer movermeyer force-pushed the movermeyer/fix_fallbacks branch from 9eb64d5 to 17e858c Compare December 9, 2021 16:58
@movermeyer movermeyer marked this pull request as ready for review December 9, 2021 17:46
@movermeyer movermeyer requested a review from Korri December 9, 2021 17:46
Copy link
Collaborator

@Korri Korri left a comment

Choose a reason for hiding this comment

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

@movermeyer movermeyer merged commit 123e959 into main Dec 13, 2021
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.

Fallbacks for locales with more than 2 segments are incorrect
2 participants