イム・リーディングThe Ruby Way第3版。そこのページ155での国際化スクリプトの簡単な例ですが、私は「ルビーsurvay.rb」コマンドでそれを実行すると、それは私にエラーRuby Wayエクササイズ(I18n)
/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)
私は、最新のルビーやレールを持っているを与えます。私はLubuntuを使います。
ソースコード/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!"
あなたがソースコード/ロケール/ en.rb' '書きました。 '/ locale/en.yml'であってはなりませんか? – Ursus
うわー、オタク。もちろん.ymlがあります。 –
'Dir [" locale/* "]'によって選択されているテキストエディタによって一時ファイルが作成されていますか? 'locale/en.yml〜'は一時ファイルのようです。 – jphager2