Why is the translation path not being found?

1

Assuming my yml file is organized this way:

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 within a decorator the command:

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

I get a response to the Translate missing exception, knowing that the "type.to_s.underscore" command can return "every", "on" and "each". However when running in the 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 presents the Translate Missing exception.

Even inside the decorator the path is correct, because the exception is presented ?, it is not possible to concatenate variables ?, and in the console, because only the one finished in "on" presents error ?, would it be a special word? >     

asked by anonymous 06.03.2015 / 21:25

1 answer

2

Could you enter the decorator code? It may be a problem with the "type" variable.

Regarding translation missing from

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

I noticed that it works if you change the "on" to "on_date"

DE:

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

TO:

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 throw away code within a YAML file named 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 you 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 on the gem i18n repository in GitHub:

link

I hope it helps!

    
07.03.2015 / 16:22