In Magento1 we can get translated string by

_getTranslatedString() from app/code/core/Mage/Core/Model/Translate.php

but in Magento2 there is not such methods. Is there any alternative method available for this?

  • What you want to translate? Oct 9 '18 at 8:34
  • I want to translate string :)
    – Max
    Oct 9 '18 at 8:48
  • I mean you want to translate simply string in phtml for different language? Oct 9 '18 at 8:55
  • I need to log all translated string in my custom file . In Magento 1 I can do it with just calling _getTranslatedString() method so I am looking same method in Magento 2
    – Max
    Oct 9 '18 at 9:53

I am not more knowledge about Magento 1 and _getTranslatedString() function but as per your query this might be help to you.

Magento 2 already has a command that can collect all the texts from a certain folder that are translatable.

Since one module can mean 1 folder, let's say your module name is app/code/Vendor/Module you can collect all translatable texts like this:

bin/magento i18n:collect-phrases app/code/Vendor/Module/ -o app/code/Vendor/Module/i18n/en_US_raw.csv

Just make sure the folder i18n exists inside your module.

For more details Check this

  • Yes, it can collect the only original words not translatable and I am looking for translatable word. For ex. "Hi" and in csv file it has "hello" then it should return "hello"
    – Max
    Oct 9 '18 at 10:40

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.