Attention! Official Gettext plugin for Smarty has domain support since version 1.1. Check official repository: https://github.com/smarty-gettext/smarty-gettext.
Description:
This is a Smarty gettext plugin modification. It enables domain support and utilize gettext wrapper for PHP,
Why do I use such wrapper for a gettext? It’s simple, not every server has native support for translation. This crafty script gives you fallback in case if it does not.
Usage example:
Init before any template parsed by Smarty:
// include gettext wrapper for PHP
include('./php-gettext/gettext.inc');
// set locale
T_setlocale(LC_MESSAGES, 'en_US');
// load lang file
/* loads ./lang/en_US/LC_MESSAGES/example.mo (do not close path with final slash) */
T_bindtextdomain('example', './lang');
T_bind_textdomain_codeset('example', 'utf-8'); /* just in case */
// set default domain
T_textdomain('default');
Smarty syntax example:
{t domain="example"}This text will be translated using gettext domain example.{/t}
{t}This text will be translated using standard gettext domain.{/t}
Installation:
Simply put file block.t.php into Smarty plugins directory.
Download:
Comments
0 responses to “Smarty gettext with domain support (block t plugin) [depreciated]”
hi
i’m here to inform that this version, inludes domain support as well since 1.1:
https://github.com/smarty-gettext/smarty-gettext
Hey, thank you for this information. I’m updating this post.