在我的Rails 4.2應用程序中,所有模塊都是用I18n.t()開發的。下面是index.html.erb的例子:RAILS:如何消除生產中某些I18n.t中的「翻譯缺失」(啓用了I18n.t回退)?
<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}')]
但我還是看到translation missing
錯誤從一些I18n.t
在如生產和開發,如標籤和索引標題如下:
如何擺脫的錯誤0?
UPDATE:錯誤translation missing
顯示了在production
即使有以下I18n.t
回退在environment/production.rb
:
# 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
UPDATE: 新增CSS:
//hide all "translation missing" warnings:
body.production span.translation_missing {
display: none;
}
這裏是HTML源代碼的部分顯示的標籤Employee Infos
之一:
<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>
看看這是否能解決你的專業blem。 http://stackoverflow.com/questions/12914019/rails-remove-missing-translation-errors – rakeshp
ahhhh在'en.yaml'下添加'Customers'鍵? – niceman
@ user938363我刪除了我的答案。第一種解決方案當然應該是將**翻譯添加到'en'字典文件**,就像@niceman所說的那樣。我以某種方式假設你不能這樣做,並且你需要隱藏其餘的警告,但是在重讀你的問題之後,我看到你沒有在任何地方說出任何類似的東西。如果確實如此,請更新問題,我將重新發佈一個全面更新的答案,以便如何修改首選的導軌行爲。對不起,這個誤解。 – BoraMa