在我的多语言joomla 2.5页面上,我想使用JoomGallery。图像符合类别。如何根据网页当前语言制作这些类别?
谢谢。 Spikey
答案 0 :(得分:0)
简答:尚不支持翻译类别。作为一种解决方法,您可以使用joomla的字符串stranslation功能。我借口快速而肮脏地触摸设计:主要目标是能够在后端更改管理员的翻译而无需更改管理代码。以下示例将德语作为其基本语言,这意味着:
以下功能有助于自动获取其他语言的正确常量值。
/**
* Remove umlauts and special chars.
*/
if(!function_exists('toASCII')) {
function toASCII($str) {
$str = mb_strtolower($str,'UTF-8'); // Useful if the current server setting is not UTF-8
//$str = strtolower($str);
$str = preg_replace( '#ß#' , "ss", $str ); // maps German ß onto ss
$str = preg_replace( '#ä#' , "ae", $str ); // Æ => AE
$str = preg_replace( '#ö#' , "oe", $str ); // Œ => OE
$str = preg_replace( '#ü#' , "ue", $str ); // œ => oe
$str = preg_replace( '#Ä#' , "ae", $str ); // Æ => AE
$str = preg_replace( '#Ö#' , "oe", $str ); // Œ => OE
$str = preg_replace( '#Ü#' , "ue", $str ); // œ => oe
$str = preg_replace( '# #' , "", $str ); // remove spaces
$str = preg_replace( '#-#' , "", $str ); // remove hyphens
$str = preg_replace( "#'#" , "", $str ); // remove apostrophs
$str = preg_replace( "#/#" , "", $str ); // remove apostrophs
$str = preg_replace( "#\(#" , "", $str ); // remove apostrophs
$str = preg_replace( "#\)#" , "", $str ); // remove apostrophs
$str = preg_replace( "#\.#" , "", $str ); // remove apostrophs
$str = preg_replace( "#,#" , "", $str ); // remove apostrophs
$str = preg_replace( "#\[#" , "", $str ); // remove apostrophs
$str = preg_replace( "#\]#" , "", $str ); // remove apostrophs
// Process all other special chars
$str = strtr(utf8_decode($str),
utf8_decode('ŠŒŽšœžŸ¥µÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿ'),
'SOZsozYYuAAAAAAACEEEEIIIIDNOOOOOOUUUUYsaaaaaaaceeeeiiiionoooooouuuuyy');
return strtoupper($str);
}
}
function translate($de_string) {
// Translate all JoomGallery category names
$menu = JFactory::getApplication()->getMenu();
$active = $menu->getActive();
$activeItemLanguage = $active->language;
$lang = substr($activeItemLanguage, 0, 2);
// Do not translate german category names
$trans_str = $de_string;
if ($lang != "de") {
// Parse all category names and replace them with an existing override-string.
$const = toASCII($trans_str);
$trans_str = JText::_($const);
}
return $trans_str;
}
如何使用:替换显示类别名称的模板中的字符串函数:
<?php echo translate($this->escape($row->name)); ?>
而不是
<?php echo $this->escape($row->name); ?>