2013-03-10 30 views
1
翻譯

我有幾個翻譯侷促到初始化像這樣:的Rails:在初始值設定

GROUP_GOVERNANCE_STYLES = [ 
    [I18n.t("constants.group_governance_styles.collective"), 1], 
    [I18n.t("constants.group_governance_styles.electoral_democracy"), 2], 
    [I18n.t("constants.group_governance_styles.dictatorship"), 3] 
] 

在我en.yml文件我有:

en: 
    constants: 
    group_governance_styles: 
     collective: "collective" 
     electoral_democracy: "electoral democracy" 
     dictatorship: "dictatorship" 

不幸的是,當我嘗試呈現這些翻譯在一個視圖中,我得到以下錯誤:

translation missing: en.constants.group_governance_styles.collective 
translation missing: en.constants.group_governance_styles.electoral_democracy 
translation missing: en.constants.group_governance_styles.dictatorship 

我也試過去除範圍,但th翻譯仍然缺失。有另一種方法來解決這個問題嗎?也許有一個我不知道的初始值設定項的默認範圍?

回答

3

AFAIK,翻譯會在初始化程序之後加載。嘗試把它放在environment.rb

+0

這個工程!我對environment.rb瞭解不多,但似乎用像這樣的常量填充它可能是一種不好的做法。是否有可能從environment.rb中加載包含常量的文件? – nullnullnull 2013-03-10 21:43:46

+2

同意。我不是向environment.rb添加代碼的忠實粉絲。您也可以將該代碼放在一個單獨的文件中(可能位於lib文件夾中?)並在environment.rb中需要該文件。 – Hesham 2013-03-10 22:06:08

+0

非常好,那就是訣竅。 – nullnullnull 2013-03-10 22:21:50

相關問題