ice_cube icon indicating copy to clipboard operation
ice_cube copied to clipboard

Fix I18n.load_path ordering conflicts with rails_i18n

Open brianswko opened this issue 4 years ago • 8 comments

Addresses https://github.com/seejohnrun/ice_cube/pull/432 and https://github.com/seejohnrun/ice_cube/issues/431

Since ice_cube's translation files are different from the defaults in rails-i18n, the translations are incorrect when ice_cube gets loaded.

For example, in french for the abbreviated form of January: rails-18n uses jan. https://github.com/svenfuchs/rails-i18n/blob/0cb422dc111b2dfa61a19b4740d04e72fb082d17/rails/locale/fr.yml#L23 ice_cube uses Jan https://github.com/seejohnrun/ice_cube/blob/d4443a29de12d277e04fede34df4d0e626a9634e/config/locales/fr.yml#L124

When ice_cube gets loaded, it overrides the default resulting in incorrect formatting. This change checks for the presence of rails_i18n in the load path. If it exists, it inserts ice_cube's files before them so that conflicts get overridden by the defaults. If rails_i18n is not in use, then they get added to the end of the load path.

brianswko avatar Nov 17 '20 01:11 brianswko

I've looked through the linked discussions and haven't really seen any movement on them recently. We've solved this for our own application by monkey patching IceCube::I18n in this exact way, let me know what you think!

brianswko avatar Nov 17 '20 02:11 brianswko

@brianswko Thanks for the fix - we issued the same problem and your solution worked great.

Are there any plans to merge it into master?

timfsw avatar Feb 03 '21 09:02 timfsw

poke @seejohnrun ☝🏻

joshRpowell avatar Sep 14 '21 13:09 joshRpowell

This looks good to me @seejohnrun

pacso avatar Oct 21 '21 22:10 pacso

Thank you! Do you mind making a quick update to the CHANGELOG then we'll get this merged?

seejohnrun avatar Oct 25 '21 14:10 seejohnrun

So looks like this PR stuck only because missing record for CHANGELOG?

Faq avatar Sep 23 '22 06:09 Faq

Yes. welcome to open source development 😢

krtschmr avatar Sep 23 '22 06:09 krtschmr

this just hit me by way of flaky test failures on ci. the problem is that IceCube::I18n gets autoloaded lazily which may happen after all other I18n gem initialization phases have been completed -- worse yet, at runtime.

the proper way would be to either

  • change the I18n.load_path initialisation to happen at gem load time as to not modify the load path after everything else was setup
  • or to respect user customisation and not muck around with the date, time and datetime namespaces

messed up load path:

[
 ...,
 "project/config/locales/en/views/integrations.yml",
 "project/.bundle/ruby/gems/3.0.0/gems/ice_cube-0.16.4/config/locales/de.yml",
 "project/.bundle/ruby/gems/3.0.0/gems/ice_cube-0.16.4/config/locales/en.yml",
 "project/.bundle/ruby/gems/3.0.0/gems/ice_cube-0.16.4/config/locales/es.yml",
 "project/.bundle/ruby/gems/3.0.0/gems/ice_cube-0.16.4/config/locales/fr.yml",
 "project/.bundle/ruby/gems/3.0.0/gems/ice_cube-0.16.4/config/locales/it.yml",
 "project/.bundle/ruby/gems/3.0.0/gems/ice_cube-0.16.4/config/locales/ja.yml",
 "project/.bundle/ruby/gems/3.0.0/gems/ice_cube-0.16.4/config/locales/nl.yml",
 "project/.bundle/ruby/gems/3.0.0/gems/ice_cube-0.16.4/config/locales/pt-BR.yml",
 "project/.bundle/ruby/gems/3.0.0/gems/ice_cube-0.16.4/config/locales/ru.yml",
 "project/.bundle/ruby/gems/3.0.0/gems/ice_cube-0.16.4/config/locales/sv.yml"
]

glaszig avatar Nov 09 '23 16:11 glaszig