如何在Rails控制台中加载西班牙语?

4

我已经用西班牙语和英语设置了我的应用程序。如果对象返回验证错误,我的控制台会显示英文错误消息。我想设置我的Rails控制台,以便我能够获得西班牙语的验证错误消息。

1个回答

15

这应该可以工作:

I18n.locale = 'es'

出现以下错误。C:\projects\CyncErp>ruby script/console Loading development environment (Rails 2.3.8)
I18.locale = 'es' NameError: uninitialized constant I18 from c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_suppo rt/dependencies.rb:443:in load_missing_constant' from c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_suppo rt/dependencies.rb:80:in const_missing' from c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_suppo rt/dependencies.rb:92:in `const_missing' from (irb):1
- krunal shah
你忘记在 I18n 中加上 n 了。 - Shadwell
@Shadwell 现在虽然没有返回错误,但验证消息仍然是英文的。 - krunal shah
嗯,好的,我这边正常。恐怕无法提供帮助。例如,在 I18n.locale = 'es' 后使用 User.create! 会出现大量的缺失翻译信息,例如:ActiveRecord::RecordInvalid: Validation failed: Password confirmation translation missing: es, activerecord, errors, models, user, attributes, password_confirmation, blank - Shadwell
只是想知道:你的应用程序中有西班牙语翻译,对吧?除非你提供了它们,否则它们不会神奇地出现。这里有很多样例Rails翻译:http://github.com/svenfuchs/rails-i18n/tree/master/rails/locale - Shadwell
@Shadwell 谢谢。我错过了一些配置。 - krunal shah

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接