简体   繁体   中英

Dealing with missing argument and I18n

Given that I have a key with this translation key

t('my.key', :url => @url)

And translation in many language:

key: "Click %{url}"

I do the following change:

t('my.key', :link => @link)

key: "Click %{url}"

The keys are translated by the community, I have quite a few. We only maintain english locale.

Now ofcourse, my test go red, because if this view render in any other language than english without updating all the other keys, it will return:

missing interpolation argument in "Click %{url}" ({:link=>"..."} given)
(ActionView::TemplateError)

What's the lazy-programmer way to solve that? Rake task to remove the keys? Monkey patch I18n to rescue to :en?

Nothing changed in the localizable section of the string.

The %{...} is never translated, it is just a variable name.

So it is safe to change %{url} to %{link} it in all languages (making sure to not damage the strings by using an editor that messes up the encoding though).

It is a bit like changing html tags:

   <p>Click <b>Print</b> to whatever</p>

change to:

   <p>Click <i>Print</i> to whatever</p>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM