Magento:在php中翻译String

时间:2016-10-02 16:31:14

标签: php magento

以某种方式可以在PHP代码中获取Magento中类别的翻译名称吗?即像$category->getTranslatedName之类的东西? 背景:我想按字母顺序对类别进行排序,但在不同的语言中使用不同的名称,这只适用于英语商店视图。我的代码:

foreach ($children as $child) {
    $_children[$i]["child"] = $child;
    $_children[$i]["name"] = $child->getName();
    //gets english name, not the translated
    $i++;
}

if (!function_exists('compare')) {
    function compare($a,$b) {
        return strcmp($a["name"],$b["name"]);
    }
}

usort($_children, "compare");

for ($i=0; $i<count($_children); $i++) {
    //code for main menu here
}

编辑:这是加载$ children的部分(取自renderer.phtml):

$children = $menuTree->getChildren();
$parentLevel = $menuTree->getLevel();
$childLevel = is_null($parentLevel) ? 0 : $parentLevel + 1;

$counter = 1;
$childrenCount = $children->count();

$parentPositionClass = $menuTree->getPositionClass();
$itemPositionClassPrefix = $parentPositionClass ? $parentPositionClass . '-' : 'nav-';

$i = 0;
foreach ($children as $child) {
    $_children[$i]["child"] = $child;
    $_children[$i]["name"] = $child->getName();
    $i++;
}

if (!function_exists('compare')) {
    function compare($a,$b) {
        return strcmp($a["name"],$b["name"]);
    }
}

usort($_children, "compare");

for ($i=0; $i<count($_children); $i++) {
//Code for main menu
}

0 个答案:

没有答案