Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Display Attribute label - how to use translation
 
Gui
Guru
 
Avatar
Total Posts:  588
Joined:  2008-03-09
 

Hi,

I have a strange problem. I would like to display a custom Attribute on the product view page but I can’t seem to get it translated. It only shows the Admin label instead of the translation. This is in the section next to the image. It is perfectly translated under: Additional information.

this is the code i’m using:

echo $_product->getResource()->getAttribute('my_attribute')->getFrontend()->getLabel($_product);

Running 1.3.1. with a spinoff of the Modern theme.

Am I missing something that should also be called?

Thanks
Gui

 
Magento Community Magento Community
Magento Community
Magento Community
 
Rainbow Forest
Jr. Member
 
Avatar
Total Posts:  23
Joined:  2009-04-29
Belgrade, Serbia
 

I had the same issue until I figured out that I need to change the store view while i’m on a product admin/backend page, and then enter the translated label for that specific store view (language site) while i’m editing product info.

Then it should show translated label when you switch store views in frontend. At least that worked for me.  smile

 
Magento Community Magento Community
Magento Community
Magento Community
 
Jools
Sr. Member
 
Total Posts:  95
Joined:  2009-03-05
 
Gui - 10 May 2009 11:58 PM

Hi,

echo $_product->getResource()->getAttribute('my_attribute')->getFrontend()->getLabel($_product);

I’m having the same problem. However if print one on the attribute.phtml template it works. I’m assuming it needs to load the locale stuff for the attribute labels somehow or ?

 
Magento Community Magento Community
Magento Community
Magento Community
 
freakalis
Jr. Member
 
Total Posts:  19
Joined:  2009-01-19
 

Anyone who got a solutions for this? I have the same problem. It only takes the Default label and not the store version.

 
Magento Community Magento Community
Magento Community
Magento Community
 
shmk
Sr. Member
 
Total Posts:  297
Joined:  2009-10-28
 

I’m having the same problem, anyone knows how is generated the “Additional information” in the product view? (that is correctly translated)

Some informations I’ve taking exploring the database and I hope could help someone to find a solution:
- in the table “eav_attribute” there’s a field called “frontend_label” that is the default label value (it seems it’s the one that getFrontend() takes)
- in the table “core_translate” there are the translations of the attributes you’ve set in the administration area.

 
Magento Community Magento Community
Magento Community
Magento Community
 
julezz
Jr. Member
 
Total Posts:  15
Joined:  2008-12-10
 

Still the same problem.
Does anyone has help?

the right Label works for the shown Attributes in Frontend with \app\code\core\Mage\Catalog\Block\Product\View\Attributes.php
public function getAdditionalData(array $excludeAttr = array())

thanks & kind regards,
julezz

 
Magento Community Magento Community
Magento Community
Magento Community
 
bobbyd1
Jr. Member
 
Total Posts:  11
Joined:  2010-03-02
 

Try this;

$_product->getResource()->getAttribute('my_attribute')->getStoreLabel();
 
Magento Community Magento Community
Magento Community
Magento Community
 
nikola99
Member
 
Total Posts:  47
Joined:  2010-04-09
 

I’ve tried all of the suggestions above to no avail. The weird thing is that for some attributes $_attribute->getStoreLabel() works, while for others it returns a blank. Looking at eav_attribute_label and eav_attribute the differences between the two attributes are the type only.

Finally, for one attribute only, I was able to get this to work:

$allStoreLabels $_attribute->getStoreLabels();
echo 
$allStoreLabels [Mage::app()->getStore()->getStoreId()];

Anyone have any idea why this is?

 
Magento Community Magento Community
Magento Community
Magento Community
 
nikola99
Member
 
Total Posts:  47
Joined:  2010-04-09
 

I think this takes all possibilities in consideration. I used this in app/design/frontend/nti/default/template/catalog/product/view/type/grouped.phtml

<?php 
// Get the store label. Fall back on manually getting it from a list of labels, finally use the Frontend Label
if($_attribute->getStoreLabel()) {
    
echo $_attribute->getStoreLabel();
}
else {
    $storeLabels 
$_attribute->getStoreLabels(); 
    if(
array_key_exists(Mage::app()->getStore()->getStoreId(), $storeLabels)) {
        
echo $storeLabels[Mage::app()->getStore()->getStoreId()];
    
else {
        
echo $_attribute->getFrontendLabel();
    
}
}?>
 
Magento Community Magento Community
Magento Community
Magento Community
 
mrgalaxy
Jr. Member
 
Total Posts:  27
Joined:  2009-10-22
 

The suggestion by Nikola works great!

Thanks!

 
Magento Community Magento Community
Magento Community
Magento Community
 
choussamaster
Sr. Member
 
Total Posts:  93
Joined:  2009-07-14
 

for who need to show the attribute label in the cart page ‘default.phtml” file
change <dt>htmlEscape($_option[’label’]) ?></dt> by
<?php $attributeLabel = Mage::getResourceModel('eav/entity_attribute_collection')
->setCodeFilter($_option['label'])->getFirstItem()->getFrontend_label();?>
<dt><?php echo $this->htmlEscape($attributeLabel) ?> :</dt>

 
Magento Community Magento Community
Magento Community
Magento Community
 
ethos
Jr. Member
 
Total Posts:  9
Joined:  2011-02-09
 

It seems that…

$_product->getResource()->getAttribute(’my_attribute’)->getStoreLabel();
...refers to the current store
$_product->getResource()->getAttribute(’my_attribute’)->getFrontEndLabel();
...refers to default store view

 
Magento Community Magento Community
Magento Community
Magento Community
 
Exploratus
Jr. Member
 
Total Posts:  3
Joined:  2011-12-22
 

getStoreLabel() worked for me for using the translated label!  Thats it!.

 
Magento Community Magento Community
Magento Community
Magento Community
 
hotelwww2
Jr. Member
 
Total Posts:  11
Joined:  2012-11-29
 
bobbyd1 - 20 April 2010 10:51 AM

Try this;

$_product->getResource()->getAttribute('my_attribute')->getStoreLabel();

Worked for me! Thanks!

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top