RE: Translation - fast and dynamic plugin function and modifier
| From: | MPN | Date: | Mon, 25 Mar 2002 15:11:23 +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-3329@lists.php.net to get a copy of this message | ||
Great, thanks for the examples. Anyone done a mixture of the two
approaches? File based for static translation, and DB for dynamic?
-----Original Message-----
From: Jarosław Zabiełło [mailto:webmaster@apologetyka.com]
Sent: Saturday, March 23, 2002 11:06 AM
To: smarty@lists.ispi.net
Cc: smarty@lists.ispi.net
Subject: [smarty] RE: Translation - fast and dynamic plugin function and
modifier
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)
---
You are currently subscribed to smarty as: mpn@3dgamelink.com
To unsubscribe send a blank email to $subst('Email.Unsub')
Visit Smarty's homepage at http://www.phpinsider.com/php/code/Smarty/