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})
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)

Comments

Hey Alan!

Notice: The Smarty link is broken!
#0 - Christian Machmeier ( Link) on 2004-04-18 16:46:27 Delete Comment
If you have some code where you use DataObject together with Flexy, I'd be happy to see it. I tried flexy in the last days and it was the greatest thing I've ever seen for filling in form values but not for creating lists of records. What I couldn't do is to pass a DataObject and while ($do->fetch()) print $do member variables (fields). I guess you have some cool solution for that.

Thanks.
Norbert
#1 - Norbert Mocsnik ( Link) on 2004-07-16 02:53:59 Delete Comment
I forgot to mention that my main problem with that was that I couldn't refer to object member variables in the templates nor was I able to use associative arrays so that I could have passed $do->toArray() stuff.

Anyways, parsing HTML tags and filling in form elements + using flexy properties in HTML tags is a very great idea. I must admit I almost always like what you do.
#2 - Norbert Mocsnik ( Link) on 2004-07-16 02:57:29 Delete Comment
Translation2 + Flexy, examples?
I see the translation property in Flexy, but there is no mention of it in the docs and I'm not sure how to specify the container translation2 should use with flexy... I'm really lost here. Even figuring out just DB_DataObject and Translation2 seems undocumented.

Any tips here? Am I missing a big piece of documentation somewhere?

thanks
Jacob
#3 - Jacob Singh ( Link) on 2004-12-02 16:07:12 Delete Comment
Okay, I think I get it
Okay, it's making some sence now.
WARNING! This page is outdated. You have to instantiate Translation2 via a factory method, so the example code doesn't work

#4 - Jacob Singh ( Link) on 2004-12-02 17:17:56 Delete Comment

Add Your Comment

Follow us on