diff options
-rw-r--r-- | digest.php | 16 | ||||
-rw-r--r-- | include/functions.php | 28 | ||||
-rw-r--r-- | include/game.php | 1 | ||||
-rw-r--r-- | include/preferences.php | 1 | ||||
-rw-r--r-- | include/stats.php | 1 | ||||
-rw-r--r-- | include/user.php | 1 | ||||
-rw-r--r-- | index.php | 43 | ||||
-rw-r--r-- | rss.php | 20 |
8 files changed, 55 insertions, 56 deletions
@@ -53,21 +53,7 @@ foreach($users as $uid) $PREF = DB_get_PREF($uid); // set users language preference - $language = $PREF['language']; - - switch($language) - { - case 'de': - putenv("LC_ALL=de_DE"); - setlocale(LC_ALL, "de_DE"); - // Specify location of translation tables - bindtextdomain("edoko", "./locale"); - // Choose domain - textdomain("edoko"); - break; - default: - /* do nothing */ - } + set_language($PREF['language']); // calculate mod by digest-time switch($PREF['digest']) diff --git a/include/functions.php b/include/functions.php index cb78457..1f8f2cc 100644 --- a/include/functions.php +++ b/include/functions.php @@ -1699,4 +1699,32 @@ function verify_password($email, $password) return 3; } +/* language functions */ +function detectlanguage() +{ + /* read out browser's prefered language, taken from php-manual*/ + $langcode = explode(";", $_SERVER['HTTP_ACCEPT_LANGUAGE']); + $langcode = explode(",", $langcode['0']); + return $langcode['0']; +} + +function set_language($language) +{ + switch($language) + { + case 'de': + putenv("LC_ALL=de_DE"); + setlocale(LC_ALL, "de_DE"); + // Specify location of translation tables + bindtextdomain("edoko", "./locale"); + // Choose domain + textdomain("edoko"); + break; + default: + /* do nothing */ + } + + return; +} + ?> diff --git a/include/game.php b/include/game.php index ae7d6f7..d116049 100644 --- a/include/game.php +++ b/include/game.php @@ -59,6 +59,7 @@ $playid = DB_get_current_playid($gameid); /* might be -1 at beginning of the g $PREF = DB_get_PREF(isset($_SESSION['id'])?$_SESSION['id']:$myid); /* set language chosen in preferences, will become active on the next reload (see index.php)*/ $_SESSION['language'] = $PREF['language']; +set_language($PREF['language']); /* get rule set for this game */ diff --git a/include/preferences.php b/include/preferences.php index a20913a..3517a42 100644 --- a/include/preferences.php +++ b/include/preferences.php @@ -51,6 +51,7 @@ display_user_menu($myid); $PREF = DB_get_PREF($myid); /* set language chosen in preferences, will become active on the next reload (see index.php)*/ $_SESSION['language'] = $PREF['language']; +set_language($PREF['language']); $timezone = DB_get_user_timezone($myid); DB_update_user_timestamp($myid); diff --git a/include/stats.php b/include/stats.php index f0d436b..bb6d693 100644 --- a/include/stats.php +++ b/include/stats.php @@ -37,6 +37,7 @@ if(!$myid) $PREF = DB_get_PREF($myid); /* set language chosen in preferences, will become active on the next reload (see index.php)*/ $_SESSION['language'] = $PREF['language']; +set_language($PREF['language']); DB_update_user_timestamp($myid); diff --git a/include/user.php b/include/user.php index 607e89d..551e7d5 100644 --- a/include/user.php +++ b/include/user.php @@ -120,6 +120,7 @@ else $PREF = DB_get_PREF($myid); /* set language chosen in preferences, will become active on the next reload (see index.php)*/ $_SESSION['language'] = $PREF['language']; + set_language($PREF['language']); DB_update_user_timestamp($myid); @@ -51,33 +51,28 @@ if($DBopen<0) exit(); } -/* localization */ +/**** localization ****/ /* needs to be in front of output_header, but we don't know the users preferences at this time, * so we go by the session variable or if language is set */ -if(myisset('language') || isset($_SESSION['language'])) - { - $language = 'en'; - - if(myisset('language')) - $language = $_REQUEST['language']; - else if(isset($_SESSION['language'])) - $language = $_SESSION['language']; - - switch($language) - { - case 'de': - putenv("LC_ALL=de_DE"); - setlocale(LC_ALL, "de_DE"); - // Specify location of translation tables - bindtextdomain("edoko", "./locale"); - // Choose domain - textdomain("edoko"); - break; - default: - /* do nothing */ - } - } +/* set default */ +$language = detectlanguage(); + +/* check if default in array of supported languages, else default to english */ +$supported_languages = array ('en','de'); + +if ( !in_array($language, $supported_languages) ) + $language = 'en'; + +/* override with explicit request from user */ +if(myisset('language')) + $language = $_REQUEST['language']; +else if(isset($_SESSION['language'])) + $language = $_SESSION['language']; + +/* set it */ +set_language($language); +/**** end language ****/ /* done major error checking, output header of HTML page */ output_header(); @@ -74,23 +74,9 @@ header("Content-Type: text/xml"); <title>E-DoKo Feed</title> <?php - /* set language */ - $PREF = DB_get_PREF($id); - $lang = $PREF['language']; - - switch($lang) - { - case 'de': - putenv("LC_ALL=de_DE"); - setlocale(LC_ALL, "de_DE"); - // Specify location of translation tables - bindtextdomain("edoko", "./locale"); - // Choose domain - textdomain("edoko"); - break; - default: - /* do nothing */ - } +/* set language */ +$PREF = DB_get_PREF($id); +set_language($PREF['language']); echo '<subtitle>'._('Know when it is your turn')."</subtitle>\n"; |