Re: Re: [SMARTY] using different languages in my Templates
| From: | Rasmus Schultz | Date: | Fri, 20 Dec 2002 18:04:22 +0000 |
| Subject: | Re: Re: [SMARTY] using different languages in my Templates | ||
| Groups: | php.smarty.general | ||
| Request: | Send a blank email to php-smarty-general+get-6920@lists.php.net to get a copy of this message | ||
well, the language setting has to come from PHP of course, it
could be something like a two-letter countrycode or whatever,
which you store in a cookie on the client, or as a session-
variable (probably both) ... you pass the countrycode to the
template, and it then loads the appropriate config file for
that language, i.e. in your PHP:
// set $cc = current country code, and then:
$smarty->assign("cc",$cc)
and in your template, something like:
{config_load file="lng_mypage_$cc.cfg"}
and then make yourself a set of config files named
"lng_mypage_uk.cfg", "lng_mypage_de.cfg" etc. - use a filename
prefix for language, i.e. "lng_" to avoid confusion with other
config file, and a prefix for the page that requires this
language file, i.e. "mypage_" ... you probably have language
files you want to share between several templates as well, so
consider filenaming carefully :)
if you don't like the high number of config files required for
this, you can of course also put several languages in a single
config file instead - just put each list of language constants
in a separate section in your config file, and load the right
section, like for example:
{config_load file="lng_mypage.cfg" section=$cc}
this will probably mean slightly more overhead from loading
the config files, but probably not much - config file loading
is pretty fast as it is, so it's probably not worth the worry.
if you need high performance, use caching, and include your
language-code in the cache_id you provide to display(), so
that your pages are cached per language.
I hope that's useful? :)
--- At 2002-12-20, 18:32:00, akorthaus <akorthaus@web.de> wrote:
>Hi!
>
>>I think the common routine is to simply have a config file for
>>each language?
>>
>How should this work? Or do you think of one translation-table per
>language? The problem is to include the correct language in my
>templates. Or what would be in your config-file?
>The best way is this one I think:
>http://smarty.incutio.com/?page=SmartyMultilanguageSupport
>
>regards
>Andreas