Errors in my php example / code:
invoke:
xlate("Search found {count} pages for {keywords}", $count, $query);
in xlate():
$xlated = preg_replace("/{([^\}]+)}/e", "\$replace_map[$1]" , $xlated);
Sorry :-)
Hans
On Wed, 2002-07-24 at 10:57, Hans Lellelid wrote:
> For translating text that might have dynamic values, I build a wrapper
> function for gettext() -- note that if you do this you'll probably need
> to use a shell/perl script to replace the wrapper function name with
> gettext() or _() before feeding it into thee xgettext tool.
>
> So my wrapper function is invoked like this:
>
> xlate("Search found {count} pages for {keywords}", $count, $query$);
>
> It doesn't matter how you label your {tags}, but make sure you use
> the same label in all translations.
>
> ** This way you can re-order the tags in the translated text & PHP will
> still insert the correct values.**
>
> In the [bad French] POT file:
>
> msgid "Search found {count} pages for {keywords}"
> msgstr "En cherchant le database pour {keywords}, on a trouve {count}
> results."
>
> Notice that the the order changes for dynamic elements.
>
>
> Here's the actual wrapper function I use:
>
> function xlate($text)
> {
>
> // 1) get array of {tags} in text
> // these will be replaced with passed params
>
> preg_match_all("/{([^}]+)}/", $text, $var_matches);
>
> $replace_tags = $var_matches[1];
>
> // $replace_tags is an array of all tags we need to replace
> // in original order.
>
> $num_args = func_num_args();
> $num_replace_tags = sizeof($replace_tags);
>
> if( ($num_args - 1) < $num_replace_tags) {
> trigger_error("More replace tags than arguments", E_USER_WARNING);
> }
>
> $replace_map = array();
>
> // build a hash of tags & values to replace them with.
>
> for($c = 0; $c < $num_replace_tags; $c++) {
> $replace_map[ $replace_tags[$c] ] = func_get_arg($c+1);
> }
>
>
> // 2) translate the text
>
> $xlated = gettext($text);
>
> // 3) re-insert the values from the hash
>
> $xlated = preg_replace("/{([^\}]+)}/e", "\$replace_map[$1]" ,
> $text);]
>
>
> return $xlated;
>
> }
>
>
> Cheers,
> Hans
>
> On Wed, 2002-07-24 at 10:11, Anatole Varin wrote:
> > Good question. I'll tell you my hack, however I'd be really curious to hear
> > other people's opinions as well.
> >
> > For text without links I do something similar to the phpMyAdmin way, however
> > I put my language into an array, just so that if I use language inside of
> > functions I don't have to declare each variable as a global, just the one
> > array. For example (using romanji for the Japanese for non-Japanese enabled
> > mail clients on this list):
> >
> > $lang = array(
> > "verify" => "kakunin",
> > "name" => "namae",
> > "no" => iie",
> > "delete" => "sakujo,
> > "close_window" => "tojiru"
> > );
> >
> > Then, when I want to use it in a function I just use "global $lang" and I
> > can use the bits that I want (i.e. <?php print($lang[name]); ?>
> >
> > For pieces that are a bit more complex, such as phrases that contain links
> > or bolding or other attributes that might not line up because of the
> > differences in expressing English and Japanese, I use functions:
> >
> > function lang_show_result($start,$finish) {
> > $txt = "Showing results $start-$finish.";
> > return($txt);
> > }
> >
> >
> > > It's very nice to see some activity on here from this end of the mailing
> > > list as well. I am on the verge of putting together a php/mysql
> > > multilingual website from scratch and it's good to know that some people
> > > are reading up on the list. I was wondering what people's opinion on
> > > the overall structure of a multi language php application is. There are
> > > a number of ways to implement the frontend.
> > >
> > > 1. Do something similar to the way phpMyAdmin works and have different
> > > files layed out with the different encoding types and variables listed
> > > for each message displayed to the users.
> > >
> > > 2. Use gettext or some other widely used standard.
> > >
> > > ..... Etc..
> > >
> > > Of course even these 2 solutions have their good and bad points. The
> > > first is quick but harder to maintain. The second of course is easier
> > > to maintain but more difficult to setup from the beginning. What do
> > > others think or what are they using at this time?
> > >
> > > Thanks,
> > > -jeff
> >
> > - AV
> >
> >
> > --
> > PHP Internationalization Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
>
>
>
>
> --
> PHP Internationalization Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
PHP Internationalization Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php