mirror of
https://github.com/discourse/discourse.git
synced 2025-05-23 12:41:25 +08:00
FIX: Language parser matches with dashes or underscores (#31381)
Our language parser now incorrectly matches underscored locales: ``` [1] pry(main)> HttpLanguageParser.parse("zh-CN") => "zh_CN" [2] pry(main)> HttpLanguageParser.parse("zh_CN") => "en_GB" ``` This commit makes sure the input can be agnostic of `-` or `_`
This commit is contained in:
@ -6,7 +6,7 @@ module HttpLanguageParser
|
||||
# headers use hyphens.
|
||||
require "http_accept_language" unless defined?(HttpAcceptLanguage)
|
||||
available_locales = I18n.available_locales.map { |locale| locale.to_s.tr("_", "-") }
|
||||
parser = HttpAcceptLanguage::Parser.new(header)
|
||||
parser = HttpAcceptLanguage::Parser.new(header&.tr("_", "-"))
|
||||
matched = parser.language_region_compatible_from(available_locales)&.tr("-", "_")
|
||||
matched || SiteSetting.default_locale
|
||||
end
|
||||
|
Reference in New Issue
Block a user