8

I'm building a custom page.

I add breadcrumbs like this (and it works well).

<brand_brand_index translate="label">
        <reference name="breadcrumbs">
            <action method="addCrumb">
                <crumbName>Home</crumbName>
                <crumbInfo>
                    <label>Home</label>
                    <title>Home</title>
                    <link>/</link>
                </crumbInfo>
            </action>
            <action method="addCrumb">
                <crumbName>All Brands</crumbName>
                <crumbInfo>
                    <label>All Brands</label>
                    <title>All Brands</title>
                </crumbInfo>
            </action>
        </reference>
        [[...]]
    </brand_brand_index>

The problem is label not translated in front-end. It shows Home / All Brands instead of translated version.

The things I made sure:

  1. Added translate="label" to handler
  2. Cache cleared (acctually I turned off caching)
  3. Translation syntax is correct (I put in Mage_Core.csv)
  4. Label is translated properly by php code (eg: $helper->__('All Brands');

Help me to figure it out, please.

Thank you.

  • 1
    When adding translate="label" did you also include module="brand_brand" (or whatever it should be in your case)? – pspahn Jun 18 '14 at 8:09
  • <crumbInfo translate="label" module="brand_brand"> - See: stackoverflow.com/questions/7550429/… – pspahn Jun 18 '14 at 8:24
  • Thank you @pspahn, I try and tell you later. Just a minute. Thank you. – Tran Dinh Khanh Jun 18 '14 at 8:29
  • In your link, the answer says If the module attribute is not present, the core module is used. I add translate term in Mage_Core.csv in the beginning, so why doesn't still work? I just add module name (and module translation file as well) but it still doesn't work. I keep inspecting. A minute. – Tran Dinh Khanh Jun 18 '14 at 8:31
13

To translate a crumb without using a helper, you can use the translate attribute for your action node by using crumbInfo.label and crumbInfo.title.

Exemple:

<reference name="breadcrumbs">
    <action method="addCrumb" translate="crumbInfo.label crumbInfo.title">
        <crumbName>home</crumbName>
        <crumbInfo>
            <label>Home</label>
            <title>Home</title>
            <link>/</link>
        </crumbInfo>
    </action>
    <action method="addCrumb" translate="crumbInfo.label crumbInfo.title">
        <crumbName>brands</crumbName>
        <crumbInfo>
            <label>All Brands</label>
            <title>All Brands</title>
        </crumbInfo>
    </action>
</reference>

It's the better way to translate breadcrumbs, use helpers only if you have the set a custom title depend on URL params or something else.

  • Thank you Frederic. Simple but it works. I've tried it in Magento 1.9.1.0 – Andhi Irawan Aug 21 '15 at 3:10
  • @PeterJaapBlaakmeer Thanks! Yes, I really think my answer should be the accepted answer. It's easier and you don't need another helper. – Frédéric MARTINEZ Sep 4 '15 at 12:32
  • 1
    I marked your answer as accepted because I find it easier to do in many cases. Thank you. Your answer came quite late when I got it done long time ago, that's why it was not be the accepted one. – Tran Dinh Khanh Sep 20 '15 at 21:57
3

Note that you can also generate links for breadcrumbs using helper class.
Using helper class, above XML block may look like:

<brand_brand_index translate="label">
    <reference name="breadcrumbs">
        <action method="addCrumb">
            <crumbName>Home</crumbName>
            <params helper="module/getHomeUrl" />
        </action>
        <action method="addCrumb">
            <crumbName>All Brands</crumbName>
            <params helper="module/getBrandUrl" />
        </action>
    </reference>
    [[...]]
</brand_brand_index>

And add the getHomeUrl() & getBrandUrl() methods in your module's Helper/Data.php as:

class Namespace_Module_Helper_Data extends Mage_Core_Helper_Abstract
{
    //...

    public function getHomeUrl()
    {
        return array(
            'label' => Mage::helper('module')->__('Home'),
            'title' => Mage::helper('module')->__('Home'),
            'link' => Mage::getUrl(),
        );
    }

    public function getBrandUrl()
    {
        return array(
            'label' => Mage::helper('module')->__('All Brands'),
            'title' => Mage::helper('module')->__('All Brands')
        );
    }
}
  • This works pretty well, but do you have any idea on why the translation doesn't work if you use the <crumbInfo><label></label></crumbInfo>-way? – TimPietrusky Aug 28 '14 at 12:48
  • Have posted my answer below, im unable to get the proper breadcrumbs in my custom module – Sushivam Dec 25 '16 at 10:20
0

I am trying the same as below:

in my xml file:

<reference name="root">
        <action method="unsetChild"><alias>breadcrumbs</alias></action>
        <block type="page/html_breadcrumbs" name="breadcrumbs" as="breadcrumbs">
            <action method="addCrumb">
                <crumbName>Home</crumbName>
                <params helper="recipe/getHomeUrl" />
                <!-- <crumbInfo>
                    <label>Home</label>
                    <title>Home</title>
                    <link>/</link>

                </crumbInfo> -->
            </action>
            <action method="addCrumb">
                <crumbName>Recipes</crumbName>
                <crumbInfo>
                    <label>Recipes</label>
                    <title>Recipe Home Page</title>
                    <link>/recipe</link>
                </crumbInfo>
            </action>
            <action method="addCrumb">
                <crumbName>Current Page</crumbName>
                <crumbInfo>
                    <label>Current Page</label>
                    <title>Current Page</title>
                </crumbInfo>
            </action>
        </block>
    </reference>

\app\code\local\Magenshop\Recipe\Helper\Data.php

public function getHomeUrl()
{
    return array(
        'label' => Mage::helper('module')->__('Home'),
        'title' => Mage::helper('module')->__('Home'),
        'link' => Mage::getUrl(),
    );
}

Im getting only:

1) /Recipes/Current Page

2) No Home page link...

  • Make sure your extensions name is "recipe", not "magenshop/recipe". – Tran Dinh Khanh Dec 26 '16 at 3:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.