Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Locale::Middleware never uses Accept-Language #15

Closed
sakuro opened this issue Mar 18, 2024 · 2 comments · Fixed by #16
Closed

Locale::Middleware never uses Accept-Language #15

sakuro opened this issue Mar 18, 2024 · 2 comments · Fixed by #16

Comments

@sakuro
Copy link

sakuro commented Mar 18, 2024

locale 2.1.3

Gist

Locale::Middleware calls Locale::Driver::CGI#set_request with
[request["lang"]] as the first argument(query_lang).

Locale.set_request([request["lang"]],
[request.cookies["lang"]],
environment["HTTP_ACCEPT_LANGUAGE"],
environment["HTTP_ACCEPT_CHARSET"])

It is [nil] when lang is not fed and it is added to locales as Locale::Tag::Irregular: en. So locales always becomes non-empty here and unless locales.size > 0 clause prevents using values from Accept-Language header.

This applies to lang from both query string and cookie.

if langs = req[:query_langs]
langs.each do |lang|
locales << Locale::Tag.parse(lang)
end
end
unless locales.size > 0
# COOKIE "lang"
if langs = req[:cookie_langs]
langs.each do |lang|
locales << Locale::Tag.parse(lang) if lang.size > 0
end
end
end
unless locales.size > 0

@kou
Copy link
Member

kou commented Mar 18, 2024

Good catch!

Do you want to open a PR for this? It seems that we can fix this by adding .compact to [request["lang"]] and [request.cookies["lang"]].

@sakuro
Copy link
Author

sakuro commented Mar 18, 2024

#16

@kou kou closed this as completed in #16 Mar 18, 2024
kou pushed a commit that referenced this issue Mar 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants