-
Notifications
You must be signed in to change notification settings - Fork 1
FEATURE: Localization fallbacks (server-side) #9
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-copilot
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! | ||||||
| self[I18n.locale].each { |l| I18n.ensure_loaded! l } | ||||||
|
||||||
| self[I18n.locale].each { |l| I18n.ensure_loaded! l } | |
| self[I18n.locale].each { |l| TranslateAccelerator.ensure_loaded! l } |
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 | ||
|
|
||
| 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.
This array is created on every access to the fallback list. Consider memoizing the result or caching it to avoid repeated array creation and method calls.