0

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.

2 Answers 2

1

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.

3
  • Not a chance for this. I've added custom translate for header minicart but i18n text was not translated. Go to Checkout, Ga naar de checkout Commented Aug 16, 2016 at 14:13
  • I'm not sure i'm understanding you correctly, but what file are you placing the translation in? Are you able to do any other translation in that file, just not the "Go to Checkout"? Make sure that the translation file is working first and then we can trouble shoot what might be going wrong.
    – circlesix
    Commented Aug 16, 2016 at 19:17
  • 1
    Yes my translation file works when it comes to translate other strings. Texts Go to Checkout and View and edit cart from header minicart is not translated. Commented Aug 17, 2016 at 6:18
1

"1 item in cart" is display form Below file. vendor/magento/module-checkout/view/frontend/web/template/summary/cart-items.html

<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>

For translation text Item in Cart You need to create module follow below step.

Step-1 create foldar app/i18n/OnTap/en_GB/

step-2 create composer.json file

app/i18n/OnTap/en_GB/composer.json

{
  "name": "ontap/language-en_gb",
  "description": "English (GB) language",
  "version": "1.0.0",
  "license": [
    "OSL-3.0",
    "AFL-3.0"
  ],
  "require": {
    "magento/framework": "100.1.*"
  },
  "type": "magento2-language",
  "autoload": {
    "files": [
      "registration.php"
    ]
  }
}

Step-3 create app/i18n/OnTap/en_GB/language.xml

<?xml version="1.0"?> "urn:magento:framework:App/Language/package.xsd"> <code>en_GB</code> <vendor>OnTap</vendor> <package>en_GB</package> </language>

step-4 create app/i18n/OnTap/en_GB/registration.php

<?php \Magento\Framework\Component\ComponentRegistrar::register( \Magento\Framework\Component\ComponentRegistrar::LANGUAGE, 'ontap_en_gb', __DIR__ );

step-5 create csv file app/i18n/OnTap/en_GB/en_GB.csv add below text

Item in Cart,Item in Basket

remove static data from pub/static/

rm -rf pub/static/frontend

remove cache

rm -rf var/cache/ var/generation/ var/page_cache/ var/view_preprocessed/

genrate static data

php bin/magento setup:static-content:deploy

Now Item in Cart is display with Item in Basket

1
  • text is inside web/ foldar path so that's why you need to create module. web/template/summary/cart-items.html Using this module You can traslate nay web/template text like My Cart (1 item),My Basket (1 item) My Cart (%1 items),My Basket (%1 items)
    – laxita
    Commented Jul 10, 2017 at 7:38

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.