I've been trying to translate my entire site, and so far it is good. My only problem is that I cannot translate the "Only X left" text on my product page. How can I change this? Thanks Sebastian


How is this being printed in your template? For a string to be translatable it needs to be passed through the translate function which is $this->__() within a block. This way you can use your translation csv files to match the string and replace it.

In your case it is slightly more complex as there is dynamic content. Have a look at app/design/frontend/base/default/template/cataloginventory/stockqty/default.phtml.

echo $this->__('Only %s left', ($this->getStockQty()))

You will see that the X value is a %s and the second parameter to the translate function is the stock count, the %s will be replaced with the stock count at page render.

So in your translation file you should be able to replace the original string, e.g

'Only %s left', 'There are %s products left'

For example see app/locale/fr_FR/Mage_CatalogInventory.csv line 31

  • Use double quotes in your translation file to enclose each string, if you need to escape double quotes within the string, use two double quotes in place of one e.g "There are ""%s"" products left" – Richard Apr 15 '16 at 12:15
  • In my Magento 2.3.0 installation I had to translate "Only %1 left". So use %1 instead of %s. – Rick Apr 19 at 12:05

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.