FEATURE: Localization fallbacks (server-side)#2
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*
|
bugbot run |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
| # 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 |
There was a problem hiding this comment.
Translation cache stale after site default locale change
Low Severity
The FallbackLocaleList#[] dynamically includes SiteSetting.default_locale in the fallback chain, but the translation LRU cache key in the translate method is "#{key}#{config.locale}#{config.backend.object_id}", which doesn't account for the site default locale. Previously the fallback chain was static ([locale, :en]), so the cache key was sufficient. Now, if a site admin changes the default locale, cached translations resolved through fallback will be stale until the process restarts or the LRU evicts them — there's no I18n.reload! triggered on default_locale changes.


Test 9
Summary by CodeRabbit
Release Notes
Refactor
Chore
✏️ Tip: You can customize this high-level summary in your review settings.
Replicated from ai-code-review-evaluation/discourse-coderabbit#9
Note
Medium Risk
Touches global I18n initialization and per-request locale setup, which can affect translation resolution and runtime loading behavior across the app. Risk is moderated by the small, targeted surface area but could impact production localization if fallback ordering/loading is incorrect.
Overview
Adds a new
config/initializers/i18n.rbthat centralizes I18n setup: enables pluralization, wires inI18n::Backend::Fallbacks, and defines a custom fallback order (requested locale →SiteSetting.default_locale→:en).Moves fallback behavior out of environment configs by removing
config.i18n.fallbacks = truefrom production/profile-related configs, and updates request handling to proactively load all fallback locales viaI18n.fallbacks.ensure_loaded!inApplicationController#set_locale.translate_acceleratoris extended withI18n.ensure_loaded!(locale)to support this on-demand loading model.Written by Cursor Bugbot for commit ecfa17b. Configure here.