Why is the path of translation not being found?

Assuming my yml file is organized like this:

pt-BR:
  alert_system:
    schedules:
      teste: 'ss'
      every: 'Todo Dia:'
      each: 'A Cada:'
      each_day: 'A Cada #{dias} Dias'
      on: 'Na data:'

When calling from inside a decorator the command:

I18n.t("alert_system.schedules.#{type.to_s.underscore} ")

I get the Translate missing exception as a response, knowing that the "type.to_s.underscore" command can return "every", "on" and "each". But when running in rails console the following commands

I18n.t("alert_system.schedules.on")
I18n.t("alert_system.schedules.every")
I18n.t("alert_system.schedules.each")

Only the first one has the Translate Missing exception.

Even inside the decorator the path be correct, why is the exception presented?, cannot concatenate variables?, and in the console, because only the one finished in " on " presents error? would that be a special word?

Author: leonardo freitas oliveira, 2015-03-06

1 answers

Could you enter the decorator code? There may be some problem with the variable "type".

With respect to the missing translation of

I18n.t("alert_system.schedules.on")

I realized it works if I change the " on " to "on_date"

From:

pt-BR:
  alert_system:
    schedules:
      teste: 'ss'
      every: 'Todo Dia:'
      each: 'A Cada:'
      each_day: 'A Cada #{dias} Dias'
      on: 'Na data:'

For:

pt-BR:
  alert_system:
    schedules:
      teste: 'ss'
      every: 'Todo Dia:'
      each: 'A Cada:'
      each_day: 'A Cada #{dias} Dias'
      on_date: 'Na data:'

Using:

I18n.t("alert_system.schedules.on_date")

This is because YAML automatically changes the parameters on and off to true and false respectively. If you play if squint code inside a YAML file called x.yaml:

pt-BR:
  alert_system:
    schedules:
      teste: 'ss'
      every: 'Todo Dia:'
      each: 'A Cada:'
      each_day: 'A Cada #{dias} Dias'
      on: 'Na data:'

And in the sequence loading it directly using YAML will see that the return will be true=>"Na data:":

>> YAML.load_file('x.yml')
=> {"pt-BR"=>{"alert_system"=>{"schedules"=>{"teste"=>"ss", "every"=>"Todo Dia:", "each"=>"A Cada:", "each_day"=>"A Cada \#{dias} Dias", true=>"Na data:"}}}}

More information in the gem i18n repository on GitHub:

Https://github.com/svenfuchs/i18n/issues/308

Hope it helps!

 2
Author: brunowff, 2015-03-12 02:36:52