diff --git a/htdocs/application/config/language.php b/htdocs/application/config/language.php index 221fe16..c322d89 100644 --- a/htdocs/application/config/language.php +++ b/htdocs/application/config/language.php @@ -14,98 +14,98 @@ $config['supported_languages'] = array( 'name' => 'English', 'folder' => 'english', 'direction' => 'ltr', - 'codes' => array('en', 'english', 'en_US'), + 'codes' => array('en', 'english', 'en-US'), 'ckeditor' => NULL ), 'de' => array( 'name' => 'Deutsch', 'folder' => 'german', 'direction' => 'ltr', - 'codes' => array('de', 'german', 'de_DE'), + 'codes' => array('de', 'german', 'de'), 'ckeditor' => NULL ), 'sw' => array( 'name' => 'Schweizerdeutsch', 'folder' => 'swissgerman', 'direction' => 'ltr', - 'codes' => array('sw', 'swissgerman', 'sw_SW'), + 'codes' => array('sw', 'swissgerman', 'de-CH'), 'ckeditor' => NULL ), 'es' => array( 'name' => 'Español', 'folder' => 'spanish', 'direction' => 'ltr', - 'codes' => array('esp', 'spanish', 'es_ES'), + 'codes' => array('esp', 'spanish', 'es-ES'), 'ckeditor' => NULL ), 'no' => array( 'name' => 'norsk', 'folder' => 'norwegian', 'direction' => 'ltr', - 'codes' => array('no', 'norwegian', 'no_NO'), + 'codes' => array('no', 'norwegian', 'no-NO'), 'ckeditor' => NULL ), 'da' => array( 'name' => 'dansk', 'folder' => 'danish', 'direction' => 'ltr', - 'codes' => array('da', 'danish', 'da_DA'), + 'codes' => array('da', 'danish', 'da-DA'), 'ckeditor' => NULL ), 'pt' => array( 'name' => 'Português de Portugal', 'folder' => 'portuguese', 'direction' => 'ltr', - 'codes' => array('ptb', 'portuguese-portugal', 'pt_PT'), + 'codes' => array('ptb', 'portuguese-portugal', 'pt-PT'), 'ckeditor' => 'pt-pt' ), 'tr' => array( 'name' => 'Türkçe', 'folder' => 'turkish', 'direction' => 'ltr', - 'codes' => array('tr', 'turkish', 'tr_TR'), + 'codes' => array('tr', 'turkish', 'tr-TR'), 'ckeditor' => NULL ), 'fr' => array( 'name' => 'Français', 'folder' => 'french', 'direction' => 'ltr', - 'codes' => array('fra', 'french', 'fr_FR'), + 'codes' => array('fra', 'french', 'fr-FR'), 'ckeditor' => NULL ), 'jp' => array( 'name' => '日本語', 'folder' => 'japanese', 'direction' => 'ltr', - 'codes' => array('jp', 'japanese', 'jp_JP'), + 'codes' => array('jp', 'japanese', 'jp-JP'), 'ckeditor' => NULL ), 'pl' => array( 'name' => 'Polski', 'folder' => 'polish', 'direction' => 'ltr', - 'codes' => array('plk', 'polish', 'pl_PL'), + 'codes' => array('plk', 'polish', 'pl-PL'), 'ckeditor' => NULL ), 'ru' => array( 'name' => 'Русский', 'folder' => 'russian', 'direction' => 'ltr', - 'codes' => array('rus', 'russian', 'ru_RU'), + 'codes' => array('rus', 'russian', 'ru-RU'), 'ckeditor' => NULL ), 'cn' => array( 'name' => '繁體中文', 'folder' => 'chinese-simplified', 'direction' => 'ltr', - 'codes' => array('cht', 'chinese-simplified', 'zh_CN'), + 'codes' => array('cht', 'chinese-simplified', 'zh-CN'), 'ckeditor' => NULL ), 'zh' => array( 'name' => '繁體中文', 'folder' => 'chinese-traditional', 'direction' => 'ltr', - 'codes' => array('cht', 'chinese-traditional', 'zh_TW'), + 'codes' => array('cht', 'chinese-traditional', 'zh-TW'), 'ckeditor' => NULL ), ); @@ -121,5 +121,5 @@ $config['supported_languages'] = array( * chinese-simplified (cn) | chinese-traditional (zh) * */ -$config['default_language'] = 'en'; +$config['language'] = 'en'; diff --git a/htdocs/application/hooks/pick_language.php b/htdocs/application/hooks/pick_language.php index 928f5ab..399f827 100644 --- a/htdocs/application/hooks/pick_language.php +++ b/htdocs/application/hooks/pick_language.php @@ -1,69 +1,87 @@ -set_item('language', $config['supported_languages'][$lang]['folder']); + // explode languages into array + $accept_langs = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']); + $supported_languages = $config['supported_languages']; - // Sets a constant to use throughout ALL of CI. - define('AUTO_LANGUAGE', $lang); + // Check them all, until we find a match + foreach ($accept_langs as $al) + { + + // Check its in the array. If so, break the loop, we have one! + foreach ($supported_languages as $i => $l) + { + + if ($al == $l['codes'][2]) + { + $lang = $i; + break; + } + } + } + } + + // If no language has been worked out - or it is not supported - use the default + + if (empty($lang) OR !array_key_exists($lang, $config['supported_languages'])) + { + $lang = $config['language']; + } + + // Whatever we decided the lang was, save it for next time to avoid working it out again + $_SESSION['lang_code'] = $lang; + + // Load CI config class + $CI_config = & load_class('Config'); + + // Set the language config. Selects the folder name from its key of 'en' + $CI_config->set_item('language', $config['supported_languages'][$lang]['folder']); + + // Sets a constant to use throughout ALL of CI. + define('AUTO_LANGUAGE', $lang); }