Skip to content
Snippets Groups Projects
Commit f2855c2d authored by Olav Morken's avatar Olav Morken
Browse files

Template: Iterate over languages in the order they are in the Accept-Language header.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@479 44740490-163a-0410-bde0-09ae8108e29a
parent fdbdad1e
No related branches found
No related tags found
No related merge requests found
...@@ -78,14 +78,19 @@ class SimpleSAML_XHTML_Template { ...@@ -78,14 +78,19 @@ class SimpleSAML_XHTML_Template {
/* Find the available language with the best score. */ /* Find the available language with the best score. */
$bestLanguage = NULL; $bestLanguage = NULL;
$bestScore = -1.0; $bestScore = -1.0;
foreach($availableLanguages as $language) {
if(!array_key_exists($language, $languageScore)) { foreach($languageScore as $language => $score) {
/* Skip this language - it wasn't mentioned in the http header. */
if(!in_array($language, $availableLanguages, TRUE)) {
/* Skip this language - we don't have it. */
continue; continue;
} }
$score = $languageScore[$language];
/* Some user agents use very limited precicion of the quality value, but order the
* elements in descending order. Therefore we rely on the order of the output from
* getAcceptLanguage() matching the order of the languages in the header when two
* languages have the same quality.
*/
if($score > $bestScore) { if($score > $bestScore) {
$bestLanguage = $language; $bestLanguage = $language;
$bestScore = $score; $bestScore = $score;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment