【问题标题】:Attribute translation in RailsRails 中的属性翻译
【发布时间】:2013-05-28 06:46:39
【问题描述】:

所以我几天前遇到的问题仍然让我对我的代码感到不舒服。我无法为我的应用程序获得正确的翻译:Yml 看起来像这样:

 pl:
   errors: &errors
   format: ! '%{attribute} %{message}'
   messages: 
      confirmation: nie zgadza się z potwierdzeniem

   activemodel:
     errors: 
       <<: *errors
   activerecord:
     errors:
       <<: *errors

模型看起来像这样:

 module Account
   class User < ActiveRecord::Base
     attr_accessor: password_confirmation
   end
 end

并且在控制器中声明了 flash:

 flash[:errors] = @user.errors.full_messages

我尝试并阅读了 activerecord 文档并堆叠了以前的问题(How to use Rails I18n.t to translate an ActiveRecord attribute?Translated attributes in Rails error messages (Rails 2.3.2, I18N))。但是它仍然无法按我的意愿工作。 password_confirmation 仍然是“密码确认”,而不是应有的“Potwierdzenie hasła”。屏幕截图可能会更好地解释它:http://i42.tinypic.com/1glz5.png

【问题讨论】:

    标签: ruby-on-rails internationalization attributes translation


    【解决方案1】:

    您的用户模型位于命名空间中,因此您还必须在翻译文件中声明命名空间。尝试以下方法以获得 password_confirmation 的正确翻译:

    pl:    
      activerecord:
        attributes:
          account/user:
            password_confirmation: "Potwierdzenie hasła"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多