How to Translate a Phrase in Magento 2.1 Checkout

localisationmagento2

In checkout, under the "Summary" area, I've been able to translate "2 items in cart" using this entry in the .CSV file:

%1 items in cart, %1 artículos en tu carrito, module, Magento_Checkout

This works for 2,3,4… items in cart. However I haven't been able to translate "1 item in cart".

I've tried these entries:

%s item in cart, %1 artículo en tu carrito, module, Magento_Checkout

1 item in cart, 1 artículo en tu carrito, module, Magento_Checkout

None of them work.

Best Answer

I did a grep for the class that the text is in .items-in-cart and found the template that is being used vendor/magento/module-checkout/view/frontend/web/template/summary/cart-items.html. This is a knockout js template, and they have their own logic to how they work and how they are called. But the piece of code that you are looking for is:

<div class="title" data-role="title">
    <strong role="heading"><span data-bind="text: getItemsQty()"></span>
        <!-- ko if: getItemsQty() == 1 -->
        <!-- ko i18n: 'Item in Cart' --><!-- /ko -->
        <!-- /ko -->
        <!-- ko if: getItemsQty() > 1 -->
        <!-- ko i18n: 'Items in Cart' --><!-- /ko -->
        <!-- /ko -->
    </strong>
</div>

You can see from the code that they are using knockout to set the value in a <span> tag and sets the text after wrapped in a ko i18n: translation tag. So in theory you should be able to use the text "Item in Cart" in the translation file and it will translate for you.

Related Topic