I want to be able to use $this->__('String to translate')
in an external script. How do I do this? Magento version 1.5.1.0
.
Magento translations in external script
Asked Answered
This should work:
require 'app/Mage.php'; // here you should use the correct path to Mage.php file
Mage::app();
Mage::getSingleton('core/translate')->init('sv_SE', true); // UPDATE
$to_translate = "String to translate";
$translated = Mage::helper('core')->__($to_translate);
I have added a new line of code to force the Magento translator work in sv_SE language. Not sure if it works, but the best way to accomplish your task would be to create different store views for each language: magentocommerce.com/design_guide/articles/… –
Schooling
The init function expects an area as a parameter, not a locale. Please see the correct answer below: Mage::getSingleton('core/translate')->setLocale('sv_SE')->init('frontend', true); –
Cocke
How can we done this activity in magento2 –
Tubular
I think the right way to set locale is:
Mage::getSingleton('core/translate')->setLocale('sv_SE')->init('frontend', true);
If you copy and paste this code, this will retrieve the transactions without using the cache, the right way is:
Mage::getSingleton('core/translate')->setLocale('sv_SE')->init('frontend');
You're warned! –
Britten This should work:
require 'app/Mage.php'; // here you should use the correct path to Mage.php file
Mage::app();
Mage::getSingleton('core/translate')->init('sv_SE', true); // UPDATE
$to_translate = "String to translate";
$translated = Mage::helper('core')->__($to_translate);
Thank you, seems to be working (no errors) but it doesn't translate if I put a translation in the
translate.csv
file. How do I tell it which language to use? I want it to use sv_SE
. –
Myrmecophagous I have added a new line of code to force the Magento translator work in sv_SE language. Not sure if it works, but the best way to accomplish your task would be to create different store views for each language: magentocommerce.com/design_guide/articles/… –
Schooling
The init function expects an area as a parameter, not a locale. Please see the correct answer below: Mage::getSingleton('core/translate')->setLocale('sv_SE')->init('frontend', true); –
Cocke
How can we done this activity in magento2 –
Tubular
© 2022 - 2024 — McMap. All rights reserved.
translate.csv
file. How do I tell it which language to use? I want it to usesv_SE
. – Myrmecophagous