Skip to content

End a parent chain at root when :und is not a supported locale - #69

Closed
MrYawe wants to merge 1 commit into
elixir-localize:mainfrom
MrYawe:root-parent-chain
Closed

MrYawe wants to merge 1 commit into
elixir-localize:mainfrom
MrYawe:root-parent-chain

Conversation

@MrYawe

@MrYawe MrYawe commented Oct 29, 2026

Copy link
Copy Markdown

Fixes the English fallback reported in #68.

Locale.parent/1 builds the root tag with cldr_locale_id: :und, then with_cldr_locale_id/1 validates "und" again. When :und isn't a supported locale, that validation resolves it to the default locale, so every parent chain ended at :en instead of :und. As a result, RBNF's reject_und_spellout_stub/3 never saw root, and English answered for any spellout rule set the locale lacked. For example, Rbnf.to_string(2_000_000, :spellout_cardinal, locale: :ru) returned "two million". with_cldr_locale_id/1 now keeps root as :und, the same way cldr_locale_id_from/1 already resolves a bare root tag.

The new tests in supported_locales_test.exs remove :und from the supported locales. They check that parent chains still end at :und, and that the ru request returns UnknownRbnfRuleError. Both fail on main. The RBNF test erases the cached ru chain first, because put_supported_locales/1 doesn't clear it.

This doesn't change the nb/no question in #68.

@kipcole9

Copy link
Copy Markdown
Contributor

Thank you, this is correct and the tests are exactly the right ones.

I decided to fix it one level further back in f10f824, by making :und a supported locale whether or not it is configured, which also covers validate_locale("und") outside the parent walk and clears RBNF’s cached chains when the supported set changes.

Your test cases are in supported_locales_test.exs in that shape. With :und always supported the extra with_cldr_locale_id/1 clause is no longer reached, so I will close this in favour of f10f824.

Thank you again, much appreciated. Localize 1.5.0 will be out in the next 24 hours, including this fix.

@kipcole9 kipcole9 closed this Oct 29, 2026
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