Skip to content

FEATURE: Localization fallbacks (server-side)#2

Open
ShashankFC wants to merge 1 commit into
localization-system-prefrom
localization-system-post
Open

FEATURE: Localization fallbacks (server-side)#2
ShashankFC wants to merge 1 commit into
localization-system-prefrom
localization-system-post

Conversation

@ShashankFC

@ShashankFC ShashankFC commented Jan 22, 2026

Copy link
Copy Markdown

Test 9

Summary by CodeRabbit

Release Notes

  • Refactor

    • Restructured internationalization fallback system with optimized on-demand locale loading for improved efficiency.
    • Enhanced locale fallback resolution to intelligently cascade through requested language, site default, and English.
    • Consolidated locale initialization logic for better maintainability.
  • Chore

    • Removed deprecated pluralization backend integration from environment configurations.

✏️ 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.rb that centralizes I18n setup: enables pluralization, wires in I18n::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 = true from production/profile-related configs, and updates request handling to proactively load all fallback locales via I18n.fallbacks.ensure_loaded! in ApplicationController#set_locale. translate_accelerator is extended with I18n.ensure_loaded!(locale) to support this on-demand loading model.

Written by Cursor Bugbot for commit ecfa17b. Configure here.

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*
@ShashankFC

Copy link
Copy Markdown
Author

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Additional Locations (1)

Fix in Cursor Fix in Web

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants