gpt4 book ai didi

ruby - Sinatra 路由和 i18n

转载 作者:数据小太阳 更新时间:2023-10-29 08:06:09 25 4
gpt4 key购买 nike

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 来破坏路由吗?谢谢

最佳答案

你的 before block 在 Sinatra 1.1.3 上给我一个错误数量的参数(2 为 1)

使用来自 How to detect language from URL in Sinatrabefore对我有用:

before do
@locale, request.path_info = $1, $2 if request.path_info =~ settings.locale_pattern
end

关于ruby - Sinatra 路由和 i18n,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5079972/

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