简体   繁体   中英

Trouble on translating views after renaming statements from 'translate' to 'I18n.t' and from 'localize' to 'I18n.l'

I am using Ruby on Rails 3.2.2 and I have a strange problem. In my view files I use the following code:

# app/views/articles/show.html.erb
I18n.t('.page_title')

When I render the above view code in the browser I get the translation missing: en.page_title message. However, as you can see from the "missing" message, the translation doesn't refer to the articles.show.page_title YML statement... but it should do that! It seems that the “Lazy” Lookup doesn't work as expected.

Why that happens? Have you some idea about the issue and how to solve it?

Note: I just made a code refactoring renaming statements from translate to I18n.t and from localize to I18n.l ...

Try simply: t('.page_title') Then you should see another statement. But in fact, I18n searches in several places. You can add the translation and see for yourself:

en:
  page-title:

Or:

en:
  articles:
    show:
      page-title:

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