Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix I18n.load_path ordering conflicts with rails_i18n #489

Closed

Conversation

brianswko
Copy link

Addresses #432 and #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 brianswko marked this pull request as ready for review November 17, 2020 02:02
@brianswko
Copy link
Author

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!

@timfsw
Copy link

timfsw commented Feb 3, 2021

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

Are there any plans to merge it into master?

@joshRpowell
Copy link

poke @seejohnrun ☝🏻

@pacso
Copy link
Collaborator

pacso commented Oct 21, 2021

This looks good to me @seejohnrun

@seejohnrun
Copy link
Collaborator

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

@Faq
Copy link

Faq commented Sep 23, 2022

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

@krtschmr
Copy link

Yes. welcome to open source development 😢

@glaszig
Copy link
Contributor

glaszig commented Nov 9, 2023

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 added a commit to glaszig/ice_cube that referenced this pull request Nov 9, 2023
ice_cube would inject its locale files at the end of I18n.load_path due to its I18n module being autoloaded and thereby overwrite any customisation the user may have made in other locale files earlier in the laod path.

i fix this by injecting ice cube locales at gem load time so that the user has a chance to modify locale keys.

this also eliminates a bunch of delegation having a custom I18n module; IceCube::I18n is just the same as ::I18n if the i18n gem is available.

resolves ice-cube-ruby#489, ice-cube-ruby#432, ice-cube-ruby#431
glaszig added a commit to glaszig/ice_cube that referenced this pull request Nov 9, 2023
ice_cube would inject its locale files at the end of `I18n.load_path` due to its `IceCube::I18n` module being `autoload`ed and thereby overwrite any customisation the user may have made in other locale files earlier in the load path.

i fix this by injecting ice cube locales at gem load time so that the user has a chance to modify locale keys later.

this also eliminates a bunch of delegation having a custom I18n module; `IceCube::I18n` is just the same as ::I18n if the i18n gem is available.

resolves ice-cube-ruby#489, ice-cube-ruby#432, ice-cube-ruby#431
glaszig added a commit to glaszig/ice_cube that referenced this pull request Nov 9, 2023
ice_cube would inject its locale files at the end of `I18n.load_path` due to its `IceCube::I18n` module being `autoload`ed and thereby overwrite any customisation the user may have made in other locale files earlier in the load path.

i fix this by injecting ice cube locales at gem load time so that the user has a chance to modify locale keys later.

this also eliminates a bunch of delegation having a custom I18n module; `IceCube::I18n` is just the same as ::I18n if the i18n gem is available.

resolves ice-cube-ruby#489, ice-cube-ruby#432, ice-cube-ruby#431
glaszig added a commit to glaszig/ice_cube that referenced this pull request Nov 9, 2023
ice_cube would inject its locale files at the end of `I18n.load_path` due to its `IceCube::I18n` module being `autoload`ed and thereby overwrite any customisation the user may have made in other locale files earlier in the load path.

i fix this by injecting ice cube locales at gem load time so that the user has a chance to modify locale keys later.

this also eliminates a bunch of delegation having a custom I18n module; `IceCube::I18n` is just the same as ::I18n if the i18n gem is available.

resolves ice-cube-ruby#489, ice-cube-ruby#432, ice-cube-ruby#431
glaszig added a commit to glaszig/ice_cube that referenced this pull request May 28, 2024
ice_cube would inject its locale files at the end of `I18n.load_path` due to its `IceCube::I18n` module being `autoload`ed and thereby overwrite any customisation the user may have made in other locale files earlier in the load path.

i fix this by injecting ice cube locales at gem load time so that the user has a chance to modify locale keys later.

this also eliminates a bunch of delegation having a custom I18n module; `IceCube::I18n` is just the same as ::I18n if the i18n gem is available.

resolves ice-cube-ruby#489, ice-cube-ruby#432, ice-cube-ruby#431
@pacso pacso closed this in #546 May 30, 2024
pacso pushed a commit that referenced this pull request May 30, 2024
* fix I18n.load_path injection

ice_cube would inject its locale files at the end of `I18n.load_path` due to its `IceCube::I18n` module being `autoload`ed and thereby overwrite any customisation the user may have made in other locale files earlier in the load path.

i fix this by injecting ice cube locales at gem load time so that the user has a chance to modify locale keys later.

this also eliminates a bunch of delegation having a custom I18n module; `IceCube::I18n` is just the same as ::I18n if the i18n gem is available.

resolves #489, #432, #431

* use __dir__ expansion instead of __FILE__

* disable linter for I18n gymnastics
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants