Skip to content

FEATURE: Localization fallbacks (server-side) - #1771

Open
kaihao-zhao wants to merge 2 commits into
localization-system-prefrom
localization-system-post-hesol61-r1
Open

kaihao-zhao wants to merge 2 commits into
localization-system-prefrom
localization-system-post-hesol61-r1

Conversation

@kaihao-zhao

Copy link
Copy Markdown

See title.

riking and others added 2 commits July 15, 2015 10:17
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*
@github-actions github-actions Bot added the i18n label Sep 30, 2026

@unblocked-local-kaihao unblocked-local-kaihao 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.

3 issues found.

About Unblocked

Unblocked has been set up to automatically review your team's pull requests to identify genuine bugs and issues.

📖 Documentation — Learn more in our docs.

💬 Ask questions — Mention @unblocked-local-kaihao to request a review or summary, or ask follow-up questions.

👍 Give feedback — React to comments with 👍 or 👎 to help us improve.

⚙️ Customize — Adjust settings in your preferences.


# Include fallbacks module
require 'i18n/backend/fallbacks'
I18n.backend.class.send(:include, I18n::Backend::Fallbacks)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The globally enabled fallback backend does not distinguish pluralization metadata from ordinary messages. For :bs_BA on a Russian-default site, the configured chain is [:bs_BA, :ru, :en], so a missing i18n.plural.rule lookup can inherit Russian metadata. plurals.rb defines no :bs_BA rule; its Russian rule returns :few for count 2, while the Bosnian too_many_links entry defines only :zero, :one, and :other. Keep plural-rule metadata locale-specific rather than inheriting an incompatible site-language rule.

# 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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Translations now depend on SiteSetting.default_locale, but the global LRU in translate_accelerator.rb still keys results only by translation key, current locale, and backend identity. Changing the site default does not clear that cache, and multisite installations share it. For example, email_log.notification_already_read is absent in Swedish but present in German and French: a Swedish lookup cached with a German site default will keep returning German after switching to a French default or another site. Include the effective fallback chain in the cache key so these contexts cannot reuse each other's results.

SiteSetting.default_locale
end

I18n.fallbacks.ensure_loaded!

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is the only invocation of the fallback loader. Background jobs and rake tasks set I18n.locale without passing through this filter, while the translation accelerator still loads only the current locale and disables implicit translation-file loading. If English has not already been loaded, a Swedish-default worker cannot resolve English fallbacks—for example, PendingQueuedPostReminder sends queued_posts_reminder subject/body templates that are absent from Swedish, producing “translation missing” email text. Load the fallback chain at the translation boundary, using the effective requested locale, rather than relying solely on controller setup.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants