string(19) "ViewArticleOrg.html" Flexy - What smarty should have been? : roojs.org - open source

Published 2004-04-17 00:00:00

Interesting to John's blog mention smarty and his trials and tribulations trying to implent transparent mulitlingual web sites.

It was always part of Flexy's goal to solve the Mulitlingual problem, It already had the ability
  • to parse the sentences (blocks of words) out of a template, and serialize it to a file - and when building the 'PHP' version of the template it would do one for each language - passing each of those through gettext.
  • to pick a source template based on the locale setting (eg. - you specify welcome.html - with locale=fr, you end up with welcome.fr.html compiled into php.

Well that was all 'theoretically' very good, but I'd never had chance to put it into a live site.. That changed this week (and so did alot of the code in CVS!)

Other than the basic ability to support parsing the words out of the template, (properly as Flexy is a full HTML parser). I added
  • Backend support for
  • User defined translation blocks (UDTB)
    • For blocks that include HTML and flexytags - that the autoparser cant pick up, or you want to use 'placeholders' that are a bit more verbose.
    • These blocks are translated/replaced, prior to Tag tokenizing (so the translation can include tags - variable markers or HTML)
The classic example fo UDTB's is something that works well in english, but fails badly in another language:
eg.
there was <B>{number}</B> signups in {country}

In english, this sentence makes perfect sense, however when translated to french, you end up having to deal with the fact that country has gender. The easiest work around for this is usually to rephrase the sentence.
{country} : there was <B>{number}</B> signups.

While not perfect in english, its at least works in another language.. What UDTB's allow you to do is use the best solution for each language.

By wrapping the text in the UDTB wrappers, it is flagged to be translated: eg.
{_(there was <B>{number}</B> signups in {country})_}

You get the list of sentences that need translating by
$array = unserialize(file_get_contents(
$flexy->gettextStringsFile));


Then use this information to make an interface to edit the translations, and store in gettext or another Translate2 backend.

Once done, you set up the config vars for flexy, to tell it about how you want it to translate:

$flexy = new HTML_Template_Flexy(array(
'locale' => 'fr',
'Translation2' => array(
'driver' => 'dataobjectsimple',
'options' => array()
));

$flexy->compile('mytemplate.html');
$demo = new StdClass;
$demo->number = 12;
$demo->country = 'Germany';
$flexy->outputObject($demo);

The only major task left is to improve the modifiers support, I'm vering towards
{variable:date_format(#%d/%m/%Y#)}
{variable:strtolower:ucfirst}

as presently it only have:
{variable} = htmlspecialchar'ed
{variable:u} = urlencoded'ed
{variable:h} = raw (eg.html)
{variable:r} = print_r($variable)
{variable:n} = number_format($variable, {options settings})

Follow us on