0

我正在尝试使用 I18n 设置一个简单的 Sinatra 应用程序,遵循推荐的 Sinatra recipe,并使用Rack:Locale来确定语言。

我的 app.rb:

require 'rubygems'
require 'sinatra'
require 'rack/contrib'
require 'i18n'
require 'i18n/backend/fallbacks'
require 'tilt/haml'

use Rack::Locale

configure do
  I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks)
  I18n.load_path = Dir[File.join(settings.root, 'locales', '*.yml')]
  I18n.backend.load_translations
end

helpers do
  def t(*args)
    I18n.t(*args)
  end
end

get '/' do
  haml :index
end

我的语言环境/en.yml:

en:
  welcome: "Welcome!"

当我运行rackup并访问我的 Sinatra 应用程序的根路径时,我得到以下信息:

I18n::InvalidLocale at /
"en-US" is not a valid locale
file: i18n.rb location: enforce_available_locales! line: 284

我认为I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks)通过不找到en-US并退回到en(我有)来处理这个问题,但显然不是。我错过了什么?

4

1 回答 1

0

添加:

I18n.enforce_available_locales = false
于 2016-12-13T13:02:32.920 回答