feature 2651: fallback language, failed when the "child" file does not exists

git-svn-id: http://piwigo.org/svn/trunk@25288 68402e56-0260-453c-a942-63ccdbb3a9ee
This commit is contained in:
mistic100
2013-11-01 15:34:30 +00:00
parent 41a74a821e
commit af040415e2
+30 -1
View File
@@ -1352,6 +1352,31 @@ function get_pwg_charset()
return $pwg_charset;
}
/**
* returns the parent language of the current language or any language
* @since 2.6
* @param string $lang_id
* @return string
*/
function get_parent_language($lang_id=null)
{
if (empty($lang_id))
{
global $lang_info;
return !empty($lang_info['parent']) ? $lang_info['parent'] : null;
}
else
{
$f = PHPWG_ROOT_PATH.'language/'.$lang_id.'/common.lang.php';
if (file_exists($f))
{
include($f);
return !empty($lang_info['parent']) ? $lang_info['parent'] : null;
}
}
return null;
}
/**
* includes a language file or returns the content of a language file
* availability of the file
@@ -1402,6 +1427,10 @@ function load_language($filename, $dirname = '',
{
$languages[] = $user['language'];
}
if ( ($parent = get_parent_language()) != null)
{
$languages[] = $parent;
}
if ( ! @$options['no_fallback'] )
{
if ( defined('PHPWG_INSTALLED') )
@@ -1453,7 +1482,7 @@ function load_language($filename, $dirname = '',
$parent_language = !empty($load_lang_info['parent']) ? $load_lang_info['parent'] : (
!empty($lang_info['parent']) ? $lang_info['parent'] : null );
if (!empty($parent_language))
if (!empty($parent_language) and $parent_language != $selected_language)
{
@include(str_replace($selected_language, $parent_language, $source_file));
}