Code

Smarty gettext with domain support (block t plugin) [depreciated]

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:

Published by

Konrad Fedorczyk

I'm interested in programming and gamedev. I especially luv HTML5 and everything connected to web technologies.

2 thoughts on “Smarty gettext with domain support (block t plugin) [depreciated]”

Leave a Reply

Your email address will not be published.