4

Magento 2 translation problem (my locale is set to en_US):

I want to change the "Email" label on the Contact Us page to "Email Address:". However, I DO NOT WANT the "Email" label changed anywhere else.

The Contact Us page URL is https://[your m2 site]/contact/ One of the form entry fields is Email. The label translation is "Email". When you examine vendor/magento/module-contact/i18n/en_US.csv I can see Email, Email in there. Obviously, I can't change it here.

We also have "Email" listed in other areas like vendor/magento/module-customer/i18n/en_US.csv. For example, when you browse to the customer account login page you will see it uses the translation from this file. That's fine. I don't want that to change.

So how can I use/extend Magento 2 to help me change JUST the Contact Us page "Email" label via i18n translations?

  • If I create a Storefront Inline Translation that's a global change across the whole site (i.e. "Email" label changes on all pages). No good.
  • If I create a language pack and store the csv file under app/i18n/[THEME]/[locale]/... the change in there is global too. No good.
  • If I create a an i18n csv file under our theme i.e. app/design/frontend/[THEME]/default/i18n/en_US.csv it changes all translations across the site. No good.

So how can I pinpoint my change without having to interfere with vendor/magento?

When reading the guides zooming in on language packages (http://devdocs.magento.com/guides/v2.1/config-guide/cli/config-cli-subcommands-i18n.html) I tried following the steps there.

When I ran the command

bin/magento i18n:pack /var/www/html/magento2/xx_YY.csv -d xx_YY

it created new xx_YY.csv files across all vendor/magento/ modules that I made reference to in Step 1. Is this correct? For example, I can now see: vendor/magento/module-contact/i18n/xx_YY.csv file.

If I now register this language pack maybe that is the only way to fix it? It doesn't feel right.

  • I also tried creating an app/design/frontend/[THEME]/default/Magento_Contact/i18n folder with my en_US.csv file in there. No joy either.

Thanks, Tadhg

0

2 Answers 2

0

Add a row with 'Email Address' and define language-specific values.

Now in .phtml change the echo __('Email') by echo __('Email Address') and this will work.

5
  • Thanks for your reply. However, I don't want to nor should I have to change the .phtml file. Any other ideas?
    – TigerCotty
    Feb 3, 2017 at 9:37
  • Well For same string within a module you cant have two values.When I say change you can apply Magento concept of mapping a new .phtml file to your related block and changing value there.So add/overwrite a block in XML and associate a .phtml file Feb 3, 2017 at 19:45
  • Hello oscprofessionals. Thanks for the feedback. Having to create a new .phtml file seems crazy really. Magento 2 has so many nice internationalisation features but it looks like they forgot one basic requirement. We should be able to do this via a simple translation file and not have to start playing about the xml and templates. The fact that they put so much effort into __(...) across the template system for me indicates that it should be doable. I'm looking into the idea of a language pack at the moment. But it doesn't feel right. Hey ho. T :-)
    – TigerCotty
    Feb 6, 2017 at 8:14
  • one modue can have one transaltion file.So within a module you can not have a single string translate in two different values. Feb 6, 2017 at 16:51
  • Hello. I don't want two different values. I simply want to overwrite the existing value that exists in i18n/en_US.csv for the magento-contact module. I don't want to use layout and templates. I should be able to specify a new value for it somewhere easily (it can't be global either). Looks like it can't be done easily :-(
    – TigerCotty
    Feb 10, 2017 at 12:34
0

You can found that solution using Inline translation.

  1. Navigate to the Admin Panel> Stores> Configuration: enter image description here

  2. Find the Developer tab under Advanced settings and preset it: enter image description here

  3. Open the Translate Inline options: enter image description here

  4. Set the ‘Enable for Frontend’ option to ‘Yes’ and click the ‘Save Config’ button: enter image description here

  5. Store frontend: Then navigate to your store frontend and refresh the page. Thus, different sections of text on your website are placed into red frames: enter image description here

  6. Let’s assume you want to change the ‘Contact us page’ section to ‘Email’. Mouseover the red frame and click the icon with a book: enter image description here

Submit and refresh the page to see the changes on page.

Once you’ve finished with the settings, don’t forget to disable the Translate Inline option and press the ‘Save Config’ button.

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