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

Better error message when I18n::TranslationMissingData is rescued. #375

Closed
tgxworld opened this issue Jun 15, 2017 · 6 comments
Closed

Better error message when I18n::TranslationMissingData is rescued. #375

tgxworld opened this issue Jun 15, 2017 · 6 comments

Comments

@tgxworld
Copy link

tgxworld commented Jun 15, 2017

What I tried to do

en:
  some_key: 'My name is %{name}'
I18n.t('some_key', wrong_key: 'testing')
=>  "translation missing: en.some_key"

What I expected to happen

I18n.t('some_key', wrong_key: 'testing')
=>  "translation data missing: en.some_key"

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

I would like to propose a change for the default string that is returned when a I18n::MissingTranslationData is raised.

pry(main)> I18n.t('some_key', wrong_key: 'testing')
=> "translation missing: en.some_key"
pry(main)> I18n.t('some_ke', wrong_key: 'testing')
=> "translation missing: en.some_ke"

My confusion comes from the fact that translation missing can refer to a case where the key has not been defined as well as the case where the key has been defined but the variables are incorrect. I feel that returning translation data missing: en.some_key would be a much more accurate error message.

Thank you for your time! ❤️

@radar
Copy link
Collaborator

radar commented Jul 6, 2017

I believe #371 might fix this issue? Could you please confirm for me @tgxworld?

@tgxworld
Copy link
Author

tgxworld commented Jul 6, 2017

@radar Thanks :) The new translation looks alittle odd to me though..

super "translation data #{entry.inspect} can not be used with :count => #{count}. key '#{key}' is missing."

It seems like it always assume that there will always be a count key?

@ragesoss
Copy link
Contributor

ragesoss commented Jul 6, 2017

The new error message from #371 is only for pluralization, where there will always be a count. (The 'count' part if it was already part of the message; the key part at the end is what got added.)

This is a separate issue.

@ragesoss
Copy link
Contributor

ragesoss commented Jul 6, 2017

I can't replicate this. Here's what I get, which I think is sensible behavior:

pry(main)> I18n.t('some_key', wrong_key: 'testing')
=> I18n::MissingInterpolationArgument: missing interpolation argument :correct_key in "%{correct_key} message"
pry(main)> I18n.t('some_ke', wrong_key: 'testing')
=> "translation missing: en.some_ke"

@ragesoss
Copy link
Contributor

ragesoss commented Jul 6, 2017

@tgxworld It looks like maybe somewhere in your environment, missing_interpolation_argument_handler has been set differently from the default, so that it is handling the interpolation error the same way as a missing key error.

The gem lets you define an arbitrary handler for that error via I18n.config.missing_interpolation_argument_handler=, but by default, if I'm understanding it correctly, it should do something like what I posted above: raising an error.

@tgxworld
Copy link
Author

tgxworld commented Jul 7, 2017

@ragesoss Thanks for clarifying 👍 It does look like we have

I18n.config.missing_interpolation_argument_handler = proc { throw(:exception) } by default. I'll investigate and fix it on our end.

@tgxworld tgxworld closed this as completed Jul 7, 2017
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

3 participants