[prev in list] [next in list] [prev in thread] [next in thread] 

List:       smarty-dev
Subject:    [SMARTY-DEV] Translations... where's the problem? ;-)
From:       80.141.80.107
Date:       2002-04-14 1:53:22
[Download RAW message or body]

"Andreas Kossmeier" <andreas.kossmeier@bergfex.at> schrieb im
Newsbeitrag news:3CACB389.6060009@bergfex.at...
> Monte Ohrt wrote:
> > Try out the block functionality in the cvs version of Smarty. You
can do
> > this with a custom block function:
> >
> > {translate lang="en"}
> >    blah blah blah
> > {/translate}
>
> i don't think that this is solving his problem ;)
>
> but it's not a matter of the template engine. what about using a
caching
> layer for the database calls in your custom function? should decrease
> your db calls to a minimum.
>
> BTW: using a block function like shown above is IMO the cleaner
solution
> for translating tag :)

Why the heck does none never not use a modifier not to translate? (Wow,
this sound negative)

I love smarty's modifiers... :-))

file "lang.de.php":
<?PHP
global $translation;
$translation = array ('yes' => 'ja',
                                   'no' => 'nein',
                                   'submit' => 'senden',
...and so on....
?>

In your php-app:
<?PHP
include ("lang.de.php");
global $translation
$smarty -> assign ('dummy' , ''); //YES, IMPORTANT!
...
?>

In your template:
Translate static strings:
{$dummy|default:"yes"|translate}

Translate dynamic strings:
{$yourWord|default:"empty or what ever"|translate}


The plugin:
function smarty_modifier_translate ($string){
 global $trans;
 if isset ($trans[$string]){
  return $trans[$string];
 } else {
  return $string;
 }
}

That's it... ready to translate static and dynamic content. Use and add
as much languages as you want without a single change to one of your
templates. Add and change global translation without need to change any
template for a correction of your translations and keep the translation
for all templates synchronized. Because of including a separate file
for each language you could also assign language dependent data like
date-/timeformats, charsets and all that crap from within the included
file to your templates. And at least you can combine your translations
with other modifiers.

Life can be so nice and easy... ;-)

Regards,
Norbert


-- 
Smarty Development Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic