2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-09-07 12:02:53 +08:00

FIX: Include resolved locale in anonymous cache key (#10289)

This only applies when set_locale_from_accept_language_header is enabled
This commit is contained in:
David Taylor 2020-07-22 18:00:07 +01:00 committed by GitHub
parent bcb0e62363
commit c09b5807f3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 52 additions and 13 deletions

View file

@ -0,0 +1,13 @@
# frozen_string_literal: true
module HttpLanguageParser
def self.parse(header)
# Rails I18n uses underscores between the locale and the region; the request
# 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)
matched = parser.language_region_compatible_from(available_locales)&.tr('-', '_')
matched || SiteSetting.default_locale
end
end