set :locales, %w[en it]
set :default_locale, 'it'
set :locale_pattern, /^\/?(#{Regexp.union(settings.locales)})(\/.+)$/
helpers do
def locale
@locale || settings.default_locale
end
end
before('/:locale/*') { |params| @locale = params.first } # params shouldn't be a Hash?
我无法获得以/ en /:
开头的其他页面get '/attivita/:activity' do |activity|
erb "attivita/#{activity.to_sym}".to_sym
end
我应该使用:locale任何地方的路线吗?感谢
答案 0 :(得分:2)
您的before
屏蔽在wrong number of arguments (2 for 1)
上为Sinatra 1.1.3
提供了{。}}。
来自How to detect language from URL in Sinatra的before
适用于我:
before do
@locale, request.path_info = $1, $2 if request.path_info =~ settings.locale_pattern
end