From bd09881e5ba9d0d6fe993193baf778b26148bacc Mon Sep 17 00:00:00 2001
From: Thijs Kinkhorst <thijs@kinkhorst.com>
Date: Sat, 4 Sep 2021 15:25:25 +0000
Subject: [PATCH] Remove language[priorities]. It's been hardly used in the
 code.

We could use it everywhere, but it's better to reduce the already big
amount of configuration options the admin is confronted with than the
small problem this option solves.
---
 config-templates/config.php                 | 35 ---------------------
 docs/simplesamlphp-upgrade-notes-2.0.md     |  3 ++
 lib/SimpleSAML/Locale/Translate.php         | 14 ---------
 tests/lib/SimpleSAML/XHTML/TemplateTest.php |  6 ++--
 4 files changed, 6 insertions(+), 52 deletions(-)

diff --git a/config-templates/config.php b/config-templates/config.php
index de3dd82d1..679c1b023 100644
--- a/config-templates/config.php
+++ b/config-templates/config.php
@@ -733,41 +733,6 @@ $config = [
      | LANGUAGE AND INTERNATIONALIZATION |
      *************************************/
 
-    /*
-     * Language-related options.
-     */
-    'language' => [
-        /*
-         * An array in the form 'language' => <list of alternative languages>.
-         *
-         * Each key in the array is the ISO 639 two-letter code for a language,
-         * and its value is an array with a list of alternative languages that
-         * can be used if the given language is not available at some point.
-         * Each alternative language is also specified by its ISO 639 code.
-         *
-         * For example, for the "no" language code (Norwegian), we would have:
-         *
-         * 'priorities' => [
-         *      'no' => ['nb', 'nn', 'en', 'se'],
-         *      ...
-         * ],
-         *
-         * establishing that if a translation for the "no" language code is
-         * not available, we look for translations in "nb",
-         * and so on, in that order.
-         */
-        'priorities' => [
-            'no' => ['nb', 'nn', 'en', 'se'],
-            'nb' => ['no', 'nn', 'en', 'se'],
-            'nn' => ['no', 'nb', 'en', 'se'],
-            'se' => ['nb', 'no', 'nn', 'en'],
-            'nr' => ['zu', 'en'],
-            'nd' => ['zu', 'en'],
-            'tw' => ['st', 'en'],
-            'nso' => ['st', 'en'],
-        ],
-    ],
-
     /*
      * Languages available, RTL languages, and what language is the default.
      */
diff --git a/docs/simplesamlphp-upgrade-notes-2.0.md b/docs/simplesamlphp-upgrade-notes-2.0.md
index b2684c375..15bd534de 100644
--- a/docs/simplesamlphp-upgrade-notes-2.0.md
+++ b/docs/simplesamlphp-upgrade-notes-2.0.md
@@ -49,3 +49,6 @@ Upgrade notes for SimpleSAMLphp 2.0
     - lib/SimpleSAML/Store/SQL.php has been renamed to lib/SimpleSAML/Store/SQLStore.php
     - lib/SimpleSAML/Store/Memcache.php has been renamed to lib/SimpleSAML/Store/MemcacheStore.php
     - lib/SimpleSAML/Store/Redis.php has been renamed to lib/SimpleSAML/Store/RedisStore.php
+
+- Configuration options removed:
+  - languages[priorities]
diff --git a/lib/SimpleSAML/Locale/Translate.php b/lib/SimpleSAML/Locale/Translate.php
index 4c26b670d..9d57f6c3a 100644
--- a/lib/SimpleSAML/Locale/Translate.php
+++ b/lib/SimpleSAML/Locale/Translate.php
@@ -393,20 +393,6 @@ class Translate
             return $translations[$context['currentLanguage']];
         }
 
-        // we don't have a translation for the current language, load alternative priorities
-        $sspcfg = Configuration::getInstance();
-        /** @psalm-var \SimpleSAML\Configuration $langcfg */
-        $langcfg = $sspcfg->getConfigItem('language');
-        $priorities = $langcfg->getArray('priorities', []);
-
-        if (!empty($priorities[$context['currentLanguage']])) {
-            foreach ($priorities[$context['currentLanguage']] as $lang) {
-                if (isset($translations[$lang])) {
-                    return $translations[$lang];
-                }
-            }
-        }
-
         // nothing we can use, return null so that we can set a default
         return null;
     }
diff --git a/tests/lib/SimpleSAML/XHTML/TemplateTest.php b/tests/lib/SimpleSAML/XHTML/TemplateTest.php
index d5c2732d1..48b7b2be1 100644
--- a/tests/lib/SimpleSAML/XHTML/TemplateTest.php
+++ b/tests/lib/SimpleSAML/XHTML/TemplateTest.php
@@ -90,7 +90,7 @@ class TemplateTest extends TestCase
         $c = Configuration::loadFromArray([], '', 'simplesaml');
         $t = new Template($c, self::TEMPLATE);
 
-	$prop = 'description';
+        $prop = 'description';
         $data = [
             'entityid' => 'urn:example.org',
             $prop => ['nl' => 'Something', 'en' => 'Other lang', 'fr' => 'Another desc'],
@@ -103,11 +103,11 @@ class TemplateTest extends TestCase
         $name = $t->getEntityPropertyTranslation($prop, $data);
         $this->assertEquals('Something', $name);
 
-	unset($data[$prop]['nl']);
+        unset($data[$prop]['nl']);
         $name = $t->getEntityPropertyTranslation($prop, $data);
         $this->assertEquals('Other lang', $name);
 
-	unset($data[$prop]['en']);
+        unset($data[$prop]['en']);
         $name = $t->getEntityPropertyTranslation($prop, $data);
         $this->assertNull($name);
     }
-- 
GitLab