Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
archery
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
3
Issues
3
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
archery
Commits
2061fd3a
Commit
2061fd3a
authored
Oct 09, 2014
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improved locale detection
parent
125a6d19
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
15 deletions
+31
-15
app.php
app.php
+4
-15
util.php
util.php
+27
-0
No files found.
app.php
View file @
2061fd3a
...
...
@@ -8,21 +8,10 @@ require 'DatabaseAuthenticator.php';
* Set locale based on browser language specification, and set up gettext
*/
$supported_locales
=
array
(
'nl_NL'
);
// English is default, Dutch is optional
if
(
isset
(
$_SERVER
[
'HTTP_ACCEPT_LANGUAGE'
]))
{
$locale
=
explode
(
','
,
$_SERVER
[
'HTTP_ACCEPT_LANGUAGE'
])[
0
];
// nl -> nl_NL
if
(
preg_match
(
'/^[a-z]{2}$/'
,
$locale
))
$locale
.=
'_'
.
strtoupper
(
$locale
);
if
(
in_array
(
$locale
,
$supported_locales
))
{
if
(
$locale
=
set_accept_locale
(
array
(
'nl'
)))
{
putenv
(
"LANG=
$locale
"
);
putenv
(
"LC_ALL=
$locale
"
);
putenv
(
"LC_MESSAGES=
$locale
"
);
setlocale
(
LC_ALL
,
$locale
);
}
}
$domain
=
'archery'
;
...
...
util.php
View file @
2061fd3a
...
...
@@ -15,3 +15,30 @@ function load_config($filename, $optional=false) {
return
$config
;
}
function
set_accept_locale
(
$supported_languages
=
null
)
{
if
(
!
isset
(
$_SERVER
[
'HTTP_ACCEPT_LANGUAGE'
]))
return
null
;
foreach
(
explode
(
','
,
$_SERVER
[
'HTTP_ACCEPT_LANGUAGE'
])
as
$locale
)
{
if
(
!
preg_match
(
'/^(\w\w)(?:[-_](\w\w))?(\.\w+)?$/'
,
$locale
,
$m
))
continue
;
$lang
=
$m
[
1
];
$region
=
isset
(
$m
[
2
])
?
'_'
.
$m
[
2
]
:
''
;
$ext
=
isset
(
$m
[
3
])
?
$m
[
3
]
:
''
;
if
(
$supported_languages
===
null
||
in_array
(
$lang
,
$supported_languages
))
{
$locale
=
setlocale
(
LC_ALL
,
$lang
.
$region
.
$ext
,
$lang
.
$region
.
'.utf8'
,
$lang
.
$region
,
$lang
.
$ext
,
$lang
.
'.utf8'
,
$lang
);
return
$locale
;
}
}
return
null
;
}
Write
Preview
Markdown
is supported
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