Debug multilang website
This commit is contained in:
parent
a3e56994b6
commit
2d841d9d83
@ -784,7 +784,32 @@ class Translate
|
||||
{
|
||||
// We must keep only main languages
|
||||
if ($mainlangonly) {
|
||||
$arrayofspecialmainlanguages = array('en_US', 'sq_AL', 'ar_SA', 'eu_ES', 'bn_DB', 'bs_BA', 'ca_ES', 'zh_TW', 'cs_CZ', 'da_DK', 'et_EE', 'ka_GE', 'el_GR', 'he_IL', 'kn_IN', 'km_KH', 'ko_KR', 'lo_LA', 'nb_NO', 'fa_IR', 'sr_RS', 'sl_SI', 'uk_UA', 'vi_VN');
|
||||
$arrayofspecialmainlanguages = array(
|
||||
'en'=>'en_US',
|
||||
'sq'=>'sq_AL',
|
||||
'ar'=>'ar_SA',
|
||||
'eu'=>'eu_ES',
|
||||
'bn'=>'bn_DB',
|
||||
'bs'=>'bs_BA',
|
||||
'ca'=>'ca_ES',
|
||||
'zh'=>'zh_TW',
|
||||
'cs'=>'cs_CZ',
|
||||
'da'=>'da_DK',
|
||||
'et'=>'et_EE',
|
||||
'ka'=>'ka_GE',
|
||||
'el'=>'el_GR',
|
||||
'he'=>'he_IL',
|
||||
'kn'=>'kn_IN',
|
||||
'km'=>'km_KH',
|
||||
'ko'=>'ko_KR',
|
||||
'lo'=>'lo_LA',
|
||||
'nb'=>'nb_NO',
|
||||
'fa'=>'fa_IR',
|
||||
'sr'=>'sr_RS',
|
||||
'sl'=>'sl_SI',
|
||||
'uk'=>'uk_UA',
|
||||
'vi'=>'vi_VN'
|
||||
);
|
||||
if (strtolower($regs[1]) != strtolower($regs[2]) && ! in_array($dir, $arrayofspecialmainlanguages)) continue;
|
||||
}
|
||||
// We must keep only languages into MAIN_LANGUAGES_ALLOWED
|
||||
|
||||
@ -1275,7 +1275,7 @@ class Website extends CommonObject
|
||||
/**
|
||||
* Component to select language inside a container (Full CSS Only)
|
||||
*
|
||||
* @param array|string $languagecodes 'auto' to show all languages available for page, or language codes array like array('en_US','fr_FR','de_DE','es_ES')
|
||||
* @param array|string $languagecodes 'auto' to show all languages available for page, or language codes array like array('en','fr','de','es')
|
||||
* @param Translate $weblangs Language Object
|
||||
* @param string $morecss More CSS class on component
|
||||
* @param string $htmlname Suffix for HTML name
|
||||
@ -1287,6 +1287,33 @@ class Website extends CommonObject
|
||||
|
||||
if (!is_object($weblangs)) return 'ERROR componentSelectLang called with parameter $weblangs not defined';
|
||||
|
||||
$arrayofspecialmainlanguages = array(
|
||||
'en'=>'en_US',
|
||||
'sq'=>'sq_AL',
|
||||
'ar'=>'ar_SA',
|
||||
'eu'=>'eu_ES',
|
||||
'bn'=>'bn_DB',
|
||||
'bs'=>'bs_BA',
|
||||
'ca'=>'ca_ES',
|
||||
'zh'=>'zh_TW',
|
||||
'cs'=>'cs_CZ',
|
||||
'da'=>'da_DK',
|
||||
'et'=>'et_EE',
|
||||
'ka'=>'ka_GE',
|
||||
'el'=>'el_GR',
|
||||
'he'=>'he_IL',
|
||||
'kn'=>'kn_IN',
|
||||
'km'=>'km_KH',
|
||||
'ko'=>'ko_KR',
|
||||
'lo'=>'lo_LA',
|
||||
'nb'=>'nb_NO',
|
||||
'fa'=>'fa_IR',
|
||||
'sr'=>'sr_RS',
|
||||
'sl'=>'sl_SI',
|
||||
'uk'=>'uk_UA',
|
||||
'vi'=>'vi_VN'
|
||||
);
|
||||
|
||||
// Load tmppage if we have $websitepagefile defined
|
||||
$tmppage = new WebsitePage($this->db);
|
||||
|
||||
@ -1302,7 +1329,7 @@ class Website extends CommonObject
|
||||
}
|
||||
}
|
||||
|
||||
// Fill with existing translation, nothing if none
|
||||
// Fill $languagecodes array with existing translation, nothing if none
|
||||
if (!is_array($languagecodes) && $pageid > 0)
|
||||
{
|
||||
$languagecodes = array();
|
||||
@ -1325,16 +1352,17 @@ class Website extends CommonObject
|
||||
}
|
||||
}
|
||||
}
|
||||
// Now $languagecodes is always an array
|
||||
// Now $languagecodes is always an array. Example array('en', 'fr', 'es');
|
||||
|
||||
$languagecodeselected = $weblangs->defaultlang; // Because we must init with a value, but real value is the lang of main parent container
|
||||
$languagecodeselected = substr($weblangs->defaultlang, 0, 2); // Because we must init with a value, but real value is the lang of main parent container
|
||||
if (!empty($websitepagefile))
|
||||
{
|
||||
$pageid = str_replace(array('.tpl.php', 'page'), array('', ''), basename($websitepagefile));
|
||||
if ($pageid > 0)
|
||||
{
|
||||
$languagecodeselected = $tmppage->lang;
|
||||
if (!in_array($tmppage->lang, $languagecodes)) $languagecodes[] = $tmppage->lang; // We add language code of page into combo list
|
||||
$pagelang = substr($tmppage->lang, 0, 2);
|
||||
$languagecodeselected = substr($pagelang, 0, 2);
|
||||
if (!in_array($pagelang, $languagecodes)) $languagecodes[] = $pagelang; // We add language code of page into combo list
|
||||
}
|
||||
}
|
||||
|
||||
@ -1373,12 +1401,18 @@ class Website extends CommonObject
|
||||
';
|
||||
$out .= '</style>';
|
||||
$out .= '<ul class="componentSelectLang'.$htmlname.($morecss ? ' '.$morecss : '').'">';
|
||||
|
||||
if ($languagecodeselected)
|
||||
{
|
||||
$shortcode = strtolower(substr($languagecodeselected, -2));
|
||||
// Convert $languagecodeselected into a long language code
|
||||
if (strlen($languagecodeselected) == 2) {
|
||||
$languagecodeselected = (empty($arrayofspecialmainlanguages[$languagecodeselected]) ? $languagecodeselected.'_'.strtoupper($languagecodeselected) : $arrayofspecialmainlanguages[$languagecodeselected]);
|
||||
}
|
||||
|
||||
$countrycode = strtolower(substr($languagecodeselected, -2));
|
||||
$label = $weblangs->trans("Language_".$languagecodeselected);
|
||||
if ($shortcode == 'us') $label = preg_replace('/\s*\(.*\)/', '', $label);
|
||||
$out .= '<a href="'.$url.$languagecodeselected.'"><li><img height="12px" src="medias/image/common/flags/'.$shortcode.'.png" style="margin-right: 5px;"/>'.$label;
|
||||
if ($countrycode == 'us') $label = preg_replace('/\s*\(.*\)/', '', $label);
|
||||
$out .= '<a href="'.$url.$languagecodeselected.'"><li><img height="12px" src="medias/image/common/flags/'.$countrycode.'.png" style="margin-right: 5px;"/>'.$label;
|
||||
$out .= '<span class="fa fa-caret-down" style="padding-left: 5px;" />';
|
||||
$out .= '</li></a>';
|
||||
}
|
||||
@ -1387,11 +1421,17 @@ class Website extends CommonObject
|
||||
{
|
||||
foreach ($languagecodes as $languagecode)
|
||||
{
|
||||
// Convert $languagecode into a long language code
|
||||
if (strlen($languagecode) == 2) {
|
||||
$languagecode = (empty($arrayofspecialmainlanguages[$languagecode]) ? $languagecode.'_'.strtoupper($languagecode) : $arrayofspecialmainlanguages[$languagecode]);
|
||||
}
|
||||
|
||||
if ($languagecode == $languagecodeselected) continue; // Already output
|
||||
$shortcode = strtolower(substr($languagecode, -2));
|
||||
|
||||
$countrycode = strtolower(substr($languagecode, -2));
|
||||
$label = $weblangs->trans("Language_".$languagecode);
|
||||
if ($shortcode == 'us') $label = preg_replace('/\s*\(.*\)/', '', $label);
|
||||
$out .= '<a href="'.$url.$languagecode.'"><li><img height="12px" src="medias/image/common/flags/'.$shortcode.'.png" style="margin-right: 5px;"/>'.$label;
|
||||
if ($countrycode == 'us') $label = preg_replace('/\s*\(.*\)/', '', $label);
|
||||
$out .= '<a href="'.$url.$languagecode.'"><li><img height="12px" src="medias/image/common/flags/'.$countrycode.'.png" style="margin-right: 5px;"/>'.$label;
|
||||
if (empty($i) && empty($languagecodeselected)) $out .= '<span class="fa fa-caret-down" style="padding-left: 5px;" />';
|
||||
$out .= '</li></a>';
|
||||
$i++;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user