diff options
author | Joas Schilling <coding@schilljs.com> | 2016-10-11 10:09:21 +0200 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2016-10-11 10:09:21 +0200 |
commit | ee2d77279f7fa7df4e74b69119ce61ae24612e67 (patch) | |
tree | bd71f259ed4817fef734c635c43c125cad89badd /lib | |
parent | a61cab80d57a3215806082445fadb1c10e529b8d (diff) | |
download | nextcloud-server-ee2d77279f7fa7df4e74b69119ce61ae24612e67.tar.gz nextcloud-server-ee2d77279f7fa7df4e74b69119ce61ae24612e67.zip |
Fallback from "de" to "de_DE" and the other way around
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/app.php | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/lib/private/app.php b/lib/private/app.php index 0b775be2ef1..337437b69d2 100644 --- a/lib/private/app.php +++ b/lib/private/app.php @@ -1205,21 +1205,48 @@ class OC_App { } protected static function findBestL10NOption($options, $lang) { - $fallback = $englishFallback = false; + $fallback = $similarLangFallback = $englishFallback = false; + + $lang = strtolower($lang); + $similarLang = $lang; + if (strpos($similarLang, '_')) { + // For "de_DE" we want to find "de" and the other way around + $similarLang = substr($lang, 0, strpos($lang, '_')); + } + foreach ($options as $option) { if (is_array($option)) { if ($fallback === false) { $fallback = $option['@value']; } - if (isset($option['@attributes']['lang']) && $option['@attributes']['lang'] === $lang) { + if (!isset($option['@attributes']['lang'])) { + continue; + } + + $attributeLang = strtolower($option['@attributes']['lang']); + if ($attributeLang === $lang) { return $option['@value']; } + + if ($attributeLang === $similarLang) { + $similarLangFallback = $option['@value']; + } else if (strpos($attributeLang, $similarLang . '_') === 0) { + if ($similarLangFallback === false) { + $similarLangFallback = $option['@value']; + } + } } else { $englishFallback = $option; } } - return $englishFallback !== false ? $englishFallback : (string) $fallback; + + if ($similarLangFallback !== false) { + return $similarLangFallback; + } else if ($englishFallback !== false) { + return $englishFallback; + } + return (string) $fallback; } /** |