Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
birger
users
Commits
f10b6bd5
Commit
f10b6bd5
authored
Aug 30, 2018
by
o@immerda.ch
Browse files
fix locale selection, when locale is not available
parent
a3dd9a94
Changes
1
Hide whitespace changes
Inline
Side-by-side
app/controllers/application_controller.rb
View file @
f10b6bd5
...
...
@@ -7,12 +7,17 @@ class ApplicationController < ActionController::Base
before_action
:set_locale
def
valid_l
(
l
)
return
l
if
l
&&
I18n
.
available_locales
.
include?
(
l
)
nil
end
def
extract_locale
(
request
.
env
[
'HTTP_ACCEPT_LANGUAGE'
]
||
''
).
scan
(
/^[a-z]{2}/
).
first
(
request
.
env
[
'HTTP_ACCEPT_LANGUAGE'
]
||
''
).
scan
(
/^[a-z]{2}/
).
select
{
|
l
|
valid_l
(
l
)}.
first
end
def
set_locale
I18n
.
locale
=
params
[
:l
]
||
session
[
:locale
]
||
extract_locale
||
I18n
.
default_locale
I18n
.
locale
=
valid_l
(
params
[
:l
]
)
||
valid_l
(
session
[
:locale
]
)
||
extract_locale
||
I18n
.
default_locale
session
[
:locale
]
=
I18n
.
locale
end
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment