【发布时间】:2017-04-26 01:52:49
【问题描述】:
在我的 Rails 4.2 应用程序中,所有模块都是使用 I18n.t() 开发的。下面是 index.html.erb 的一个例子:
<table class="table table-hover">
<thead>
<tr>
<th><%= t('Create Date') %></th>
<th><%= t(@for_which.sub('_', ' ').titleize) %></th>
<th><%= t('Brief Note') %></th>
<th><%= t('Ranking Index') %></th>
<th><%= t('Active') %></th>
<th><%= t('Entered By') %></th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
在initializers下的local.rb中,本地设置为en:
I18n.enforce_available_locales = false
I18n.default_locale = 'en' if Rails.env.production? || Rails.env.development?
I18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}')]
但在生产和开发中,我仍然从一些I18n.t 中看到translation missing 的错误,例如标签和索引标题如下:
如何摆脱translation missing的错误?
更新:错误translation missing 显示在production 中,即使在environment/production.rb 中使用以下I18n.t 后备:
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation cannot be found).
config.i18n.fallbacks = true
更新: 添加CSS:
//hide all "translation missing" warnings:
body.production span.translation_missing {
display: none;
}
这是显示标签Employee Infos之一的html源代码的一部分:
<li class="dropdown">
<a id="dropdownuser" href="#" data-toggle="dropdown" class="dropdown-toggle" data-toggle="tooltip" data-placement="bottom" ><span class="glyphicons glyphicons-yen text-danger"></span> <span class="translation_missing" title="translation missing: en.Employee Info">Employee Info</span> <b class="caret" id="caret_medium"></b></a>
<ul id="banktransaction" class="dropdown-menu" role="menu">
<li><a href="/tt/view_handler?index=1&url=/tt/tsheet/employee_infos"><i class='glyphicon glyphicon-list'></i> translation missing: en.List</a></li>
<li></li>
<li><a href="/tt/view_handler?index=1&url=/tt/tsheet/employee_infos/search"><i class='glyphicon glyphicon-list-alt'></i> translation missing: en.Search</a></li>
</ul>
</li>
【问题讨论】:
-
看看这是否能解决您的问题。 stackoverflow.com/questions/12914019/…
-
啊啊啊在
en.yaml下添加Customers键?? -
@user938363 我删除了我的答案。正如@niceman 建议的那样,第一个解决方案当然应该是将翻译添加到
en字典文件。我以某种方式认为您不能这样做,并且您需要隐藏其余的警告,但是在重读您的问题后,我发现您在任何地方都没有说类似的话。如果确实如此,请更新问题,我将重新发布一个彻底更新的答案,如何修改首选的 Rails 行为。很抱歉造成这种误解。
标签: ruby-on-rails ruby-on-rails-4 internationalization