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)

# Configure custom fallback order
class FallbackLocaleList < Hash

Copilot AI Jan 30, 2026

Copy link

Choose a reason for hiding this comment

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

The class name FallbackLocaleList suggests it's a list, but it inherits from Hash. This is misleading since the class behaves more like a locale resolver than a collection. Consider renaming to LocaleFallbackResolver or FallbackLocaleResolver to better reflect its purpose.

Copilot uses AI. Check for mistakes.
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

Copilot AI Jan 30, 2026

Copy link

Choose a reason for hiding this comment

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

If SiteSetting.default_locale returns nil, calling .to_sym on it will raise a NoMethodError. The fallback chain should handle the case where SiteSetting.default_locale might be nil before calling .to_sym. Consider adding a nil check or using &.to_sym safe navigation.

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.
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
Comment on lines +62 to +65

Copilot AI Jan 30, 2026

Copy link

Choose a reason for hiding this comment

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

The @loaded_locales instance variable is initialized here but also initialized in the load_locale method (line 59). This duplicated initialization logic could lead to inconsistency. Consider initializing @loaded_locales once in an initialize method or at the class level to ensure consistency across methods.

Copilot uses AI. Check for mistakes.

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