-
Notifications
You must be signed in to change notification settings - Fork 0
FEATURE: Localization fallbacks (server-side) #2
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
base: localization-system-pre
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,24 @@ | ||||||||||
| # order: after 02-freedom_patches.rb | ||||||||||
|
|
||||||||||
| # Include pluralization module | ||||||||||
| require 'i18n/backend/pluralization' | ||||||||||
| I18n::Backend::Simple.send(:include, I18n::Backend::Pluralization) | ||||||||||
|
|
||||||||||
| # Include fallbacks module | ||||||||||
| require 'i18n/backend/fallbacks' | ||||||||||
| I18n.backend.class.send(:include, I18n::Backend::Fallbacks) | ||||||||||
|
|
||||||||||
| # Configure custom fallback order | ||||||||||
| class FallbackLocaleList < Hash | ||||||||||
| def [](locale) | ||||||||||
| # user locale, site locale, english | ||||||||||
| # TODO - this can be extended to be per-language for a better user experience | ||||||||||
| # (e.g. fallback zh_TW to zh_CN / vice versa) | ||||||||||
| [locale, SiteSetting.default_locale.to_sym, :en].uniq.compact | ||||||||||
| end | ||||||||||
|
|
||||||||||
| def ensure_loaded! | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔷 Medium: ensure_loaded! depends on the global I18n.locale; if called before I18n.locale is set in set_locale, it may preload fallbacks for the previous locale and miss the intended one for the current request. Accept an optional locale to remove ordering dependence.
Suggested change
|
||||||||||
| self[I18n.locale].each { |l| I18n.ensure_loaded! l } | ||||||||||
| end | ||||||||||
| end | ||||||||||
| I18n.fallbacks = FallbackLocaleList.new | ||||||||||
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔷 Medium: Calling to_sym on a nil default locale will raise NoMethodError (e.g., during boot or misconfiguration), preventing fallbacks from resolving. Guard the conversion to keep this path safe.