Book Image

Magento 2 Development Cookbook

Book Image

Magento 2 Development Cookbook

Overview of this book

With the challenges of growing an online business, Magento 2 is an open source e-commerce platform with innumerable functionalities that gives you the freedom to make on-the-fly decisions. It allows you to customize multiple levels of security permissions and enhance the look and feel of your website, and thus gives you a personalized experience in promoting your business.
Table of Contents (18 chapters)
Magento 2 Development Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Adding a translation file


Magento is made to run in multiple languages. This means that the interface and content needs to be translatable in the configured languages.

In this recipe, you will learn how to make the strings in our module translatable in different languages.

Getting ready

We will create translation files for the module that we created in the previous recipes of this chapter. Ensure that you have the code in your Magento instance.

How to do it...

The following procedure demonstrates how we can manage translations in our module:

  1. To make a test translation, we can create a test translation in the template file that we created in the previous recipe. Add the following code at the end of the file app/code/Packt/HelloWorld/view/frontend/templates/landingspage.phtml:

    <p>
        <?php echo __('Test translation') ?>
    </p>
  2. Go to the /helloworld page and you will see that the text Test translation is added on the page.

  3. To translate this string, we have to create the app/code/Packt...