This is a beta release of documentation for Magento 2.4, published for previewing soon-to-be-released functionality. Content in this version is subject to change. Links to the v2.4 code base may not properly resolve until the code is officially released.

Example theme translation dictionary

This topic is a step-by-step tutorial to create 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. When customizing their theme, 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 current strings are used:

Product page where the Add to Compare string is displayed

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

  1. Run the i18n (internationalization) tool to generate the en_US dictionary for the orange theme:

    1
    
    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:

    1
    2
    3
    
    "Add to Cart", "Purchase"
    "Add to Compare", "Compare"
    "Add to Wish List", "Wishlist"
    
  3. Run the deploy command to get localization changes:

    1
    
    bin/magento setup:static-content:deploy
    

Results

When OrangeCo applies the orange theme, the custom strings are used instead of the default.

For example:

Product page where the customized Compare string is displayed

Additional information