2015-10-28 109 views
0

有沒有什麼方法可以設置默認標籤。可以說,我有5個模型都具有電子郵件屬性,我希望它們都具有相同的翻譯。Rails,I18n,標籤,默認翻譯

sv.yaml

sv:   
    helpers: 
    label: 
     defaults: 
     email: "E-post" 

這是行不通的。

+0

怎麼樣把'email'到頂級?應該工作,IIRC。 –

回答

0
label(:post, :title) 
# => <label for="post_title">Title</label> 

helpers: 
    label: 
    post: 
     body: "Write your entire text here" 

http://apidock.com/rails/ActionView/Helpers/FormHelper/label

+0

如果我有5個具有相同屬性的不同模型,並且我想讓它們獲取該屬性的一個翻譯而不是5,則這並不能幫助我。 – Philip

+0

@Philip翻譯模型http://guides.rubyonrails.org/i18n .html#translations-for-active-record-models – user2322409

+0

?????我知道模型的翻譯。那不是我要求的。你讀過我的q? – Philip

0

您可以通過在前面的路徑,以冒號現有的翻譯是指現有的YAML標籤「:」。舉例來說,在我的表我有經常使用的標籤通用部分:

coding_systems: 
    code:   'Code' 
    note:   'Remark' 

後來,我重提這些是這樣的:

attributes: 
    a1_code: 
    code:  :coding_systems.code 
    note:  :coding_systems.note 
    a2_code: 
    code:  :coding_systems.code 
    note:  :coding_systems.note