5

So I have to set a translation for the Mr. and Mrs. prefix options in the one-page checkout form, where a customer fills his name, address, etc.

All the translations so far I have done through the .csv files or in the template files, but this one I cannot find. Even by turning on the Translation inline for frontend - I cannot see which scope is for these 2 elements. I guess it's the Mage_Customer.csv but it doesn't work from there. Neither from the translate.csv file in the design/frontend directory.

Are these optional elements' translations somewhat different? I would appreciate some hints on how to achieve translating this.

3 Answers 3

2

If you set the options via the admin config section Customer Configuration->Name and Address Options then you can set-up each site with different values.

Otherwise by default the block used to translate will belong to Mage_Customer. See template /app/design/frontend/base/default/template/customer/widget/name.phtml.

Since these options are set-up via the admin section there is no "default" translations. You could do one of the following options. I think 1 is the easiest, 2 is the one you should not do and 3 is a good option.

  1. Add them to your translate.csv file,
  2. Add them to Mage_Customer.csv file (please do not do this as these changes will be lost if you update),
  3. Create a custom module that deals with customer translations and put them in it's translation file,
1
  • 2
    While using the translate.csv option does display them in the right language per store view on the site, the emails and order emails will still have the non-translated default value that you entered in the backend.
    – tecjam
    Commented Apr 2, 2015 at 8:27
1

If you want to translate prefix in other Language please follow below Steps that translate prefix option in other language in frontend.

Note: Please installed language pack before these changes.

Copy: /app/code/core/Mage/Customer/Model/Address/Abstract.php to /app/code/local/Mage/Customer/Model/Address/Abstract.php

Replace:

public function getName()
    {
        $name = '';
        $config = Mage::getSingleton('eav/config');
        if ($config->getAttribute('customer_address', 'prefix')->getIsVisible() && $this->getPrefix()) {
            $name .= $this->getPrefix() . ' ';
        }
        $name .= $this->getFirstname();
        if ($config->getAttribute('customer_address', 'middlename')->getIsVisible() && $this->getMiddlename()) {
            $name .= ' ' . $this->getMiddlename();
        }
        $name .=  ' ' . $this->getLastname();
        if ($config->getAttribute('customer_address', 'suffix')->getIsVisible() && $this->getSuffix()) {
            $name .= ' ' . $this->getSuffix();
        }
        return $name;
    }

with:

public function getName()
    {
        $name = '';
        $config = Mage::getSingleton('eav/config');
        if ($config->getAttribute('customer_address', 'prefix')->getIsVisible() && $this->getPrefix()) {
            $preFix = $this->getPrefix();
            $name .= Mage::helper('customer')->__($preFix) . ' ';           
        }
        $name .= $this->getFirstname();
        if ($config->getAttribute('customer_address', 'middlename')->getIsVisible() && $this->getMiddlename()) {
            $name .= ' ' . $this->getMiddlename();
        }
        $name .=  ' ' . $this->getLastname();
        if ($config->getAttribute('customer_address', 'suffix')->getIsVisible() && $this->getSuffix()) {
            $name .= ' ' . $this->getSuffix();
        }
        return $name;
    }

Copy: /app/code/core/Mage/Customer/Model/Customer.php to /app/code/local/Mage/Customer/Model/Customer.php

Replace:

public function getName()
    {
        $name = '';
        $config = Mage::getSingleton('eav/config');
        if ($config->getAttribute('customer', 'prefix')->getIsVisible() && $this->getPrefix()) {
            $name .= $this->getPrefix() . ' ';
        }
        $name .= $this->getFirstname();
        if ($config->getAttribute('customer', 'middlename')->getIsVisible() && $this->getMiddlename()) {
            $name .= ' ' . $this->getMiddlename();
        }
        $name .=  ' ' . $this->getLastname();
        if ($config->getAttribute('customer', 'suffix')->getIsVisible() && $this->getSuffix()) {
            $name .= ' ' . $this->getSuffix();
        }
        return $name;
    }

with:

public function getName()
    {
        $name = '';
        $config = Mage::getSingleton('eav/config');
        if ($config->getAttribute('customer', 'prefix')->getIsVisible() && $this->getPrefix()) {
            $preFix = $this->getPrefix();
            $name .= Mage::helper('customer')->__($preFix) . ' ';
        }
        $name .= $this->getFirstname();
        if ($config->getAttribute('customer', 'middlename')->getIsVisible() && $this->getMiddlename()) {
            $name .= ' ' . $this->getMiddlename();
        }
        $name .=  ' ' . $this->getLastname();
        if ($config->getAttribute('customer', 'suffix')->getIsVisible() && $this->getSuffix()) {
            $name .= ' ' . $this->getSuffix();
        }
        return $name;
    }

Copy /app/code/core/Mage/Customer/Block/Address/Renderer/Default.php to /app/code/local/Mage/Customer/Block/Address/Renderer/Default.php

Replace:

public function render(Mage_Customer_Model_Address_Abstract $address, $format=null)
    {
        switch ($this->getType()->getCode()) {
            case 'html':
                $dataFormat = Mage_Customer_Model_Attribute_Data::OUTPUT_FORMAT_HTML;
                break;
            case 'pdf':
                $dataFormat = Mage_Customer_Model_Attribute_Data::OUTPUT_FORMAT_PDF;
                break;
            case 'oneline':
                $dataFormat = Mage_Customer_Model_Attribute_Data::OUTPUT_FORMAT_ONELINE;
                break;
            default:
                $dataFormat = Mage_Customer_Model_Attribute_Data::OUTPUT_FORMAT_TEXT;
                break;
        }

        $formater   = new Varien_Filter_Template();
        $attributes = Mage::helper('customer/address')->getAttributes();

        $data = array();
        foreach ($attributes as $attribute) {
            /* @var $attribute Mage_Customer_Model_Attribute */
            if (!$attribute->getIsVisible()) {
                continue;
            }
            if ($attribute->getAttributeCode() == 'country_id') {
                $data['country'] = $address->getCountryModel()->getName();
            } else if ($attribute->getAttributeCode() == 'region') {
                $data['region'] = Mage::helper('directory')->__($address->getRegion());
            } else {
                $dataModel = Mage_Customer_Model_Attribute_Data::factory($attribute, $address);
                $value     = $dataModel->outputValue($dataFormat);
                if ($attribute->getFrontendInput() == 'multiline') {
                    $values    = $dataModel->outputValue(Mage_Customer_Model_Attribute_Data::OUTPUT_FORMAT_ARRAY);
                    // explode lines
                    foreach ($values as $k => $v) {
                        $key = sprintf('%s%d', $attribute->getAttributeCode(), $k + 1);
                        $data[$key] = $v;
                    }
                }
                $data[$attribute->getAttributeCode()] = $value;
            }
        }

        if ($this->getType()->getHtmlEscape()) {
            foreach ($data as $key => $value) {
                $data[$key] = $this->escapeHtml($value);
            }
        }

        $formater->setVariables($data);

        $format = !is_null($format) ? $format : $this->getFormat($address);

        return $formater->filter($format);
    }

With:

public function render(Mage_Customer_Model_Address_Abstract $address, $format=null)
    {
        switch ($this->getType()->getCode()) {
            case 'html':
                $dataFormat = Mage_Customer_Model_Attribute_Data::OUTPUT_FORMAT_HTML;
                break;
            case 'pdf':
                $dataFormat = Mage_Customer_Model_Attribute_Data::OUTPUT_FORMAT_PDF;
                break;
            case 'oneline':
                $dataFormat = Mage_Customer_Model_Attribute_Data::OUTPUT_FORMAT_ONELINE;
                break;
            default:
                $dataFormat = Mage_Customer_Model_Attribute_Data::OUTPUT_FORMAT_TEXT;
                break;
        }

        $formater   = new Varien_Filter_Template();
        $attributes = Mage::helper('customer/address')->getAttributes();

        $data = array();
        foreach ($attributes as $attribute) {
            //echo $attribute->getAttributeCode(); echo '<br />';
            /* @var $attribute Mage_Customer_Model_Attribute */
            if (!$attribute->getIsVisible()) {
                continue;
            }
            if ($attribute->getAttributeCode() == 'prefix') {
                 $prefixopt = $address->getPrefix();
            }
            if ($attribute->getAttributeCode() == 'country_id') {
                $data['country'] = $address->getCountryModel()->getName();
            } else if ($attribute->getAttributeCode() == 'region') {
                $data['region'] = Mage::helper('directory')->__($address->getRegion());
            } else {
                $dataModel = Mage_Customer_Model_Attribute_Data::factory($attribute, $address);
                $value     = $dataModel->outputValue($dataFormat);
                if ($attribute->getFrontendInput() == 'multiline') {
                    $values    = $dataModel->outputValue(Mage_Customer_Model_Attribute_Data::OUTPUT_FORMAT_ARRAY);
                    // explode lines
                    foreach ($values as $k => $v) {
                        $key = sprintf('%s%d', $attribute->getAttributeCode(), $k + 1);
                        $data[$key] = $v;
                    }
                }
                $data[$attribute->getAttributeCode()] = $value;
            }
        }

        $data['prefix'] = Mage::helper('customer')->__($prefixopt);

        if ($this->getType()->getHtmlEscape()) {
            foreach ($data as $key => $value) {
                $data[$key] = $this->escapeHtml($value);
            }
        }

        $formater->setVariables($data);

        $format = !is_null($format) ? $format : $this->getFormat($address);

        return $formater->filter($format);
    }

Make sure you have added the translation words in your translation CSV. I have successfully done this in Magento 1.9.2.4

1
  • this one resolves the problem. tested with 1.9.3.2
    – Florin P.
    Commented Jul 24, 2017 at 10:50
0

I know its an old threat, but I needed the answer and couldn't find it here. I found the answer myself, for the people who aren't familiar with Magento:

Copy System.xml from /app/code/core/Mage/Customer/etc/ to /app/code/local/Mage/Customer/etc/

Change in System.xml at the prefix label the show_in_store value from 0 to 1. You can now see the label in every store view and give it different values, thus translations.

NOTE: Prefix has a label for activating and a label for the options.

You can also use these values in the transactional emails.

2
  • 1
    This works? Afaik system.xml can not be "overwritten" by copying to local? Commented Apr 8, 2014 at 8:53
  • Fabian is right, I tried this and the file located at /app/code/local/Mage/Customer/etc/system.xml does not seem to overwrite the core file.
    – tecjam
    Commented Apr 2, 2015 at 8:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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