Flexy - What smarty should have been?
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
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
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
- gettext
- Translation2
- File_Gettext
- 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})
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})
Mentioned By:
google.com : php flexy (233 referals)
google.com : flexy tutorial (207 referals)
forum.mojavi.org : Mojavi Forum -> The best PHP toolkit (112 referals)
google.com : flexy php (102 referals)
google.com : april (101 referals)
google.com : flexy smarty (76 referals)
google.com : php flexy tutorial (63 referals)
google.com : flexy template tutorial (62 referals)
google.com : Smarty Flexy (55 referals)
google.com : flexy example (51 referals)
google.com : smarty ucfirst (50 referals)
google.com : flexy examples (49 referals)
google.com : 96 (39 referals)
google.com : flexy translation2 (37 referals)
google.com : flexy gettext (33 referals)
google.com : smarty alternative (33 referals)
b.hatena.ne.jp : はてなブックマーク - ジェフティマーク / Flexy (33 referals)
google.com : flexy (28 referals)
google.com : pear flexy tutorial (28 referals)
google.com : Flexy Templates (22 referals)
google.com : php flexy (233 referals)
google.com : flexy tutorial (207 referals)
forum.mojavi.org : Mojavi Forum -> The best PHP toolkit (112 referals)
google.com : flexy php (102 referals)
google.com : april (101 referals)
google.com : flexy smarty (76 referals)
google.com : php flexy tutorial (63 referals)
google.com : flexy template tutorial (62 referals)
google.com : Smarty Flexy (55 referals)
google.com : flexy example (51 referals)
google.com : smarty ucfirst (50 referals)
google.com : flexy examples (49 referals)
google.com : 96 (39 referals)
google.com : flexy translation2 (37 referals)
google.com : flexy gettext (33 referals)
google.com : smarty alternative (33 referals)
b.hatena.ne.jp : はてなブックマーク - ジェフティマーク / Flexy (33 referals)
google.com : flexy (28 referals)
google.com : pear flexy tutorial (28 referals)
google.com : Flexy Templates (22 referals)
Follow us
-
- Some thoughts on the language server and its usefulness in the roobuilder
- Roo Builder for Gtk4 moving forward
- Clustered Web Applications - Mysql and File replication
- GitLive - Branching - Merging
- PDO_DataObject Released
- PDO_DataObject is under way
- Mass email Marketing and anti-spam - some of the how-to..
- Hydra - Recruitment done right
Blog Latest
-
Twitter - @Roojs