Archivi categoria: Solutions

Gettext support for Smarty

Smarty is a great template engine for PHP because it’s very powerful and very easy to use. By separating the PHP logic from the presentation template your code becomes cleaner and easier to maintain, so it’s a good deal.

Anyway Smarty lacks of a native internationalization support, but it’s expandable nature permits to easy come around this problem. Gettext support can be added to Smarty using this plugin. It’s a revisited version of a previous plugin, with some improvement and fixes. Just put it in Smarty’s plugins folder and you are ready to use the added {t}…{/t} tag where you can put text that has to be localized.

With the plugin comes a tool  that extracts all the text string marked by the tag and saves them in a C source file which can be processed with the usual Gettext utility to obtain a classic POT file. You can add localizations and use them to localize the text in your templates!