Skip to content

FEATURE: Localization fallbacks (server-side)#3

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

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

Conversation

@akshayutture-augment

Copy link
Copy Markdown

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*
Copilot AI review requested due to automatic review settings November 14, 2025 23:12

Copilot AI 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.

Pull Request Overview

This PR implements server-side localization fallbacks for I18n, replacing Rails' built-in fallback configuration with a custom implementation that provides more control over the fallback chain (user locale → site locale → English).

  • Introduces a custom FallbackLocaleList class to manage locale fallback order
  • Adds ensure_loaded! method to preload locale files before translation lookups
  • Removes Rails environment-specific fallback configurations in favor of centralized initialization

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
lib/freedom_patches/translate_accelerator.rb Adds ensure_loaded! method to support preloading locales
config/initializers/pluralization.rb Removes pluralization configuration (moved to new initializer)
config/initializers/i18n.rb Creates new centralized I18n configuration with custom fallback implementation
config/environments/profile.rb Removes Rails fallback configuration
config/environments/production.rb Removes Rails fallback configuration
config/cloud/cloud66/files/production.rb Removes Rails fallback configuration
app/controllers/application_controller.rb Calls ensure_loaded! to preload fallback locales

# 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 Nov 14, 2025

Copy link

Choose a reason for hiding this comment

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

The compact method has no effect here since to_sym will never return nil. If SiteSetting.default_locale could be nil, it would raise a NoMethodError on to_sym before compact is called. Either add nil handling before calling to_sym, or remove the unnecessary compact call.

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.
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