活动记录翻译时出错

时间:2014-05-18 22:21:22

标签: ruby-on-rails rails-i18n

我在db:reset时收到错误。我已经阅读了几篇关于此的帖子,但没有一个适合我。

错误说:

translation missing: es.activerecord.errors.messages.record_invalid

我的locales/es.yml是:

es:
  activerecord:
    errors:
      messages:
        accepted: "must be accepted"
        blank: "can't be blank"
        confirmation: "doesn't match confirmation"
        empty: "can't be empty"
        equal_to: "must be equal to {{count}}"
        even: "must be even"
        exclusion: "is reserved"
        greater_than: "must be greater than {{count}}"
        greater_than_or_equal_to: "must be greater than or equal to {{count}}"
        inclusion: "is not included in the list"
        invalid: "is invalid"
        less_than: "must be less than {{count}}"
        less_than_or_equal_to: "must be less than or equal to {{count}}"
        not_a_number: "is not a number"
        odd: "must be odd"
        taken: "is already taken"
        too_long: "is too long (maximum is {{count}} characters)"
        too_short: "is too short (minimum is {{count}} characters)"
        wrong_length: "is the wrong length (should be {{count}} characters)"

2 个答案:

答案 0 :(得分:4)

通过将所有语言环境翻译从rails locales repo复制到我的es.yml来修复它。

https://github.com/svenfuchs/rails-i18n/blob/master/rails/locale/es.yml

答案 1 :(得分:1)

如果您安装了rails-i18n gem,则会自动将其包含在您的rails应用中。

来自rails-i18n宝石自述文件:

添加到您的Gemfile:

gem 'rails-i18n', '~> 5.1' # For 5.0.x, 5.1.x and 5.2.x
gem 'rails-i18n', '~> 4.0' # For 4.0.x
gem 'rails-i18n', '~> 3.0' # For 3.x
gem 'rails-i18n', github: 'svenfuchs/rails-i18n', branch: 'master' # For 5.x
gem 'rails-i18n', github: 'svenfuchs/rails-i18n', branch: 'rails-4-x' # For 4.x
gem 'rails-i18n', github: 'svenfuchs/rails-i18n', branch: 'rails-3-x' # For 3.x

或运行此命令:

gem install rails-i18n -v '~> 5.1' # For  For 5.0.x, 5.1.x and 5.2.x
gem install rails-i18n -v '~> 4.0' # For 4.0.x
gem install rails-i18n -v '~> 3.0' # For 3.x