-
Notifications
You must be signed in to change notification settings - Fork 0
FEATURE: Localization fallbacks (server-side) #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: qodo_competitor_benchmark_full_1_base_feature_localization_fallbacks_server-side
Are you sure you want to change the base?
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*
| SiteSetting.default_locale | ||
| end | ||
|
|
||
| I18n.fallbacks.ensure_loaded! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[remediation_recommended] [Fallback locales not loaded in background jobs]
• The I18n.fallbacks.ensure_loaded! method is only called in set_locale for HTTP requests via controllers
• Background jobs set I18n.locale = SiteSetting.default_locale directly without loading fallback locale files
• When a translation is missing and I18n attempts fallback to :en or site default locale, those locale files won't be loaded
• This causes fallback translations to silently fail, potentially returning MissingTranslation errors in async operations
Agent Prompt
Copy this prompt and use it to remediate the issue with your preferred AI generation tools
## Issue description
Background jobs set `I18n.locale` directly without ensuring fallback locale files are loaded. When translations fall back to other locales, those locale files haven't been loaded, causing fallback translations to fail.
## Issue Context
The new `I18n.fallbacks.ensure_loaded!` method loads all locales in the fallback chain, but it's only called in `set_locale` for HTTP requests. Background jobs in `app/jobs/base.rb` set the locale directly.
## Fix Focus Areas
- app/jobs/base.rb[149-153] - Add `I18n.fallbacks.ensure_loaded!` after setting `I18n.locale`
| def ensure_loaded!(locale) | ||
| @loaded_locales ||= [] | ||
| load_locale locale unless @loaded_locales.include?(locale) | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[informational] [Thread safety pattern inconsistency]
• The new ensure_loaded! method initializes @loaded_locales with ||= [] outside any mutex protection
• The reload! method sets @loaded_locales = [] without synchronization
• There's a potential race condition where @loaded_locales could be modified between the nil check and subsequent operations
• While the existing translate method has the same pattern, duplicating it perpetuates the inconsistency
Agent Prompt
Copy this prompt and use it to remediate the issue with your preferred AI generation tools
## Issue description
The `ensure_loaded!` method accesses `@loaded_locales` outside mutex protection while `reload!` can modify it concurrently.
## Issue Context
The existing `translate` method has the same pattern, so this is consistent with current code but not ideal.
## Fix Focus Areas
- lib/freedom_patches/translate_accelerator.rb[62-65] - Consider adding a comment explaining why this is safe, or wrap access in mutex
Benchmark PR from qodo-benchmark/discourse-qodo#7