I always use %s variable as a placeholder when there is error or success such as this code:
Mage::getSingleton('customer/session')->addError(Mage::helper('module')
->__('Hi %s, there is an error', $name));
The problem is: sometimes it works, sometimes it doesn't. Surely the $name does contain a valid string value (I've var_dump it many times). Do you know why?
As others have noted, you're not limited to one argument in your translated string. Some examples:
One argument, in one place:
Mage::helper('module')->__('Hi %s, there is an error', $name);
Two arguments, in two places:
Mage::helper('module')->__('Hi %s, there is an error with code %s', $name, $code);
One argument, in two places:
Mage::helper('module')->__('Hi %1$s, there is an error. Your name is %1$s', $name);
Two arguments, swapping places:
// Template or block file
Mage::helper('module')->__('Hi %1$s %2$s, there is an error', $firstname, $lastname);
// CSV translation
"Hi %1$s %2$s, there is an error", "%2$s, %1$s received an error"
Documentation on the PHP function being used to power this can be found here: vsprintf
(PS: The double-quoting that knase is talking about only applies to your CSV file, where a double-quote is an escaped single quote.)
%s varible work in translate magento. You can write in .csv translate file such as in example:
"Hi %s, there is an error","An error is %s"
Or if you use "%s" for translate you must write double slashe twiсe for shield. Look example:
"Hi ""%s"", there is an error.","An error is ""%s""."
You write for this translate:
Mage::helper('module')->__('Hi "%s", there is an error', $name);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With