Re: Flexy and localization

From: Date: Mon, 08 Sep 2003 14:20:26 +0000
Subject: Re: Flexy and localization
References: 1 2 3 4  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-7642@lists.php.net to get a copy of this message
Ooh...It is clear as crystal for me... If you have a template like this: <h2>{heading:l}</h2> <table> <tr flexy:foreach="rows,row"> <td>{row[text]}</td> </tr> </table> It would create a compiled template called example.en.php like this: <h2>Title</h2> <table> <?php if(is_array($t->rows)) foreach($t->rows as $row){ ?> <tr><td><?php echo htmlspecialchars($row[text]) ?><td></tr> <?php }?> A Norwegian template would have been called example.no.php and look this: <h2>Tittel</h2> <table> <?php if(is_array($t->rows)) foreach($t->rows as $row){ ?> <tr><td><?php echo htmlspecialchars($row[text]) ?><td></tr> <?php }?> In this way a range of languages could be compiled from one template and the static text is only outputed once and that is when the template gets compiled. In my eyes this would be a easy and "cheap" way of making localization with templates. But my eyes may deceive me... -- Kjetil W. Stan Lemon wrote:
I'll be honest, I'm not sure I understand what you're saying. Can you give it another shot? - Stan Kjetil Wikestad wrote:
Your solution is feasible, but is that the most "elegant" solution? Then you have one template for each language and you need to update templates for all language each time a change is done. The solution I have been thinking of is to have one template where {variable:l} is replaced by static text in the compiled directory (Flexy already make different compiled templates for localizations). A big problem is that {variable:l} doesn't exist in Flexy templates. Another problem is that you not sure it will work as expected. How to detect when variables have changed? -- Kjetil W. Stan Lemon wrote:
Maybe I am not thinking in the right line here, but are you planning on already having the items translated? If you developed a method of detecting where they were from (maybe cookie based? Or maybe use Net_Traceroute) and then do something like this... $lang = whatever you determine; $output = new HTML_Template_Flexy(); $output->compile("./templates/mytemp." . $lang . ".tpl"); $output->outputObject($this,$this->elements); The same could work for the vars you set too, maybe parse an XML file based on the language? I'm not familiar with the package, but there is a translation package available, consider exploring that. Internationalization is documented very well by PEAR so I'm sure you'll find what you need... second thought, better hope they've got good inline docs. Maybe run PhpDocumentor first on em and see what you get. - Stan Kjetil Wikestad wrote:
I'm building a site using Flexy templates and I want to have different languages available for users. I have been thinking a lot on how to implement this and I'm still not sure of the best way of doing this. Are there anybody that have experience with Flexy and localization? How have you solved it? I have searched this newsgroup and read some posts about the gettext function, but it was to abstract for me. So....if somebody could please explaine me how gettext works in Flexy... -- Kjetil W.


« previous php.pear.general (#7642) next »