Rails控制台无法启动I18n的错误

时间:2012-09-05 16:43:50

标签: ruby-on-rails localization internationalization

当我尝试启动控制台时,我得到了

/home/username/.rvm/gems/ruby-1.9.2-p320/gems/i18n-0.6.1/lib/i18n/backend/base.rb:158:in `load_file': can not load translations from /var/www/railsapp/config/locales/ru.yml, expected it to return a hash, but does not (I18n::InvalidLocaleData)
from /home/username/.rvm/gems/ruby-1.9.2-p320/gems/i18n-0.6.1/lib/i18n/backend/base.rb:15:in `block in load_translations'
from /home/username/.rvm/gems/ruby-1.9.2-p320/gems/i18n-0.6.1/lib/i18n/backend/base.rb:15:in `each'
from /home/username/.rvm/gems/ruby-1.9.2-p320/gems/i18n-0.6.1/lib/i18n/backend/base.rb:15:in `load_translations'
from /home/username/.rvm/gems/ruby-1.9.2-p320/gems/i18n-0.6.1/lib/i18n/backend/simple.rb:57:in `init_translations'
from /home/username/.rvm/gems/ruby-1.9.2-p320/gems/i18n-0.6.1/lib/i18n/backend/simple.rb:71:in `lookup'
from /home/username/.rvm/gems/ruby-1.9.2-p320/gems/i18n-0.6.1/lib/i18n/backend/base.rb:26:in `translate'
from /home/username/.rvm/gems/ruby-1.9.2-p320/gems/i18n-0.6.1/lib/i18n.rb:156:in `block in translate'
from /home/username/.rvm/gems/ruby-1.9.2-p320/gems/i18n-0.6.1/lib/i18n.rb:152:in `catch'
from /home/username/.rvm/gems/ruby-1.9.2-p320/gems/i18n-0.6.1/lib/i18n.rb:152:in `translate'
from /home/username/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.1.0/lib/active_record/railtie.rb:102:in `block in <class:Railtie>'
from /home/username/.rvm/gems/ruby-1.9.2-p320/gems/activesupport-3.1.0/lib/active_support/lazy_load_hooks.rb:34:in `call'
from /home/username/.rvm/gems/ruby-1.9.2-p320/gems/activesupport-3.1.0/lib/active_support/lazy_load_hooks.rb:34:in `execute_hook'
from /home/username/.rvm/gems/ruby-1.9.2-p320/gems/activesupport-3.1.0/lib/active_support/lazy_load_hooks.rb:43:in `block in run_load_hooks'
from /home/username/.rvm/gems/ruby-1.9.2-p320/gems/activesupport-3.1.0/lib/active_support/lazy_load_hooks.rb:42:in `each'
from /home/username/.rvm/gems/ruby-1.9.2-p320/gems/activesupport-3.1.0/lib/active_support/lazy_load_hooks.rb:42:in `run_load_hooks'
from /home/username/.rvm/gems/ruby-1.9.2-p320/gems/railties-3.1.0/lib/rails/application/finisher.rb:56:in `block in <module:Finisher>'
from /home/username/.rvm/gems/ruby-1.9.2-p320/gems/railties-3.1.0/lib/rails/initializable.rb:25:in `instance_exec'
from /home/username/.rvm/gems/ruby-1.9.2-p320/gems/railties-3.1.0/lib/rails/initializable.rb:25:in `run'
from /home/username/.rvm/gems/ruby-1.9.2-p320/gems/railties-3.1.0/lib/rails/initializable.rb:50:in `block in run_initializers'
from /home/username/.rvm/gems/ruby-1.9.2-p320/gems/railties-3.1.0/lib/rails/initializable.rb:49:in `each'
from /home/username/.rvm/gems/ruby-1.9.2-p320/gems/railties-3.1.0/lib/rails/initializable.rb:49:in `run_initializers'
from /home/username/.rvm/gems/ruby-1.9.2-p320/gems/railties-3.1.0/lib/rails/application.rb:92:in `initialize!'
from /home/username/.rvm/gems/ruby-1.9.2-p320/gems/railties-3.1.0/lib/rails/railtie/configurable.rb:30:in `method_missing'
from /var/www/railsapp/config/environment.rb:6:in `<top (required)>'
from /home/username/.rvm/gems/ruby-1.9.2-p320/gems/railties-3.1.0/lib/rails/application.rb:78:in `require'
from /home/username/.rvm/gems/ruby-1.9.2-p320/gems/railties-3.1.0/lib/rails/application.rb:78:in `require_environment!'
from /home/username/.rvm/gems/ruby-1.9.2-p320/gems/railties-3.1.0/lib/rails/commands.rb:39:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'

我的应用运行正常,只有控制台无法启动。 可能是这个问题与从第二个rails版本升级有关。但是一年来一直运转良好。

我的ru.yml:

ru:
 activerecord:
  attributes:
   user:
    password: "Пароль"
    login: "Имя пользователя"
    password_confirmation: "Повтор пороля"
  models:
   user: "пользователь"

这是一个奇怪的错误。删除ru.yml的评论后一切正常。

1 个答案:

答案 0 :(得分:0)

您的ru.yml似乎不对,您可能需要双倍空格缩进,rails不会将您的翻译视为散列,请尝试将您的yml更改为使用两个空格。