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
1 Answer
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"– RichardCommented Apr 15, 2016 at 12:15
-
In my Magento 2.3.0 installation I had to translate
"Only %1 left"
. So use%1
instead of%s
.– RickCommented Apr 19, 2019 at 12:05 -
How to add multiple dynamic variables? in php & translate file Commented Mar 22, 2022 at 14:02