-
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?
Conversation
The FallbackLocaleList object tells I18n::Backend::Fallbacks what order the languages should be attempted in. Because of the translate_accelerator patch, the SiteSetting.default_locale is *not* guaranteed to be fully loaded after the server starts, so a call to ensure_loaded! is added after the locale is set for the current user. The declarations of config.i18n.fallbacks = true in the environment files were actually garbage, because the I18n.default_locale was SiteSetting.default_locale, so there was nothing to fall back to. *derp*
| # 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 |
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.
[Security] Path Traversal in I18n.locale
- Problem: User-controlled
I18n.localeis used in locale loading without sanitization, risking arbitrary file reads via path traversal. - Fix: Strictly validate and sanitize
I18n.localeto allow only valid identifiers, preventing path traversal attacks.
| end | ||
| end | ||
|
|
||
| def ensure_loaded!(locale) |
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.
[Refactor] Intrusive Monkey-Patching of I18n Backend
- Problem: The
ensure_loaded!method is added toI18n::Backend::Simplevia a freedom patch, leading to fragility and potential conflicts. - Fix: Re-evaluate the need for monkey-patching; consider alternative, less intrusive ways to extend
I18nfunctionality or encapsulate the behavior.
| # 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 |
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.
[Refactor] Tight Coupling in I18n Fallback Logic
- Problem: The
FallbackLocaleListdirectly accessesSiteSetting.default_locale, tightly coupling the I18n fallback mechanism to a specific application configuration. - Fix: Decouple
FallbackLocaleListfromSiteSetting.default_localeby injecting the default locale or using a more generic configuration access pattern.
Test 9