]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fallback from "de" to "de_DE" and the other way around
authorJoas Schilling <coding@schilljs.com>
Tue, 4 Oct 2016 11:29:54 +0000 (13:29 +0200)
committerJoas Schilling <coding@schilljs.com>
Tue, 11 Oct 2016 07:52:28 +0000 (09:52 +0200)
Signed-off-by: Joas Schilling <coding@schilljs.com>
lib/private/legacy/app.php

index a029fdf7ebc47f9a2861863d7662b027387d9e7b..f8219f17acf914ce553849b9b0932452b664b288 100644 (file)
@@ -1334,21 +1334,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;
        }
 
        /**