FEATURE: Localization fallbacks (server-side)#3
Open
akshayutture-augment wants to merge 1 commit into
Open
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*
There was a problem hiding this comment.
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
FallbackLocaleListclass 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 |
There was a problem hiding this comment.
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Test 9
Replicated from ai-code-review-evaluation/discourse-copilot#9