1

I want to translate "Buy" and "Save" word in tier_price.phtml file.I have added the word in translation csv file but it is not working form me.

Refer screenshot

enter image description here

PATH :

vendor/magento/module-configurable-product/view/base/templates/product/price/tier_price.phtml

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

?>
<script type="text/x-magento-template" id="tier-prices-template">
    <ul class="prices-tier items">
        <% _.each(tierPrices, function(item, key) { %>
        <%  var priceStr = '<span class="price-container price-tier_price">'
                 '<span data-price-amount="' + priceUtils.formatPrice(item.price, currencyFormat) + '"'
                 ' data-price-type=""' + ' class="price-wrapper ">'
                 '<span class="price">' + priceUtils.formatPrice(item.price, currencyFormat) + '</span>'
                 '</span>'
             '</span>'; %>
        <li class="item">
            <%= $t('Buy %1 for %2 each and').replace('%1', item.qty).replace('%2', priceStr) %>
                <strong class="benefit">
                        <%= $t('save') %><span class="percent tier-<%= key %>">&nbsp;<%= item.percentage %></span>%
                </strong>
        </li>
        <% }); %>
    </ul>
</script>
<div data-role="tier-price-block"></div>
5
  • Does this strings "Buy" and "save" are coming from admin side or from your file? Oct 29, 2018 at 10:28
  • yes it is front side (product detail page) @Shubham Oct 29, 2018 at 10:32
  • can you share code how you are showing it in front end i mean you must be echo the word right can u share that line for buy or save anyone? Oct 29, 2018 at 10:34
  • @Sagar Dobariya, have you add this word in ''app/design/frontend/YourVendor/theme/Magento_Catalog/i18n/en_US.csv" ? and have clear cache and re-index ? Oct 29, 2018 at 10:34
  • @SagarDobariya any luck with it? Is it a configurable product for what you want the translation?
    – Daniel
    Nov 6, 2018 at 14:46

7 Answers 7

2

Create a directory app/i18n/Vendorname/en_US(If not there presently)

Run command:

bin/magento i18n:collect-phrases --output "app/i18n/Vendorname/en_US/en_US.csv" --magento

Now this command actually collect all the translatable phrases in csv file and place it in the specified path. Make changes to the csv file as per your requirement and when ready issue command:

bin/magento i18n:pack app/i18n/Vendorname/en_US/en_US.csv -d en_US

This will deploy the translations from your file.

clear the cache etc and you can see your changes.

You will see that each line of the CSV contains 4 fields:

"Original Text","Translated Text",module,Magento_ConfigurableProduct

That allows you to make translations for a specific module.

In your case, these two lines will translate correctly your text:

"Buy %1 for %2 each and","Achetez-en %1 à %2 pièce et",module,Magento_ConfigurableProduct
save,économisez,module,Magento_ConfigurableProduct

In this example, the translation is in French.

Finally, if you want to put your translations in a theme, you just have to put the file containing these two lines into:

app/design/frontend/*ThemeBrand*/*YourTheme*/i18n/fr_FR.csv
0

Here is what I have tried and working --

1) First copy and paste en_US.csv fie from vendor/magento/module-catalog/i18n to your theme directory app/design/frontend/YourVendor/theme/Magento_Catalog/i18n/en_US.csv.

2) and then find below lines in above csv file --

 Buy %1 for %2 each and <strong class=""benefit"">save<span class=""percent tier-%3"">&nbsp;%4</span>%</strong>","Buy %1 for %2 each and <strong class=""benefit"">save<span class=""percent tier-%3"">&nbsp;%4</span>%</strong>

and in this line you can translate buy and save word.

don't forget to clear cache and reindexing via command line.

check below image for what I have tried --

en_US.csv file --

enter image description here

product page (frontend) --

enter image description here

0

app/design/frontend/{Vendor}/{themename}/i18n/language_ISO.csv

language_ISO.csv example : en_US.csv

"Your word","translated word",module,Magento_Modulename

Magento_Modulename example : Magento_catalog

You can also use the inline translation.

0

I found the same problem. I am sure this is a core bug because the string "Buy %1 for %2 each and" is nowhere to find in the js-translation.json. My guess is that it's not picked up because it's in the phtml.

What helped me is overwriting the template in app/design/frontend/Vendor/Theme/Magento_ConfigurableProduct/templates/product/price/tier_price.phtml

You can then simply use the __() function to get your translations.

In your case if you only want to translate "Buy" and "save" it would be:

<script type="text/x-magento-template" id="tier-prices-template">
    <ul class="prices-tier items">
        <% _.each(tierPrices, function(item, key) { %>
        <%  var priceStr = '<span class="price-container price-tier_price">'
                + '<span data-price-amount="' + priceUtils.formatPrice(item.price, currencyFormat) + '"'
                + ' data-price-type=""' + ' class="price-wrapper ">'
                + '<span class="price">' + priceUtils.formatPrice(item.price, currencyFormat) + '</span>'
                + '</span>'
        + '</span>'; %>
        <li class="item">
            <%= '<?php echo __('Buy') ?> %1 for %2 each and'.replace('%1', item.qty).replace('%2', priceStr) %>
            <strong class="benefit">
                <?php echo __('save') ?><span class="percent tier-<%= key %>">&nbsp;<%= item.percentage %></span>%
            </strong>
        </li>
        <% }); %>
    </ul>
</script>
<div data-role="tier-price-block"></div>

Now you can simply add the phrases to your dictionary and translate them.

I hope this helps.

Update:
I created this magento core Issue

0

For me the issue was simpler, turned out that I used an outdated translation file for my language (German), so I had to manually add these translations:

"Buy %1 for %2 each and","Kaufe %1 für je %2 und"
"save","spare"

After clearing the cache, I can see that the text on the product page has now been translated!

0

"Buy %1 for %2 each and","Koop %1 voor %2 elk en"

save and cache clean check

0

I have tried every possible solution mentioned here. But the translation only shows on configurable products, I want to show it with simple products as well.

Any ideas on how to fix this?

This is my code so far

<script type="text/x-magento-template" id="tier-prices-template">
<ul class="">
    <%  var priceStr = '<span class="price-container price-tier_price">'
            + '<span data-price-amount="' + priceUtils.formatPrice(item.price, currencyFormat) + '"'
            + ' data-price-type=""' + ' class="price-wrapper ">'
            + '<span class="price">' + priceUtils.formatPrice(item.price, currencyFormat) + '</span>'
            + '</span>'
        + '</span>'; %>
    <li class="item">
        <%= $t('Koop %1 voor %2 per stuk incl. BTW en').replace('%1', item.qty).replace('%2', priceStr) %>
            <strong class="benefit">
                    <%= $t('bespaar') %><span class="percent tier-<%= key %>">&nbsp;<%= item.percentage %></span>%
            </strong>
    </li>
</ul>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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