Create a translation dictionary for a theme

What's in this topic

This topic is a step-by-step illustration of creating a default en_US locale dictionary for a custom theme.

Changing default strings

OrangeCo created a custom orange theme that inherits from the Magento Blank theme. Among the other changes, they want to rephrase certain strings used in the Blank theme and modules for the default locale.

Namely, they need the following changes:

  • Change Add to Cart label to Purchase
  • Change Add to Compare label to Compare
  • Change Add to Wish List label to Wishlist

The following image shows a page where the strings meant to be changed are used:

Product page where the Add to Compare string is displayed

To override the strings, OrangeCo plan to use the en_US dictionary file.

So OrangeCo take the following steps:

  1. Run the i18n (internationalization) tool to generate the en_US dictionary for the orange theme:
    php magento2/bin/magento i18n:collect-phrases --output="magento2/app/design/frontend/OrangeCo/orange/i18n/en_US.csv" magento2/app/design/frontend/OrangeCo/orange
    
  2. Open the newly generated magento2/app/design/frontend/OrangeCo/orange/i18n/en_US.csv file and add the following rows:
    "Add to Cart", "Purchase"
    "Add to Compare", "Compare"
    "Add to Wish List", "Wishlist"
    

When the OrangeCo apply the orange theme, the custom strings are used instead default ones.

For example:

Product page where the customized Compare string is displayed

Recommended reading