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>
  • Does this strings "Buy" and "save" are coming from admin side or from your file? – Shubham Khandelwal Oct 29 '18 at 10:28
  • yes it is front side (product detail page) @Shubham – Sagar Dobariya Oct 29 '18 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? – Shubham Khandelwal Oct 29 '18 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 ? – Shashank Kumrawat Oct 29 '18 at 10:34
  • @SagarDobariya any luck with it? Is it a configurable product for what you want the translation? – Daniel Nov 6 '18 at 14:46
0

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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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