RE: Translation - fast and dynamic plugin function and modifier

From: Date: Sat, 23 Mar 2002 19:06:19 +0000
Subject: RE: Translation - fast and dynamic plugin function and modifier
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-3326@lists.php.net to get a copy of this message
On suterday 2002-03-23 at 05:18:26 MPN <mpn@3dgamelink.com> wrote: > Do you have some script examples and/or more documentation to go > along with this? I'm fairly new to the Smarty and the whole template > scene so a few usage examples, short database dump, would help alot > in term of understanding how it all works. OK. Look at the following example. OLD, STANDARD FILE BASED CONF: ============================ lang_en.conf: ----------- [section1] var1="expression one" var2="expression two" [section2] var1="sentence one" var2="sentence two" lang_pl.conf: ----------- [section1] var1="wyrazenie pierwsze" var2="wyrazenie drugie" [section2] var1="zdanie pierwsze" var2="zdanie drugie" mytemplate.php: ------------- global $HTTP_GET_VARS; $language = $HTTP_GET_VARS{'language'}; $this->assign( "language", !empty($language) ? $language : "en" ); mytemplate.tpl: -------------- {include_php file="mytemplate.php"} {config_load file="lang_$language.conf" section="section1"} Var1 is {#var1#}, Var2 is {#var2#} DB BASED CONF: ============= # First, create table structure for table 'transl': CREATE TABLE transl ( section varchar(31) default NULL, name varchar(31) NOT NULL default '', expr blob NOT NULL, lang char(2) NOT NULL default '', KEY idx (name,section,lang) ); # Next, load into database the equivalent of lang_en.conf: INSERT INTO transl (section, name, expr, lang) VALUES ("section1", "var1", "expression one", "en"); INSERT INTO transl (section, name, expr, lang) VALUES ("section1", "var2", "expression two", "en"); INSERT INTO transl (section, name, expr, lang) VALUES ("section2", "var1", "sentence one", "en"); INSERT INTO transl (section, name, expr, lang) VALUES ("section2", "var2", "sentence two", "en"); # and load the equivalent of lang_pl.conf: INSERT INTO transl (section, name, expr, lang) VALUES ("section1", "var1", "wyrazenie pierwsze", "pl"); INSERT INTO transl (section, name, expr, lang) VALUES ("section1", "var2", "wyrazenie drugie", "pl"); INSERT INTO transl (section, name, expr, lang) VALUES ("section2", "var1", "zdanie pierwsze", "pl"); INSERT INTO transl (section, name, expr, lang) VALUES ("section2", "var2", "zdanie drugie", "pl"); If section field is null it is for global names like global1 = "global1 expr" global2 = "global2 expr" [section1] ... etc. my_db_based_template.tpl: ------------------------ {include_php file="mytemplate.php"} Var1 is {transl section="section1" name="var1" lang=$language}, Var1 is {transl section="section1" name="var2" lang=$language}, This is {$tmp|default|transl:en|var2:section2} {* if $tmp is null, the output is: 'sentence two' *} It is much faster and more dynamic aproach. -- Jarosław Zabiełło (UIN: 6712522)

« previous php.smarty.general (#3326) next »