Add ?uselang=xx language override option (only valid, locally-enabled languages supported, just as with headers and user settings).
Great aid for debugging & translation testing
This commit is contained in:
parent
173778eab1
commit
3e8af172d6
33
lib/util.php
33
lib/util.php
@ -138,23 +138,38 @@ function common_timezone()
|
|||||||
return common_config('site', 'timezone');
|
return common_config('site', 'timezone');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function common_valid_language($lang)
|
||||||
|
{
|
||||||
|
if ($lang) {
|
||||||
|
// Validate -- we don't want to end up with a bogus code
|
||||||
|
// left over from some old junk.
|
||||||
|
foreach (common_config('site', 'languages') as $code => $info) {
|
||||||
|
if ($info['lang'] == $lang) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
function common_language()
|
function common_language()
|
||||||
{
|
{
|
||||||
|
// Allow ?uselang=xx override, very useful for debugging
|
||||||
|
// and helping translators check usage and context.
|
||||||
|
if (isset($_GET['uselang'])) {
|
||||||
|
$uselang = strval($_GET['uselang']);
|
||||||
|
if (common_valid_language($uselang)) {
|
||||||
|
return $uselang;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// If there is a user logged in and they've set a language preference
|
// If there is a user logged in and they've set a language preference
|
||||||
// then return that one...
|
// then return that one...
|
||||||
if (_have_config() && common_logged_in()) {
|
if (_have_config() && common_logged_in()) {
|
||||||
$user = common_current_user();
|
$user = common_current_user();
|
||||||
$user_language = $user->language;
|
|
||||||
|
|
||||||
if ($user->language) {
|
if (common_valid_language($user->language)) {
|
||||||
// Validate -- we don't want to end up with a bogus code
|
return $user->language;
|
||||||
// left over from some old junk.
|
|
||||||
foreach (common_config('site', 'languages') as $code => $info) {
|
|
||||||
if ($info['lang'] == $user_language) {
|
|
||||||
return $user_language;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user