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

Remove "overriding" translation keys #432

Conversation

MGPalmer
Copy link

Refs #431

All specs still pass, and this solves my overriding problem :)

… translations from the commonly used I18n systems.
@seejohnrun
Copy link
Collaborator

@MGPalmer thanks! do you mind adding a test or two to make sure formats can differ between locales? I'm unsure if they already exist

@MGPalmer
Copy link
Author

Hmm I'm not 100% sure I understand what you'd like me to test...

However, looking over the code and specs, it seems to me like only the ice_cube....formats.default is being used, and that is pretty well tested.

In fact, setting a different to_s format seems broken:

mssngr(dev)> IceCube.to_s_time_format = "aaaa"
=> "aaaa"
mssngr(dev)> IceCube.to_s_time_format
=> "%B %-d, %Y"

Maybe because the instance variable set is not actually used in this getter:

  # Defines the format used by IceCube when printing out Schedule#to_s.
  # Defaults to '%B %e, %Y'
  def self.to_s_time_format
    IceCube::I18n.t("ice_cube.date.formats.default")
  end

  # Sets the format used by IceCube when printing out Schedule#to_s.
  def self.to_s_time_format=(format)
    @to_s_time_format = format
  end

but that's a different ticket ;)

@avit
Copy link
Collaborator

avit commented Dec 20, 2017

but that's a different ticket ;)

Yes, it looks like that setting was just left behind after translations were added. We should remove since it does nothing, but that could break code which actually sets it, so it should have a deprecation first.

Copy link
Collaborator

@avit avit left a comment

Choose a reason for hiding this comment

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

Thanks for this!

Unfortunately, I'm not sure if we can use this approach since those default values come from a rails gem, which would make us dependent on loading all of rails:

It would be nice to use those strings, but we would like to avoid this dependency if possible. (I suspect there's a way to reuse them without a runtime gem dependency.)

The real problem is that previously, the load order was causing other problems and now it sounds like we are overwriting these fields the wrong way. I will take another look at the c7b305c commit which broke this.

default: "%a, %d %b %Y %H:%M:%S %z"
long: "%d %B %Y %H:%M"
short: "%d %b %H:%M"
pm: pm
Copy link
Collaborator

Choose a reason for hiding this comment

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

👮 dropped line ending at EOF

@avit
Copy link
Collaborator

avit commented Dec 20, 2017

Also I'm surprised why the test suite is all green here with these removed... something to look into.

I'm still not 100% on this: do all users who use i18n use it with i18n-rails anyway?

@MGPalmer
Copy link
Author

Also I'm surprised why the test suite is all green here with these removed... something to look into.

I might be mistaken, but my guess is that the format keys I've removed have not actually been used in ice_cube.

The real problem is that previously, the load order was causing other problems and now it sounds like we are overwriting these fields the wrong way. I will take another look at the c7b305c commit which broke this.

This would of course be my favorite solution!

@pacso
Copy link
Collaborator

pacso commented Oct 25, 2021

This will be resolved by #489

@pacso pacso closed this Oct 25, 2021
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 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.

4 participants