|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
kills Smarty Elite
Joined: 28 May 2004 Posts: 493
|
Posted: Mon Jul 26, 2004 6:55 am Post subject: Built in MultiLanguage Support |
|
|
Hi all,
why dont have a multilanguage support in smarty?
for example:
first set a language dir:
[php:1:66ac953023]
/* Template Objekt initialisieren */
$oTpl = new Smarty;
$oTpl->template_dir = 'templates/';
$oTpl->compile_dir = 'templates/tpl_compiled/';
$oTpl->config_dir = 'templates/tpl_configs/';
$oTpl->cache_dir = 'templates/tpl_cached/';
$oTpl->language_dir = 'templates/tpl_lang/';
[/php:1:66ac953023]
set the default Lang:
[php:1:66ac953023]
$oTpl->setDefaultLang('de'); // Smarty default should be 'en'
[/php:1:66ac953023]
another method is needed for switching between the languages:
[php:1:66ac953023]
$oTpl->setLang('fr');
[/php:1:66ac953023]
some lang files in the lang dir with a meaningful structure or like the config files structure:
(The Filenames should be represented by the country-token)
a english language file:
Filename example: "en.lang"
Code: |
save = "save"
abort = "abort"
male_title = "Mr"
female_title = "Mrs"
.
.
|
a german language file:
Filename example: "de.lang"
Code: |
save = "Speichern"
abort = "Abbrechen"
male_title = "Herr"
female_title = "Frau"
.
.
|
and in the templates:
Code: |
<div>
{lang name="save" }
</div>
|
|
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Mon Jul 26, 2004 3:21 pm Post subject: |
|
|
It looks like your templates will be the same for all languages, so why make separate template directories for them? As for using config files, you can accomplish the same thing with Smarty as it stands:
en.conf
Code: | lang_save = "save"
... |
de.conf
Code: | lang_save = "Speichern"
... |
index.php
Code: | $lang = 'en';
$smarty->load_config("$lang.conf");
$smarty->display('index.tpl'); |
index.tpl
Code: | <div>
{#lang_save#}
</div> |
(I put the lang_ prefix on the config file names to prevent collision with other config file vars)
There are lots of other i18n ideas in this forum as well, such as using gettext() block functions. |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|