Skip to content

Commit 9903751

Browse files
committed
Merge pull request #30 from jnuserful/master
fixed error in Louder::init_language() when the language files don't exist
2 parents ab8ba10 + ca3be54 commit 9903751

File tree

2 files changed

+32
-20
lines changed

2 files changed

+32
-20
lines changed

system/language/es/generic.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
// locale
44
define( "LOCALE", "es_MX.utf-8,es_MX,esp,Español" ); //define locale language
55

6-
$days = array("Lunes","Martes","Miércoles","Jueves","Viernes","Sábado","Domingo");//needed to use %l option for date()
7-
$abbrDays = array("Lun","Mar","Mié","Jue","Vie","Sáb","Dom");//needed to use %D option for date()
8-
6+
$days = array("Domingo","Lunes","Martes","Miércoles","Jueves","Viernes","Sábado");//needed to use %l option for date()
7+
$abbrDays = array("Dom","Lun","Mar","Mié","Jue","Vie","Sáb");//needed to use %D option for date()
98
//Time
109
define( "DATE_FORMAT" , "%d %b %Y" );
11-
define( "DATE_TIME_FORMAT" , $abbrDays[ date("%w") ] . " - %I:%M %p" );//array notation to simulate %D
10+
define( "DATE_TIME_FORMAT" , $abbrDays[ date("w") ] . " - %I:%M %p" );//array notation to simulate %D
1211
define( "TIME_FORMAT" , "%I:%M %p" );
1312
define( "MONTH_FORMAT" , "%d %b" );
1413

system/library/Loader.php

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -283,27 +283,40 @@ function init_language() {
283283

284284
$installed_language = get_installed_language();
285285
$installed_language = array_flip( $installed_language );
286+
287+
$priority_lang = array();
286288

287-
// get the language
288-
if (get('set_lang_id'))
289-
$lang_id = get('set_lang_id');
290-
elseif (isset($_SESSION['lang_id']))
291-
$lang_id = $_SESSION['lang_id'];
292-
else
293-
$lang_id = get_setting('lang_id');
289+
// get the languages
290+
$requested_lang = get('set_lang_id');
291+
if ($requested_lang)// the first in the priority list is the GET query like ?set_lang_id=en
292+
$priority_lang[] = $requested_lang;
293+
294+
if (isset($_SESSION['lang_id']))// the second on the priority list is the previously established
295+
$priority_lang[] = $_SESSION['lang_id'];
294296

295-
// language not found, load the default language
296-
if (!isset($installed_language[$lang_id])) {
297-
$default_language = array_pop($installed_language);
298-
$lang_id = $default_language['lang_id'];
297+
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { // the third is the sent by the browser
298+
299+
foreach (explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']) as $part) {
300+
$priority_lang[] = strtolower(substr($part, 0, 2));
301+
}
299302
}
300303

301-
// set the language in session
302-
$_SESSION['lang_id'] = $lang_id;
304+
$priority_lang[] = get_setting('lang_id');// the fourth is the system
303305

304-
// define the constant
305-
define("LANG_ID", $lang_id);
306+
$priority_lang = array_unique( $priority_lang );
306307

308+
// through the list of langs ​​to see which is the best to use
309+
while ((list(,$lang) = each($priority_lang)) && !defined("LANG_ID")) {
310+
if(isset($installed_language[ $lang ]))
311+
define("LANG_ID", $lang);
312+
}
313+
314+
if(!defined("LANG_ID"))// whether the languages listed is not available
315+
throw new Exception("Can not find the language file");
316+
317+
// set the language in session
318+
$_SESSION['lang_id'] = LANG_ID;
319+
307320
// load the dictionaries
308321
load_lang('generic');
309322

@@ -546,4 +559,4 @@ protected function _get_load_area( ){
546559
protected function __construct() {}
547560

548561

549-
}
562+
}

0 commit comments

Comments
 (0)