终于解决了错误
can not load translations from /activesupport-2.3.18/lib/active_support/locale/en.yml, the file type yml is not known
通过猴子修补 Rails 的 I18n::Backend::Base#load_file(filename) 方法。
解决方法如下:
1.1 创建了一个名为ruby2.rb
/config/initializers的文件
1.2 新增以下内容/config/initializers/ruby2.rb
if Rails::VERSION::MAJOR == 2 && RUBY_VERSION >= '2.0.0'
module I18n
module Backend
module Base
def load_file(filename)
type = File.extname(filename).tr('.', '').downcase
# As a fix added second argument as true to respond_to? method
raise UnknownFileType.new(type, filename) unless respond_to?(:"load_#{type}", true)
data = send(:"load_#{type}", filename) # TODO raise a meaningful exception if this does not yield a Hash
data.each { |locale, d| store_translations(locale, d) }
end
end
end
end
end
1.3 终于跑了
$ rake db:schema:load RAILS_ENV=test
并且模式已成功加载。
我能找到的最有用的参考资料,并帮助我找到了解决方案:
- https://github.com/rails/rails/issues/10514
- https://www.lucascaton.com.br/2014/02/28/have-a-rails-2-app-you-can-run-it-on-the-newest-ruby/