2012-08-17 27 views
2

我在當前的rails項目上遇到了一個非常奇怪的問題。每當我嘗試使用密鑰notifications時,都會收到翻譯缺失消息。例如:爲什麼「通知」這個詞造成i18n打破軌道?

#en-US.yml 
en-US: 
    notifications: 
    index: 
     title: 'notification page' 

#/notifications/index.html.erb 
<%= content_for :title, t('.title') -%> 

這將失敗,並告訴我的翻譯是缺少

#en-US.yml 
en-US: 
    notifications: 
    index: 
     title: 'notification page' 

#/notifications/index.html.erb 
<%= content_for :title, t('notifications.index.title') -%> 

這也將失敗。

#en-US.yml 
en-US: 
    notification: 
    index: 
     title: 'notification page' 

#/notifications/index.html.erb 
<%= content_for :title, t('notification.index.title') -%> 

這奇怪的是,將工作,去除s將允許它找到翻譯。

#en-US.yml 
en-US: 
    notifications1: 
    index: 
     title: 'notification page' 

#/notifications/index.html.erb 
<%= content_for :title, t('notifications1.index.title') -%> 

這也將工作,加入了1的通知工程的結束。

看來,鐵軌不喜歡單詞通知。這是一個問題,因爲我不想爲此重命名整個模型,而且我想使用i18n.t視圖快捷方式來保持一致性。是notifications保留字嗎?它有什麼理由不能找到它?

回答

0

我不知道爲什麼它的失敗在你的情況,但我只是有一個自己去,它不是一個保留字,我的語言環境文件:

en: 
    notifications: 
    foo: bar 

結果:

1.8.7 :001 > I18n.t('notifications.foo') 
=> "bar" 

這個測試是用Rails 3.1.5和Ruby 1.8.7完成的。

在你的情況下,你有以下幾點?

1.8.7 :001 > I18n.t('notifications') 
=> "translation missing: en.notifications" 
0

雖然不是確切的答案,但我發現在I18n中有幾個詞不能用作鍵。我假設I18n代碼在別處使用它們。

其他包括「無」,「是」,「對」等

只需使用同義詞或做一些像「notifications_」,使之不同。