With a native smarty translation block, you would need to store the text in the .php file, assign the result to a variable, and then include the variable inside .tpl . By translating inside the template, the text is maintained where it is used, which makes everything more user-friendly.
Since you tend to have to translate lots of texts, a short name is warrented, so I have reserved the name "t" for this purpose.
An example template:
{assign var="myemail" value="<a href=\"mailto:thu...@gmail.com\">thu...@gmail.com</a>"}
{t e="html" email=$myemail}Mail to %email|none% for support if percentage > 3%%{/t}
Which will output (normally translated, but not in this case)
Mail to <a href="mailto:thu...@gmail.com">thu...@gmail.com</a> for support if percentage > 3%
Points about the above example:
-The e="html" block args means that ">" is escaped to ">" in the output. e=... uses the standard |escape modifier. The e=... argument defaults to html, so is actually not needed in this case.
-%email% is substituted with the email=... argument
-Normally the content of the substituted %email% is escaped, but since there is a "|none" inside %email|none% it is not in this case. This is the reason why I support "|none" inside the string, instead of in the block args.
-"%" is escaped as "%%"
Other reserved arguments to the "t" block:
-charset: Which charset the escape functions should use
-assign: Assign the result to this variable, instead of outputting it
--------------
In the patch I included an smarty_xgettext.php utility, used for extracting texts into a .pot file for translation, similar to the standard xgettext utility.
This utility also has the ability to merge the extracted texts into an existing .pot file. This means that if the same text exists in both a .php and a .tpl file, and you already generated a .pot file from the .php file, then smarty_xgettext.php will merge the occurances, so it only has to be translated once.
Right now, smarty_xgettext.php uses a regexp to extract the strings from the templates. This almost always works, but there will always be cases where it fails. One could consider hooking into the smarty parser to extract the strings to be translated.
--------------
The gettext setup itself is assumed to have already happened in the php code which uses the "t"-template.
--------------
I have been using this code in production for 6 months. I had to make some small changes to make it suitable for the Smarty distribution; these small changes are not be so well tested.
Regards, Thue