Add setting to use browser locale if available (#404)

This commit is contained in:
Riccardo Graziosi
2024-09-08 14:40:48 +02:00
committed by GitHub
parent 5decb702f2
commit 2e07f7b00d
10 changed files with 41 additions and 2 deletions

View File

@@ -63,6 +63,18 @@ class ApplicationController < ActionController::Base
# Set tenant locale
I18n.locale = @tenant.locale
if @tenant_setting.use_browser_locale
user_preferred_language = request.env['HTTP_ACCEPT_LANGUAGE'].scan(/^[a-z]{2}/).first
available_locales = I18n.available_locales.map { |locale| locale.to_s[0, 2] }
if available_locales.include?(user_preferred_language)
# special cases
user_preferred_language = 'zh-CN' if user_preferred_language == 'zh'
I18n.locale = user_preferred_language
end
end
end
def load_oauths