-
Notifications
You must be signed in to change notification settings - Fork 103
Open
Description
Assumption
- Without
config.eager_load = true
(I18n.eager_load!
don't run ). config.i18n.default_locale = :ja
( Locale other thanen
)
Steps to reproduce
- Access the Mission Controle Jobs dashboard (/jobs). I18n initial read is performed.
- Run MyApplicationCode. For example,
I18n.l(Time.current)
- Error occurred
Translation missing: ja.time.formats.default (I18n::MissingTranslationData)
Smaller reproduction code
(dev)> I18n.available_locales
=> [:ja, :en]
(dev)> I18n.backend.translations.keys
=> []
(dev)> I18n.with(config: MissionControl::Jobs::I18nConfig.new) { I18n.with_locale(:en) { I18n.l(Time.current) } }
=> "Fri, 23 May 2025 01:01:47 +0900"
(dev)> I18n.backend.translations.keys
=> [:en]
(dev)> I18n.l(Time.current)
(core):5:in '<main>': Translation missing: ja.time.formats.default (I18n::MissingTranslationData)
raise exception.respond_to?(:to_exception) ? exception.to_exception : exception
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
I think it is a bug related to ca09138.
First, I18n file reading is performed only once.
https://github.com/ruby-i18n/i18n/blob/4dddd855039b0c5a0b5b3b2df69783374058a7c9/lib/i18n/backend/simple.rb#L28-L30
Next, non-valid locale files are ignored.
https://github.com/ruby-i18n/i18n/blob/4dddd855039b0c5a0b5b3b2df69783374058a7c9/lib/i18n/backend/simple.rb#L37-L40
In other words, if the first read is performed with available_locales_set set to only en, non-en locales files will be ignored.
And no further reading of locale files will be performed.
Workaround
Run I18n.eager_load!
before available_locales_set is updated.
# config/initializers/i18n.rb
Rails.application.config.after_initialize { I18n.eager_load! }
# or config.eager_load = true
(dev)> I18n.available_locales
=> [:ja, :en]
(dev)> I18n.backend.translations.keys
=> []
(dev)> I18n.eager_load!
=> true
(dev)> I18n.backend.translations.keys
=> [:en, :ja]
(dev)> I18n.with(config: MissionControl::Jobs::I18nConfig.new) { I18n.with_locale(:en) { I18n.l(Time.current) } }
=> "Fri, 23 May 2025 01:02:44 +0900"
(dev)> I18n.backend.translations.keys
=> [:en, :ja]
(dev)> I18n.l(Time.current)
=> "2025年05月23日(金) 01時02分52秒 +0900"```
danielpuglisi
Metadata
Metadata
Assignees
Labels
No labels