mirror of
https://github.com/claudehohl/Stikked.git
synced 2025-04-26 04:51:08 -05:00
fix the language mess
This commit is contained in:
parent
1ef3c0b911
commit
2e7be5e1cb
@ -14,98 +14,98 @@ $config['supported_languages'] = array(
|
|||||||
'name' => 'English',
|
'name' => 'English',
|
||||||
'folder' => 'english',
|
'folder' => 'english',
|
||||||
'direction' => 'ltr',
|
'direction' => 'ltr',
|
||||||
'codes' => array('en', 'english', 'en_US'),
|
'codes' => array('en', 'english', 'en-US'),
|
||||||
'ckeditor' => NULL
|
'ckeditor' => NULL
|
||||||
),
|
),
|
||||||
'de' => array(
|
'de' => array(
|
||||||
'name' => 'Deutsch',
|
'name' => 'Deutsch',
|
||||||
'folder' => 'german',
|
'folder' => 'german',
|
||||||
'direction' => 'ltr',
|
'direction' => 'ltr',
|
||||||
'codes' => array('de', 'german', 'de_DE'),
|
'codes' => array('de', 'german', 'de'),
|
||||||
'ckeditor' => NULL
|
'ckeditor' => NULL
|
||||||
),
|
),
|
||||||
'sw' => array(
|
'sw' => array(
|
||||||
'name' => 'Schweizerdeutsch',
|
'name' => 'Schweizerdeutsch',
|
||||||
'folder' => 'swissgerman',
|
'folder' => 'swissgerman',
|
||||||
'direction' => 'ltr',
|
'direction' => 'ltr',
|
||||||
'codes' => array('sw', 'swissgerman', 'sw_SW'),
|
'codes' => array('sw', 'swissgerman', 'de-CH'),
|
||||||
'ckeditor' => NULL
|
'ckeditor' => NULL
|
||||||
),
|
),
|
||||||
'es' => array(
|
'es' => array(
|
||||||
'name' => 'Español',
|
'name' => 'Español',
|
||||||
'folder' => 'spanish',
|
'folder' => 'spanish',
|
||||||
'direction' => 'ltr',
|
'direction' => 'ltr',
|
||||||
'codes' => array('esp', 'spanish', 'es_ES'),
|
'codes' => array('esp', 'spanish', 'es-ES'),
|
||||||
'ckeditor' => NULL
|
'ckeditor' => NULL
|
||||||
),
|
),
|
||||||
'no' => array(
|
'no' => array(
|
||||||
'name' => 'norsk',
|
'name' => 'norsk',
|
||||||
'folder' => 'norwegian',
|
'folder' => 'norwegian',
|
||||||
'direction' => 'ltr',
|
'direction' => 'ltr',
|
||||||
'codes' => array('no', 'norwegian', 'no_NO'),
|
'codes' => array('no', 'norwegian', 'no-NO'),
|
||||||
'ckeditor' => NULL
|
'ckeditor' => NULL
|
||||||
),
|
),
|
||||||
'da' => array(
|
'da' => array(
|
||||||
'name' => 'dansk',
|
'name' => 'dansk',
|
||||||
'folder' => 'danish',
|
'folder' => 'danish',
|
||||||
'direction' => 'ltr',
|
'direction' => 'ltr',
|
||||||
'codes' => array('da', 'danish', 'da_DA'),
|
'codes' => array('da', 'danish', 'da-DA'),
|
||||||
'ckeditor' => NULL
|
'ckeditor' => NULL
|
||||||
),
|
),
|
||||||
'pt' => array(
|
'pt' => array(
|
||||||
'name' => 'Português de Portugal',
|
'name' => 'Português de Portugal',
|
||||||
'folder' => 'portuguese',
|
'folder' => 'portuguese',
|
||||||
'direction' => 'ltr',
|
'direction' => 'ltr',
|
||||||
'codes' => array('ptb', 'portuguese-portugal', 'pt_PT'),
|
'codes' => array('ptb', 'portuguese-portugal', 'pt-PT'),
|
||||||
'ckeditor' => 'pt-pt'
|
'ckeditor' => 'pt-pt'
|
||||||
),
|
),
|
||||||
'tr' => array(
|
'tr' => array(
|
||||||
'name' => 'Türkçe',
|
'name' => 'Türkçe',
|
||||||
'folder' => 'turkish',
|
'folder' => 'turkish',
|
||||||
'direction' => 'ltr',
|
'direction' => 'ltr',
|
||||||
'codes' => array('tr', 'turkish', 'tr_TR'),
|
'codes' => array('tr', 'turkish', 'tr-TR'),
|
||||||
'ckeditor' => NULL
|
'ckeditor' => NULL
|
||||||
),
|
),
|
||||||
'fr' => array(
|
'fr' => array(
|
||||||
'name' => 'Français',
|
'name' => 'Français',
|
||||||
'folder' => 'french',
|
'folder' => 'french',
|
||||||
'direction' => 'ltr',
|
'direction' => 'ltr',
|
||||||
'codes' => array('fra', 'french', 'fr_FR'),
|
'codes' => array('fra', 'french', 'fr-FR'),
|
||||||
'ckeditor' => NULL
|
'ckeditor' => NULL
|
||||||
),
|
),
|
||||||
'jp' => array(
|
'jp' => array(
|
||||||
'name' => '日本語',
|
'name' => '日本語',
|
||||||
'folder' => 'japanese',
|
'folder' => 'japanese',
|
||||||
'direction' => 'ltr',
|
'direction' => 'ltr',
|
||||||
'codes' => array('jp', 'japanese', 'jp_JP'),
|
'codes' => array('jp', 'japanese', 'jp-JP'),
|
||||||
'ckeditor' => NULL
|
'ckeditor' => NULL
|
||||||
),
|
),
|
||||||
'pl' => array(
|
'pl' => array(
|
||||||
'name' => 'Polski',
|
'name' => 'Polski',
|
||||||
'folder' => 'polish',
|
'folder' => 'polish',
|
||||||
'direction' => 'ltr',
|
'direction' => 'ltr',
|
||||||
'codes' => array('plk', 'polish', 'pl_PL'),
|
'codes' => array('plk', 'polish', 'pl-PL'),
|
||||||
'ckeditor' => NULL
|
'ckeditor' => NULL
|
||||||
),
|
),
|
||||||
'ru' => array(
|
'ru' => array(
|
||||||
'name' => 'Русский',
|
'name' => 'Русский',
|
||||||
'folder' => 'russian',
|
'folder' => 'russian',
|
||||||
'direction' => 'ltr',
|
'direction' => 'ltr',
|
||||||
'codes' => array('rus', 'russian', 'ru_RU'),
|
'codes' => array('rus', 'russian', 'ru-RU'),
|
||||||
'ckeditor' => NULL
|
'ckeditor' => NULL
|
||||||
),
|
),
|
||||||
'cn' => array(
|
'cn' => array(
|
||||||
'name' => '繁體中文',
|
'name' => '繁體中文',
|
||||||
'folder' => 'chinese-simplified',
|
'folder' => 'chinese-simplified',
|
||||||
'direction' => 'ltr',
|
'direction' => 'ltr',
|
||||||
'codes' => array('cht', 'chinese-simplified', 'zh_CN'),
|
'codes' => array('cht', 'chinese-simplified', 'zh-CN'),
|
||||||
'ckeditor' => NULL
|
'ckeditor' => NULL
|
||||||
),
|
),
|
||||||
'zh' => array(
|
'zh' => array(
|
||||||
'name' => '繁體中文',
|
'name' => '繁體中文',
|
||||||
'folder' => 'chinese-traditional',
|
'folder' => 'chinese-traditional',
|
||||||
'direction' => 'ltr',
|
'direction' => 'ltr',
|
||||||
'codes' => array('cht', 'chinese-traditional', 'zh_TW'),
|
'codes' => array('cht', 'chinese-traditional', 'zh-TW'),
|
||||||
'ckeditor' => NULL
|
'ckeditor' => NULL
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@ -121,5 +121,5 @@ $config['supported_languages'] = array(
|
|||||||
* chinese-simplified (cn) | chinese-traditional (zh)
|
* chinese-simplified (cn) | chinese-traditional (zh)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
$config['default_language'] = 'en';
|
$config['language'] = 'en';
|
||||||
|
|
||||||
|
@ -1,58 +1,76 @@
|
|||||||
<?php defined('BASEPATH') OR exit('No direct script access allowed.');
|
<?php
|
||||||
|
/**
|
||||||
|
* Class and Function List:
|
||||||
|
* Function list:
|
||||||
|
* - pick_language()
|
||||||
|
* Classes list:
|
||||||
|
*/
|
||||||
|
defined('BASEPATH') OR exit('No direct script access allowed.');
|
||||||
/**
|
/**
|
||||||
* Determines the language to use.
|
* Determines the language to use.
|
||||||
*
|
*
|
||||||
* This is called from the Codeigniter hook system.
|
* This is called from the Codeigniter hook system.
|
||||||
* The hook is defined in application/config/hooks.php
|
* The hook is defined in application/config/hooks.php
|
||||||
*/
|
*/
|
||||||
function pick_language() {
|
|
||||||
|
|
||||||
|
function pick_language()
|
||||||
|
{
|
||||||
require APPPATH . '/config/language.php';
|
require APPPATH . '/config/language.php';
|
||||||
|
|
||||||
// Re-populate $_GET
|
// Re-populate $_GET
|
||||||
parse_str($_SERVER['QUERY_STRING'], $_GET);
|
parse_str($_SERVER['QUERY_STRING'], $_GET);
|
||||||
|
|
||||||
// Lang set in URL via ?lang=something
|
// Lang set in URL via ?lang=something
|
||||||
if (!empty($_GET['lang'])) {
|
|
||||||
|
if (!empty($_GET['lang']))
|
||||||
|
{
|
||||||
|
|
||||||
// Turn en-gb into en
|
// Turn en-gb into en
|
||||||
$lang = strtolower(substr($_GET['lang'], 0, 2));
|
$lang = strtolower(substr($_GET['lang'], 0, 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lang has already been set and is stored in a session
|
// Lang has already been set and is stored in a session
|
||||||
elseif (!empty($_SESSION['lang_code'])) {
|
elseif (!empty($_SESSION['lang_code']))
|
||||||
|
{
|
||||||
$lang = $_SESSION['lang_code'];
|
$lang = $_SESSION['lang_code'];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lang has is picked by a user.
|
// Lang has is picked by a user.
|
||||||
elseif (!empty($_COOKIE['lang_code'])) {
|
elseif (!empty($_COOKIE['lang_code']))
|
||||||
|
{
|
||||||
$lang = strtolower($_COOKIE['lang_code']);
|
$lang = strtolower($_COOKIE['lang_code']);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Still no Lang. Lets try some browser detection then
|
// Still no Lang. Lets try some browser detection then
|
||||||
elseif (!empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
|
elseif (!empty($_SERVER['HTTP_ACCEPT_LANGUAGE']))
|
||||||
|
{
|
||||||
|
|
||||||
// explode languages into array
|
// explode languages into array
|
||||||
$accept_langs = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
|
$accept_langs = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
|
||||||
$supported_langs = array_keys($config['supported_languages']);
|
$supported_languages = $config['supported_languages'];
|
||||||
|
|
||||||
// Check them all, until we find a match
|
// Check them all, until we find a match
|
||||||
foreach ($accept_langs as $accept_lang) {
|
foreach ($accept_langs as $al)
|
||||||
if (strpos($accept_lang, '-') === 2) {
|
{
|
||||||
// Turn pt-br into br
|
|
||||||
$lang = strtolower(substr($accept_lang, 3, 2));
|
|
||||||
// Check its in the array. If so, break the loop, we have one!
|
// Check its in the array. If so, break the loop, we have one!
|
||||||
if (in_array($lang, $supported_langs)) {
|
foreach ($supported_languages as $i => $l)
|
||||||
|
{
|
||||||
|
|
||||||
|
if ($al == $l['codes'][2])
|
||||||
|
{
|
||||||
|
$lang = $i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Turn en-gb into en
|
|
||||||
$lang = strtolower(substr($accept_lang, 0, 2));
|
|
||||||
// Check its in the array. If so, break the loop, we have one!
|
|
||||||
if (in_array($lang, $supported_langs)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If no language has been worked out - or it is not supported - use the default
|
// 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['default_language'];
|
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
|
// Whatever we decided the lang was, save it for next time to avoid working it out again
|
||||||
|
Loading…
x
Reference in New Issue
Block a user