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

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

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 ShashankFC requested a review from Copilot January 30, 2026 10:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces server-side localization fallbacks for improved internationalization support. The system now intelligently cascades through the requested language, site default, and English when translations are missing, with optimized on-demand locale loading.

Changes:

  • Implemented custom fallback logic that resolves translations through user locale → site default → English
  • Consolidated i18n initialization from deprecated environment configs into a centralized initializer
  • Added on-demand locale loading to ensure fallback locales are loaded when needed

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
lib/freedom_patches/translate_accelerator.rb Added ensure_loaded! helper method for on-demand locale loading
config/initializers/pluralization.rb Removed deprecated pluralization initializer (moved to i18n.rb)
config/initializers/i18n.rb New centralized i18n configuration with custom fallback implementation
config/environments/profile.rb Removed Rails default fallback configuration
config/environments/production.rb Removed Rails default fallback configuration
config/cloud/cloud66/files/production.rb Removed Rails default fallback configuration
app/controllers/application_controller.rb Added fallback locale loading trigger in set_locale

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +62 to +65
def ensure_loaded!(locale)
@loaded_locales ||= []
load_locale locale unless @loaded_locales.include?(locale)
end

Copilot AI Jan 30, 2026

Copy link

Choose a reason for hiding this comment

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

The @loaded_locales instance variable is initialized here but also initialized in the load_locale method (line 59). This duplicated initialization logic could lead to inconsistency. Consider initializing @loaded_locales once in an initialize method or at the class level to ensure consistency across methods.

Copilot uses AI. Check for mistakes.
# 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

Copilot AI Jan 30, 2026

Copy link

Choose a reason for hiding this comment

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

If SiteSetting.default_locale returns nil, calling .to_sym on it will raise a NoMethodError. The fallback chain should handle the case where SiteSetting.default_locale might be nil before calling .to_sym. Consider adding a nil check or using &.to_sym safe navigation.

Suggested change
[locale, SiteSetting.default_locale.to_sym, :en].uniq.compact
[locale, SiteSetting.default_locale&.to_sym, :en].uniq.compact

Copilot uses AI. Check for mistakes.
I18n.backend.class.send(:include, I18n::Backend::Fallbacks)

# Configure custom fallback order
class FallbackLocaleList < Hash

Copilot AI Jan 30, 2026

Copy link

Choose a reason for hiding this comment

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

The class name FallbackLocaleList suggests it's a list, but it inherits from Hash. This is misleading since the class behaves more like a locale resolver than a collection. Consider renaming to LocaleFallbackResolver or FallbackLocaleResolver to better reflect its purpose.

Copilot uses AI. Check for mistakes.
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.

3 participants