2017-04-26 20 views
2

在我的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> 

initializerslocal.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在如生產和開發,如標籤和索引標題如下: enter image description here

如何擺脫的錯誤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; 
} 

但在字標籤,按鈕和表頭消失: enter image description here

這裏是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&amp;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&amp;url=/tt/tsheet/employee_infos/search"><i class='glyphicon glyphicon-list-alt'></i> translation missing: en.Search</a></li>     
       </ul> 
      </li> 
+0

看看這是否能解決你的專業blem。 http://stackoverflow.com/questions/12914019/rails-remove-missing-translation-errors – rakeshp

+1

ahhhh在'en.yaml'下添加'Customers'鍵? – niceman

+1

@ user938363我刪除了我的答案。第一種解決方案當然應該是將**翻譯添加到'en'字典文件**,就像@niceman所說的那樣。我以某種方式假設你不能這樣做,並且你需要隱藏其餘的警告,但是在重讀你的問題之後,我看到你沒有在任何地方說出任何類似的東西。如果確實如此,請更新問題,我將重新發佈一個全面更新的答案,以便如何修改首選的導軌行爲。對不起,這個誤解。 – BoraMa

回答

2
#的config/application.rb中文件

你可以做這樣的事情

Rails.application.configure do |config| 
    config.action_view.raise_on_missing_translations = false 
end 

,你可以得到更多的here

我希望這能幫助你:)

+0

'MZaragoza',我只能將它放在'/environment/development.rb或production.rb'中,它在'application.rb'中不起作用。此外,它仍顯示翻譯缺失錯誤。即使在生產中。奇。 – user938363

+0

這不會做任何改變,因爲這是Rails中的[default](https://github.com/rails/rails/blob/4-2-stable/actionview/lib/action_view/base.rb#L154) 4。 – BoraMa

相關問題