我一直收到“translation missing: en.layouts.application.title” 的错误提示,无论是在 app/views/layouts/application.html.erb 文件中尝试翻译标题还是其他项目。
所有视图中的翻译都能工作,但布局中的任何内容都会提示“缺失”。 我正在使用en.yml、fr.yml和es.yml,每个文件都有相同的问题(分别是:fr.layouts.application.title和es.layouts.application.title)。
如果我将这些行移到layouts:应用程序嵌套之外,并移动到.yml文件的根层次结构下(当然,要删除t方法中的句点),那么一切都会被翻译。 只要我把它们移回layouts:应用程序下,就会再次出现翻译缺失。
可能出了什么问题? 我正在使用Rails 3.2.7
编辑1:刚试过使用<% t('layouts.application.title') %> ,但仍然显示翻译缺失。
编辑2:找到一个解决办法,即复制或重命名application.html.erb为不同名称(并相应更改*.yml文件)。 如果我开始一个新项目,则在application.html.erb内部的翻译将正常工作。 但在当前项目中:只要我使用application.html.erb(即使只有最少的测试内容),我仍然会收到翻译缺失的提示。
config/locales/en.yml
en:
layouts:
application:
title: "My Catalog"
home: "Home"
store: "Store"
faq: "FAQ"
contact: "Contact"
about: "About"
app/views/layouts/application.html.erb
<div id="banner">
<% t('.title') %>
</div>
<div id="nav_menu" class="sidebar_menu">
<a href="/"><%= t('.home') %></a>
<a href="/store"><%= t('.store') %></a>
<a href="/faq"><%= t('.faq') %></a>
<a href="/contact"><%= t('.contact') %></a>
<a href="/about"><%= t('.about') %></a>
</div>
所有视图中的翻译都能工作,但布局中的任何内容都会提示“缺失”。 我正在使用en.yml、fr.yml和es.yml,每个文件都有相同的问题(分别是:fr.layouts.application.title和es.layouts.application.title)。
如果我将这些行移到layouts:应用程序嵌套之外,并移动到.yml文件的根层次结构下(当然,要删除t方法中的句点),那么一切都会被翻译。 只要我把它们移回layouts:应用程序下,就会再次出现翻译缺失。
可能出了什么问题? 我正在使用Rails 3.2.7
编辑1:刚试过使用<% t('layouts.application.title') %> ,但仍然显示翻译缺失。
编辑2:找到一个解决办法,即复制或重命名application.html.erb为不同名称(并相应更改*.yml文件)。 如果我开始一个新项目,则在application.html.erb内部的翻译将正常工作。 但在当前项目中:只要我使用application.html.erb(即使只有最少的测试内容),我仍然会收到翻译缺失的提示。
t('layouts.application.title')
。 - Paul Fioravanti