0

I'm trying to set up a simple Sinatra app with I18n, following the recommended Sinatra recipe, and using Rack:Locale to determine the language.

My 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

My locales/en.yml:

en:
  welcome: "Welcome!"

When I run rackup and visit the root path of my Sinatra app, I get the following:

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

I thought that the I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks) would handle this, by not finding en-US and falling back to en (which I have), but apparently not. What am I missing?

CDub
  • 13,146
  • 4
  • 51
  • 68

1 Answers1

0

Add:

I18n.enforce_available_locales = false