-
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 | ||||||
|
||||||
| [locale, SiteSetting.default_locale.to_sym, :en].uniq.compact | |
| [locale, SiteSetting.default_locale&.to_sym, :en].uniq.compact |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -59,6 +59,11 @@ def load_locale(locale) | |
| end | ||
| end | ||
|
|
||
| def ensure_loaded!(locale) | ||
| @loaded_locales ||= [] | ||
| load_locale locale unless @loaded_locales.include?(locale) | ||
| end | ||
|
Comment on lines
+62
to
+65
|
||
|
|
||
| def translate(key, *args) | ||
| load_locale(config.locale) unless @loaded_locales.include?(config.locale) | ||
| return translate_no_cache(key, *args) if args.length > 0 | ||
|
|
||
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.
The class name
FallbackLocaleListsuggests it's a list, but it inherits fromHash. This is misleading since the class behaves more like a locale resolver than a collection. Consider renaming toLocaleFallbackResolverorFallbackLocaleResolverto better reflect its purpose.