我在读Ruby Way第三版在155页中有一个I18n脚本的简单示例,但是当我使用“ruby survay.rb”命令运行它时,它会给我一个错误
/home/name/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/i18n-0.7.0/lib/i18n/backend/base.rb:164:in `load_file': can not load translations from locale/en.yml~, the file type yml~ is not known (I18n::UnknownFileType)
我有最新的ruby和rails我用卢布图。
源代码/survay.rb
require 'i18n'
I18n.load_path = Dir["locale/*"]
I18n.enforce_available_locales = true
I18n.locale = ENV["LANG"].split("_").first || :en
puts I18n.t("ask.name")
name = gets.chomp
puts I18n.t("ask.location")
place = gets.chomp
puts I18n.t("ask.children")
childnum = gets.chomp.to_i
puts I18n.t("ask.thanks")
puts name, place, childnum
源代码/locale/en.yml
en:
ask:
name: "What is your name?"
location: "Where do you live?"
children: "How many children do you have?"
thanks: "Thank you!"
最佳答案
试一试
I18n.load_path = Dir["locale/*.yml"]
关于ruby - Ruby Way练习卡住了(I18n),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38373832/