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

Exclude :count option on retrieve link #480

Merged
merged 1 commit into from
Oct 7, 2019

Conversation

Tietew
Copy link
Contributor

@Tietew Tietew commented Jun 7, 2019

Using both count: option and linked lookup in locale data causes unexpected I18n::InvalidPluralizationData.

Locale YAML:

en:
  link: :linked
  linked:
    foo:
      one: 1 foo
      other: %{count} foos

Code:

I18n.t(:'link.foo', count: 2)

Expected result:

"2 foos"

Actual result:

translation data {:foo=>{:one=>"1 foo", :other=>"%{count} foos"}} can not be used with :count => 2. key 'one' is missing. (I18n::InvalidPluralizationData)

@Tietew Tietew force-pushed the exclude-count-on-retrieve-link branch from a068ef2 to dcda31c Compare October 4, 2019 07:51
@Tietew
Copy link
Contributor Author

Tietew commented Oct 4, 2019

Bebased to current master.
But I'm not sure why Travis CI #735.7 is failed.

@radar
Copy link
Collaborator

radar commented Oct 7, 2019

Thanks @Tietew. This patch looks good to me :)

@radar radar merged commit 04a814b into ruby-i18n:master Oct 7, 2019
@CrAsH1101
Copy link
Contributor

It seems that some rails validation messages are broken after applying this patch.

Here is some model example with numericality validation:

class Zone < ApplicationRecord
  validates :idc,
    numericality: {
      only_integer: true,
      greater_than_or_equal_to: 50,
      less_than_or_equal_to: 120 }
end

Then, i console:

z = Zone.first
z.idc = 20
z.save
>>>I18n::MissingInterpolationArgument (missing interpolation argument :count in "must be greater than or equal to %{count}" ({:model=>"Zone", :attribute=>"Idc", :value=>20} given))

This is due to a count parameter being removed in chain of calls. File lib/i18n/backend/base.rb, line 146 of this commit.

Another example, with manual invocation. Variable "key" will be set to non-existing key in yaml files, but defaults contains symbol with existing key in yaml files. If default is not provided, standard error is returned. If default is provided, we get exception.

Loading development environment (Rails 5.0.7.2)
2.6.4 :001 > key = 'activerecord.models.zone.greather_than_or_equal_to'
 => "activerecord.models.zone.greather_than_or_equal_to"
2.6.4 :002 > defaults = [:'activerecords.errors.messages', :'errors.messages.greater_than_or_equal_to']
 => [:"activerecords.errors.messages", :"errors.messages.greater_than_or_equal_to"]
2.6.4 :003 > I18n.t(key, count: 1, value: 5)
 => "translation missing: en.activerecord.models.zone.greather_than_or_equal_to"
2.6.4 :004 > I18n.t(key, default: defaults, count: 1, value: 5)
Traceback (most recent call last):
       16: from /home/vagrant/.rvm/gems/ruby-2.6.4/bundler/gems/i18n-06aa9ac0685a/lib/i18n/backend/base.rb:128:in `default'
       15: from /home/vagrant/.rvm/gems/ruby-2.6.4/bundler/gems/i18n-06aa9ac0685a/lib/i18n/backend/base.rb:128:in `each'
       14: from /home/vagrant/.rvm/gems/ruby-2.6.4/bundler/gems/i18n-06aa9ac0685a/lib/i18n/backend/base.rb:129:in `block in default'
       13: from /home/vagrant/.rvm/gems/ruby-2.6.4/bundler/gems/i18n-06aa9ac0685a/lib/i18n/backend/base.rb:143:in `resolve'
       12: from /home/vagrant/.rvm/gems/ruby-2.6.4/bundler/gems/i18n-06aa9ac0685a/lib/i18n/backend/base.rb:143:in `catch'
       11: from /home/vagrant/.rvm/gems/ruby-2.6.4/bundler/gems/i18n-06aa9ac0685a/lib/i18n/backend/base.rb:146:in `block in resolve'
       10: from /home/vagrant/.rvm/gems/ruby-2.6.4/bundler/gems/i18n-06aa9ac0685a/lib/i18n.rb:186:in `translate'
        9: from /home/vagrant/.rvm/gems/ruby-2.6.4/bundler/gems/i18n-06aa9ac0685a/lib/i18n.rb:186:in `catch'
        8: from /home/vagrant/.rvm/gems/ruby-2.6.4/bundler/gems/i18n-06aa9ac0685a/lib/i18n.rb:190:in `block in translate'
        7: from /home/vagrant/.rvm/gems/ruby-2.6.4/bundler/gems/i18n-06aa9ac0685a/lib/i18n/backend/base.rb:61:in `translate'
        6: from /home/vagrant/.rvm/gems/ruby-2.6.4/bundler/gems/i18n-06aa9ac0685a/lib/i18n/backend/base.rb:187:in `interpolate'
        5: from /home/vagrant/.rvm/gems/ruby-2.6.4/bundler/gems/i18n-06aa9ac0685a/lib/i18n/interpolate/ruby.rb:19:in `interpolate'
        4: from /home/vagrant/.rvm/gems/ruby-2.6.4/bundler/gems/i18n-06aa9ac0685a/lib/i18n/interpolate/ruby.rb:23:in `interpolate_hash'
        3: from /home/vagrant/.rvm/gems/ruby-2.6.4/bundler/gems/i18n-06aa9ac0685a/lib/i18n/interpolate/ruby.rb:23:in `gsub'
        2: from /home/vagrant/.rvm/gems/ruby-2.6.4/bundler/gems/i18n-06aa9ac0685a/lib/i18n/interpolate/ruby.rb:31:in `block in interpolate_hash'
        1: from /home/vagrant/.rvm/gems/ruby-2.6.4/bundler/gems/i18n-06aa9ac0685a/lib/i18n/config.rb:99:in `block in missing_interpolation_argument_handler'
I18n::MissingInterpolationArgument (missing interpolation argument :count in "must be greater than or equal to %{count}" ({:value=>5} given))
2.6.4 :005 >

I have a working patch to solve this issue, let me know if you are interested.
This is not an issue prior to this pull request (tag 1.7.0 is working properly)

Regards,
Igor

@radar
Copy link
Collaborator

radar commented Dec 17, 2019

Hey @CrAsH1101, I'd love to see a patch to fix this issue. Please submit one :)

@CrAsH1101 CrAsH1101 mentioned this pull request Dec 17, 2019
@Tietew Tietew deleted the exclude-count-on-retrieve-link branch January 9, 2020 04:29
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.

3 participants