Read More
Read More
Menu Close

    Translate newly added phrases in overridden files in PrestaShop 1.7

    In this blog, we will learn how to translate newly created phrases (sentences) in overridden templates, controllers, or classes.

    In PrestaShop module development sometimes we need to override core PrestaShop files from a module so there may be a need to add some validation messages on these files.

    The issue arises in the translation of these newly added phrases because translations of these phrases do not exist in Prestashop’s default language pack of translations. So when we check these phrases in

    International ->Translations section in the respective Translation domain then these phrases do not appear for translations.

    Let’s understand with an example,

    Searching for an experienced
    Prestashop Company ?
    Read More

    Suppose, we override a core template file “/themes/classic/templates/catalog/product.tpl” from the module and added a new phrase like this

    {block name='page_content_container'}
      <section class="page-content" id="content">
        {block name='page_content'}
          {block name='product_flags'}
            <ul class="product-flags">
              {foreach from=$product.flags item=flag}
                <li class="product-flag {$flag.type}">{$flag.label}</li>
              {/foreach}
            </ul>
          {/block}
    
          {block name='product_cover_thumbnails'}
            {include file='catalog/_partials/product-cover-thumbnails.tpl'}
          {/block}
          <div class="scroll-box-arrows">
            <i class="material-icons left"></i>
            <i class="material-icons right"></i>
          </div>
        {/block}
       <strong> {l s='This is test message' d='Shop.Theme.Catalog'}</strong>
      </section>
    {/block}

    Now, go to the translation section and check this string, you will see that there is no string in translations

    Prestashop-Translations-Img-1

    Now, go to the app/Resources/translations/default/ShopThemeCatalog.xlf file add the following code

      <file original="themes/classic/templates/catalog/product.tpl" source-language="en-US" target-language="en" datatype="plaintext">
        <body>
          <trans-unit id="73fe57e637ad5691f4b24ea842b3fb82">
            <source>This is test message</source>
            <target>This is test message</target>
            <note>Line</note>
          </trans-unit>
          // don't modify other text, only add newly created text
        </body>
      </file>
    Prestashop-Translations-Img-2

    Now, this string will be visible in translation sections and can be translated into any language.

    Prestashop-Translations-Img-3

    Similarly, this process will also work for controllers and classes.

    That’s all about this blog.

    If any issue or doubt please feel free to mention it in the comment section.

    I would be happy to help.

    Also, you can explore our PrestaShop Development Services & a large range of quality PrestaShop Modules.

    For any doubt contact us at [email protected]

    . . .
    Discuss on Helpdesk

    Leave a Comment

    Your email address will not be published. Required fields are marked*


    Be the first to comment.

    Back to Top