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

No I18n::MissingInterpolationArgument when no arguments are passed #496

Closed
danielpoonwj opened this issue Oct 21, 2019 · 1 comment
Closed

Comments

@danielpoonwj
Copy link

What I tried to do

Content of config/locales/en.yml:

en:
  greeting: Hello %{first_name} %{last_name}

Calling I18n without arguments or with an empty argument hash does not raise I18n::MissingInterpolationArgument, but just passes the original string as-is.

[1] pry(main)> I18n.t('greeting')
=> "Hello %{first_name} %{last_name}"

[2] pry(main)> I18n.t('greeting', {})
=> "Hello %{first_name} %{last_name}"

What I expected to happen

Consistency in behaviour when passing incomplete interpolation arguments, since passing no arguments should fall under missing interpolation arguments.

[1] pry(main)> I18n.t('greeting', first_name: 'John')
I18n::MissingInterpolationArgument: missing interpolation argument :last_name in "Hello %{first_name} %{last_name}" ({:first_name=>"John"} given)

[2] pry(main)> I18n.t('greeting', last_name: 'Doe')
I18n::MissingInterpolationArgument: missing interpolation argument :first_name in "Hello %{first_name} %{last_name}" ({:last_name=>"Doe"} given)

[3] pry(main)> I18n.t('greeting', middle_name: 'Danger')
I18n::MissingInterpolationArgument: missing interpolation argument :first_name in "Hello %{first_name} %{last_name}" ({:middle_name=>"Danger"} given)

Do let me know if it's intended behaviour or if it could potentially be due to the configuration of my project.

Versions of i18n, rails, and anything else you think is necessary

i18n (1.7.0)

@radar
Copy link
Collaborator

radar commented Jan 13, 2020

This is an intentional behaviour of the library, and explained here: https://github.com/ruby-i18n/i18n/blob/master/lib/i18n/tests/interpolation.rb#L6-L18

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

No branches or pull requests

2 participants