From b69c6650f000f9e9f2f8cc198c5e9fded405229c Mon Sep 17 00:00:00 2001 From: Sebastian Korotkiewicz Date: Sun, 26 Oct 2014 16:59:35 +0100 Subject: [PATCH] Support for dynamically language setting --- htdocs/application/config/config.php | 2 +- htdocs/application/config/hooks.php | 8 +- htdocs/application/config/language.php | 118 +++++++++++++++++++++ htdocs/application/hooks/pick_language.php | 76 +++++++++++++ 4 files changed, 201 insertions(+), 3 deletions(-) create mode 100644 htdocs/application/config/language.php create mode 100644 htdocs/application/hooks/pick_language.php diff --git a/htdocs/application/config/config.php b/htdocs/application/config/config.php index 9a1a123..92208d6 100644 --- a/htdocs/application/config/config.php +++ b/htdocs/application/config/config.php @@ -101,7 +101,7 @@ $config['charset'] = 'UTF-8'; | setting this variable to TRUE (boolean). See the user guide for details. | */ -$config['enable_hooks'] = FALSE; +$config['enable_hooks'] = TRUE; /* diff --git a/htdocs/application/config/hooks.php b/htdocs/application/config/hooks.php index a4ad2be..6e41765 100644 --- a/htdocs/application/config/hooks.php +++ b/htdocs/application/config/hooks.php @@ -10,7 +10,11 @@ | */ - +$hook['pre_controller'][] = array( + 'function' => 'pick_language', + 'filename' => 'pick_language.php', + 'filepath' => 'hooks' +); /* End of file hooks.php */ -/* Location: ./application/config/hooks.php */ \ No newline at end of file +/* Location: ./application/config/hooks.php */ diff --git a/htdocs/application/config/language.php b/htdocs/application/config/language.php new file mode 100644 index 0000000..99e20b0 --- /dev/null +++ b/htdocs/application/config/language.php @@ -0,0 +1,118 @@ + array( + 'name' => 'English', + 'folder' => 'english', + 'direction' => 'ltr', + 'codes' => array('en', 'english', 'en_US'), + 'ckeditor' => NULL + ), + 'de' => array( + 'name' => 'Deutsch', + 'folder' => 'german', + 'direction' => 'ltr', + 'codes' => array('de', 'german', 'de_DE'), + 'ckeditor' => NULL + ), + 'sw' => array( + 'name' => 'Schweizerdeutsch', + 'folder' => 'swissgerman', + 'direction' => 'ltr', + 'codes' => array('sw', 'swissgerman', 'sw_SW'), + 'ckeditor' => NULL + ), + 'es' => array( + 'name' => 'Español', + 'folder' => 'spanish', + 'direction' => 'ltr', + 'codes' => array('esp', 'spanish', 'es_ES'), + 'ckeditor' => NULL + ), + 'no' => array( + 'name' => 'norsk', + 'folder' => 'norwegian', + 'direction' => 'ltr', + 'codes' => array('no', 'norwegian', 'no_NO'), + 'ckeditor' => NULL + ), + 'pt' => array( + 'name' => 'Português de Portugal', + 'folder' => 'portuguese', + 'direction' => 'ltr', + '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'), + 'ckeditor' => NULL + ), + 'fr' => array( + 'name' => 'Français', + 'folder' => 'french', + 'direction' => 'ltr', + 'codes' => array('fra', 'french', 'fr_FR'), + 'ckeditor' => NULL + ), + 'jp' => array( + 'name' => '日本語', + 'folder' => 'japanese', + 'direction' => 'ltr', + 'codes' => array('jp', 'japanese', 'jp_JP'), + 'ckeditor' => NULL + ), + 'pl' => array( + 'name' => 'Polski', + 'folder' => 'polish', + 'direction' => 'ltr', + 'codes' => array('plk', 'polish', 'pl_PL'), + 'ckeditor' => NULL + ), + 'ru' => array( + 'name' => 'Русский', + 'folder' => 'russian', + 'direction' => 'ltr', + 'codes' => array('rus', 'russian', 'ru_RU'), + 'ckeditor' => NULL + ), + 'cn' => array( + 'name' => '繁體中文', + 'folder' => 'chinese-simplified', + 'direction' => 'ltr', + 'codes' => array('cht', 'chinese-simplified', 'zh_CN'), + 'ckeditor' => NULL + ), + 'zh' => array( + 'name' => '繁體中文', + 'folder' => 'chinese-traditional', + 'direction' => 'ltr', + 'codes' => array('cht', 'chinese-traditional', 'zh_TW'), + 'ckeditor' => NULL + ), +); + +/* + * Default Language + * + * If no language is specified, which one to use? + * Currently: english (en) | german (de) | swissgerman (sw) + * spanish (es) | norwegian (no) | portuguese (pt) + * turkish (tr) | french (fr) | japanese (jp) + * polish (pl) | russian (ru) + * chinese-simplified (cn) | chinese-traditional (zh) + * +*/ +$config['default_language'] = 'en'; + diff --git a/htdocs/application/hooks/pick_language.php b/htdocs/application/hooks/pick_language.php new file mode 100644 index 0000000..3b6b99b --- /dev/null +++ b/htdocs/application/hooks/pick_language.php @@ -0,0 +1,76 @@ +set_item('language', $config['supported_languages'][$lang]['folder']); + + // Sets a constant to use throughout ALL of CI. + define('AUTO_LANGUAGE', $lang); +}