Skip to content

Instantly share code, notes, and snippets.

@sakuro
Last active March 18, 2024 00:41
Show Gist options
  • Save sakuro/c284b0bb738131cc639e428e95431ec8 to your computer and use it in GitHub Desktop.
Save sakuro/c284b0bb738131cc639e428e95431ec8 to your computer and use it in GitHub Desktop.
require "bundler/inline"
gemfile do
source "https://rubygems.org"
gem "locale"
gem "rackup"
end
require "locale/middleware"
require "rack/logger"
use Locale::Middleware
use Rack::Logger
run do |env|
logger = env["rack.logger"]
logger.info(sprintf("Thread.current[:current_request]=%p", Thread.current[:current_request]))
logger.info(sprintf("Locale.driver_module.locales=%p", Locale.driver_module.locales))
[200, {}, ["200 OK"]]
end

Accept-Language is not used.

$ curl -H "Accept-Language: ja,en-US;q=0.9,en;q=0.8" http://localhost:9292/
I, [2024-03-18T09:31:34.505612 #84428]  INFO -- : Thread.current[:current_request]={:query_langs=>[nil], :cookie_langs=>[nil], :accept_language=>"ja,en-US;q=0.9,en;q=0.8", :accept_charset=>nil}
I, [2024-03-18T09:31:34.505804 #84428]  INFO -- : Locale.driver_module.locales="en"

Query parameter is used.

$ curl "http://localhost:9292?lang=ja"
I, [2024-03-18T09:32:42.490030 #84428]  INFO -- : Thread.current[:current_request]={:query_langs=>["ja"], :cookie_langs=>[nil], :accept_language=>nil, :accept_charset=>nil}
I, [2024-03-18T09:32:42.490111 #84428]  INFO -- : Locale.driver_module.locales="ja"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment