2011-08-31 80 views
3

我想使用語言環境來將設計默認語言(英語)翻譯成葡萄牙語。我發現了一個相當不錯的資源,大部分工作,但是每當我有一個指向區域內資源變量的指針時,它就會給我一個英文名稱。例如,我有一個名爲User的模型,因此當更新此用戶時出現問題時,我想顯示包含「User」正確翻譯的Flash消息,在本例中爲「Usuário」。設計國際資源

回答

2

模型名字翻譯應該付諸config/locales/pt.yml

pt: 
    activerecord: 
    models: 
     user: Usuário 
+0

出於某種原因不工作。 –

+0

您的語言環境是否設置爲葡萄牙語?什麼確切的消息沒有被翻譯? – binarycode

+0

是的,它設置正確。那麼,只有資源上的錯誤消息。在語言環境配置的條目如下: under errors/messages/not_saved: one:「Nãofoipossívelgravar o%{resource}:1 erro」 如果我更改「模型」的「資源」它說它缺少一個插值參數。 –

0

設計不使用ActiveRecord翻譯,可能不是夫婦與任何ORM。

我剛剛結束了覆蓋設計視圖中添加翻譯用ActiveRecord鍵:

h2 =t('.sign_up') 
= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => {:class => 'form-vertical' }) do |f| 
    = f.error_notification 
    = display_base_errors resource 
    = f.input :name, label: t('activerecord.attributes.user.name'), :autofocus => true 
    = f.input :email, label: t('activerecord.attributes.user.email'), :required => true 
    = f.input :password, label: t('activerecord.attributes.user.password'),:required => true 
    = f.input :password_confirmation, label: t('activerecord.attributes.user.password_confirmation'), :required => true 
    = f.button :submit, t('.sign_up'), :class => 'btn-primary' 
= render "devise/shared/links" 

要翻譯的其他消息(未字段標籤),你應該嘗試https://github.com/mcasimir/devise-i18n-views