Why is the translation path not being found?

Asked

Viewed 287 times

1

Assuming my yml file is arranged that 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 controller the command:

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

I get the Translate Missing exception in response, knowing that the "type.to_s.underscore" command can return "Every", "on" and "each". But when running 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 shows the Translate Missing exception.

Even within the Developer the path is correct, why is the exception? , is it not possible to concatenate variables? , and on the console, because only the finished one in "on" shows error? , would be a special word?

1 answer

2


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

In relation to Translation Missing de

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

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

OF:

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 for true and false respectively. If you play guinte 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 then load 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 in the Gem i18n repository on Github:

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

I hope it helps!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.