Skip to content

Commit

Permalink
He's a ~smooth~ safe operator
Browse files Browse the repository at this point in the history
  • Loading branch information
excid3 committed May 28, 2024
1 parent 424de5f commit 9b7e4bb
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/controllers/concerns/set_locale.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ def locale_from_user
# Extract the full locale (including region code)
# Handles `pt-BR` by falling back to `pt`
def locale_from_header
locale = request.env.fetch("HTTP_ACCEPT_LANGUAGE", "").scan(/^[a-z]{2}(?:-[a-zA-Z]{2})?$/).first
locale = request.env.fetch("HTTP_ACCEPT_LANGUAGE", "").scan(/^[a-z]{2}(?:-[a-zA-Z]{2})?$/).first.to_s
permit_locale(locale) || permit_locale(locale.split("-").first)
end

# Makes sure locale is in the available locales list
def permit_locale(locale)
locale&.strip.presence_in(I18n.config.available_locales_set)
locale.to_s.strip.presence_in(I18n.config.available_locales_set)
end
end

0 comments on commit 9b7e4bb

Please sign in to comment.