diff --git a/config-templates/config.php b/config-templates/config.php
index 18f88fd7ff3860cfadf24503a3d43ffe4621e98d..f3bd8b2b9611e8eaac84f37b7644c459f6442e0d 100644
--- a/config-templates/config.php
+++ b/config-templates/config.php
@@ -655,6 +655,38 @@ $config = array(
      | LANGUAGE AND INTERNATIONALIZATION |
      *************************************/
 
+    /*
+     * Language-related options.
+     */
+    'language' => array(
+        /*
+         * 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' => array(
+         *      'no' => array('nb', 'nn', 'en', 'se'),
+         *      ...
+         * ),
+         *
+         * establishing that if a translation for the "no" language code is
+         * not available, we look for translations in "nb" (Norwegian BokmĂĄl),
+         * and so on, in that order.
+         */
+        'priorities' => array(
+            'no' => array('nb', 'nn', 'en', 'se'),
+            'nb' => array('no', 'nn', 'en', 'se'),
+            'nn' => array('no', 'nb', 'en', 'se'),
+            'se' => array('nb', 'no', 'nn', 'en'),
+            'en' => array('nb', 'no', 'nn', 'se'),
+        ),
+    ),
+
     /*
      * Languages available, RTL languages, and what language is the default.
      */
diff --git a/lib/SimpleSAML/Locale/Translate.php b/lib/SimpleSAML/Locale/Translate.php
index 3e6e4677080977d9940881e7e86286dc5716fbde..b9414ebc950de8cb1a32ba78f1538ccab53b6550 100644
--- a/lib/SimpleSAML/Locale/Translate.php
+++ b/lib/SimpleSAML/Locale/Translate.php
@@ -496,4 +496,48 @@ class Translate
 
         return strtr($text, is_array($args[0]) ? $args[0] : $args);
     }
+
+
+    /**
+     * Pick a translation from a given array of translations for the current language.
+     *
+     * @param array $context An array of options. The current language must be specified as an ISO 639 code accessible
+     * with the key "currentLanguage" in the array.
+     * @param array $translations An array of translations. Each translation has an ISO 639 code as its key, identifying
+     * the language it corresponds to.
+     *
+     * @return null|string The translation appropriate for the current language, or null if none found. If the
+     * $context or $translations arrays are null, or $context['currentLanguage'] is not defined, null is also returned.
+     */
+    public static function translateFromArray($context, $translations)
+    {
+        if (!is_array($translations) || $translations === null) {
+            return null;
+        }
+
+        if (!is_array($context) || !isset($context['currentLanguage'])) {
+            return null;
+        }
+
+        if (isset($translations[$context['currentLanguage']])) {
+            return $translations[$context['currentLanguage']];
+        }
+
+        // we don't have a translation for the current language, load alternative priorities
+        $sspcfg = \SimpleSAML_Configuration::getInstance();
+        $langcfg = $sspcfg->getConfigItem('language', null);
+        $priorities = array();
+        if ($langcfg instanceof \SimpleSAML_Configuration) {
+            $priorities = $langcfg->getArray('priorities', array());
+        }
+
+        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/lib/SimpleSAML/XHTML/Template.php b/lib/SimpleSAML/XHTML/Template.php
index 3bd52fdc90ee8bbc7726324cdff494ad45841de8..56e05b3723b30be7167d5b62735dafd17477dc54 100644
--- a/lib/SimpleSAML/XHTML/Template.php
+++ b/lib/SimpleSAML/XHTML/Template.php
@@ -248,6 +248,15 @@ class SimpleSAML_XHTML_Template
         $twig->addGlobal('queryParams', $queryParams);
         $twig->addGlobal('templateId', str_replace('.twig', '', $this->normalizeTemplateName($this->template)));
 
+        // add a filter for translations out of arrays
+        $twig->addFilter(
+            new \Twig_SimpleFilter(
+                'translateFromArray',
+                array('\SimpleSAML\Locale\Translate', 'translateFromArray'),
+                array('needs_context' => true)
+            )
+        );
+
         if ($this->controller) {
             $this->controller->setUpTwig($twig);
         }