From 55f898c868d697e80467b35c6b1e0740bf6bd070 Mon Sep 17 00:00:00 2001 From: Victorien ELVINGER Date: Sun, 14 Jun 2015 23:17:52 +0200 Subject: [PATCH] Fix i18n path, language codes, and encoding. --- sources/config.php | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/sources/config.php b/sources/config.php index 55d32e5..d1e6524 100644 --- a/sources/config.php +++ b/sources/config.php @@ -1,3 +1,4 @@ + . */ + + // Limonade configuration function configure() { option('env', ENV_PRODUCTION); @@ -39,26 +42,37 @@ function T_($string) { // Before routing function before($route) { - /** + $lang_mapping = array( + 'fr' => 'fr_FR' + ); + + /** * * Locale * */ if (!isset($_SESSION['locale'])) { $locale = explode(',',$_SERVER['HTTP_ACCEPT_LANGUAGE']); $_SESSION['locale'] = strtolower(substr(chop($locale[0]),0,2)); } + $lang = $_SESSION['locale']; + // Convert simple language code into full language code + if (array_key_exists($lang, $lang_mapping)) { + $lang = $lang_mapping[$lang]; + } + $lang = $lang.'.utf8'; $textdomain="localization"; - putenv('LANGUAGE='.$_SESSION['locale']); - putenv('LANG='.$_SESSION['locale']); - putenv('LC_ALL='.$_SESSION['locale']); - putenv('LC_MESSAGES='.$_SESSION['locale']); - setlocale(LC_ALL,$_SESSION['locale']); - setlocale(LC_CTYPE,$_SESSION['locale']); - $locales_dir = dirname(__FILE__).'/../i18n'; + + putenv('LANGUAGE='.$lang); + putenv('LANG='.$lang); + putenv('LC_ALL='.$lang); + putenv('LC_MESSAGES='.$lang); + setlocale(LC_ALL,$lang); + setlocale(LC_CTYPE,$lang); + $locales_dir = dirname(__FILE__).'/i18n'; bindtextdomain($textdomain,$locales_dir); bind_textdomain_codeset($textdomain, 'UTF-8'); textdomain($textdomain); // Set the $locale variable in template - set('locale', $_SESSION['locale']); + set('locale', $lang); } // After routing