2015-01-05 61 views
0

翻譯字符串前面顯示翻譯名字在我的區域文件中,有如下翻譯:Rails的翻譯在瀏覽器

de: 
    activerecord: 
    errors: 
     models: 
     user: 
      attributes: 
      email: 
       taken: "Die E-Mail Adresse wird bereits benutzt." 

當我在瀏覽器中打開所需的頁面,錯誤信息如下所示:

Email Die E-Mail Adresse wird bereits benutzt. 

那麼有人知道爲什麼在翻譯的字符串前有另一個「電子郵件」?

+2

你可以顯示你在視圖上使用什麼?這將有助於瞭解發生了什麼。 – fjuan

+0

對不起,我忘了告訴:這是設計問題,我認爲。 – LeMark88

+0

'= form_for(resource,as:resource_name,url:registration_path(resource_name))do | f | = devise_error_messages!' – LeMark88

回答

0

正確的陽明結構應該是:

de: 
    activerecord: 
    models: 
     user: Dude 
    attributes: 
     user: 
     email: "mail" 
    errors: 
     template: 
     header: 
      one: "1 error prohibited this %{model} from being saved" 
      other: "%{count} errors prohibited this %{model} from being saved" 
     body: "There were problems with the following fields:" 

    errors: 
    format: ! '%{attribute} %{message}' 
    messages: 
     taken: "Email Die E-Mail Adresse wird bereits benutzt." 

注意,有兩個「錯誤」鍵,一個內部的ActiveRecord,另一個之外。稍後使用驗證消息。

你可以得到https://github.com/svenfuchs/rails-i18n/blob/master/rails/locale/en.yml

一個更全面詳細的翻譯文件,你可能會發現在https://github.com/mcasimir/devise-i18n-views/blob/master/locales/en.yml

爲我的項目的色器件翻譯文件,我通常爲每種語言幾個翻譯文件:

  • rails.en.yml:rails使用的消息(受svenfuchs文件啓發)
  • devise.en.yml:與認證有關的消息(f ROM中的色器件項目本身)
  • en.yml:我的信息對不屬於其他的寶石我的看法創建(如「simple_form」寶石通常也有自己的文件)

編輯

Rails Internationalization guide,驗證消息會被搜索順序:

  • activerecord.errors.models.user.attributes.name.blank
  • activerecord.errors.models.user.blank
  • activerecord.errors.messages.blank
  • errors.attributes.name.blank
  • errors.messages.blank

所以它的正確使用什麼你發佈的問題:

de: 
    activerecord: 
    errors: 
     models: 
     user: 
      attributes: 
      email: 
       taken: "http://guides.rubyonrails.org/i18n.html#translations-for-active-record-models" 
+0

感謝您的幫助! – LeMark88

+0

我仔細閱讀了有關國際化的導軌指南,並有可能採用其他方法。我將編輯answet以反映這一點。 – fjuan