gpt4 book ai didi

ruby - Ruby Way 练习卡住了 (I18n)

转载 作者:太空宇宙 更新时间:2023-11-03 17:30:46 24 4
gpt4 key购买 nike

我正在阅读 The Ruby Way 第 3 版。第 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。我使用 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!"

最佳答案

尝试

I18n.load_path = Dir["locale/*.yml"]

关于ruby - Ruby Way 练习卡住了 (I18n),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38373832/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com