Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ def set_locale
else
SiteSetting.default_locale
end

I18n.fallbacks.ensure_loaded!
end

def store_preloaded(key, json)
Expand Down
5 changes: 0 additions & 5 deletions config/cloud/cloud66/files/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@
# Specifies the header that your server uses for sending files
config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx

# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation can not be found)
config.i18n.fallbacks = true


# you may use other configuration here for mail eg: sendgrid

config.action_mailer.delivery_method = :smtp
Expand Down
4 changes: 0 additions & 4 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@

config.log_level = :info

# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation can not be found)
config.i18n.fallbacks = true

if GlobalSetting.smtp_address
settings = {
address: GlobalSetting.smtp_address,
Expand Down
4 changes: 0 additions & 4 deletions config/environments/profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@
# Specifies the header that your server uses for sending files
config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx

# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation can not be found)
config.i18n.fallbacks = true

# we recommend you use mailcatcher https://github.com/sj26/mailcatcher
config.action_mailer.smtp_settings = { address: "localhost", port: 1025 }

Expand Down
24 changes: 24 additions & 0 deletions config/initializers/i18n.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# order: after 02-freedom_patches.rb

# Include pluralization module
require 'i18n/backend/pluralization'
I18n::Backend::Simple.send(:include, I18n::Backend::Pluralization)

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

@cubic-dev-ai cubic-dev-ai Bot Feb 13, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: Inconsistent and potentially fragile inclusion pattern. Line 5 references the class directly (I18n::Backend::Simple), but this line goes through the instance (I18n.backend.class). If the backend is ever wrapped (e.g., I18n::Backend::Chain), this would include Fallbacks into the wrong class. Consider using the class directly for consistency and robustness.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At config/initializers/i18n.rb, line 9:

<comment>Inconsistent and potentially fragile inclusion pattern. Line 5 references the class directly (`I18n::Backend::Simple`), but this line goes through the instance (`I18n.backend.class`). If the backend is ever wrapped (e.g., `I18n::Backend::Chain`), this would include `Fallbacks` into the wrong class. Consider using the class directly for consistency and robustness.</comment>

<file context>
@@ -0,0 +1,24 @@
+
+# Include fallbacks module
+require 'i18n/backend/fallbacks'
+I18n.backend.class.send(:include, I18n::Backend::Fallbacks)
+
+# Configure custom fallback order
</file context>
Fix with Cubic


# Configure custom fallback order
class FallbackLocaleList < Hash
def [](locale)
# 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
end

def ensure_loaded!
self[I18n.locale].each { |l| I18n.ensure_loaded! l }
end
end
I18n.fallbacks = FallbackLocaleList.new
2 changes: 0 additions & 2 deletions config/initializers/pluralization.rb

This file was deleted.

5 changes: 5 additions & 0 deletions lib/freedom_patches/translate_accelerator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ def load_locale(locale)
end
end

def ensure_loaded!(locale)
@loaded_locales ||= []
load_locale locale unless @loaded_locales.include?(locale)
end

def translate(key, *args)
load_locale(config.locale) unless @loaded_locales.include?(config.locale)
return translate_no_cache(key, *args) if args.length > 0
Expand Down