View previous topic :: View next topic |
Author |
Message |
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Wed Jul 21, 2004 4:05 pm Post subject: |
|
|
@cod3x: nice, but constants are a little bit expensive. For my limited needs, config files do the trick and work very similiarly. Also, AFAIK, the ## syntax resolves to fewer method calls than a plugin function. |
|
Back to top |
|
AZTEK Smarty Pro
Joined: 16 Apr 2003 Posts: 235 Location: Purdue University
|
Posted: Wed Jul 21, 2004 4:29 pm Post subject: |
|
|
This all just goes to show that much like anything else in programming it can be done multiple ways. Each with its own strengths and none better then another. _________________ "Imagine a school with children that can read and write, but with teachers who cannot, and you have a metaphor of the Information Age in which we live." -Peter Cochrane |
|
Back to top |
|
cod3x Smarty n00b
Joined: 03 Nov 2003 Posts: 3
|
Posted: Wed Jul 21, 2004 6:24 pm Post subject: |
|
|
@boots: from what I understand in php versions later than 4.3.3 the performance impact of constant usage is much less than it use to be. Here's a bench test done over at phpmag: http://www.phpmag.net/itr/online_artikel/psecom,id,546,nodeid,114.html
The cost of constants is something worth checking into though, I'll see if I can set up some benchmarks for the different approaches. I'm not sure what you meant by '## syntax' though, can you explain that one for me?
@AZTEK: Indeed, and the more ideas that people bring forth gives more tools for people to select the best one for a particular job. Mine filled a need as I was working with a system that had already established a multi-lingual system built on constants.
Just a side note, you live right down the road from me AZTECH lol, I live in humble Crawfordsville, IN. |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Wed Jul 21, 2004 6:34 pm Post subject: |
|
|
@cod3x: when loading (static) data from config files, you access vars (or labels, if you prefer) using the {#var#} syntax. This gets replaced in the compiled template as a direct lookup into the array structure loaded by {config_load}. On the other hand, using a plugin results in at least one function call (and I think, perhaps a method call) per substitution.
http://smarty.php.net/manual/en/language.config.variables.php
Thanks for the link, btw, I'll give it a look.
@aztek: you hit the nail on the head. It is a good thing to have many different solutions since each has different strengths and weaknesses. |
|
Back to top |
|
cod3x Smarty n00b
Joined: 03 Nov 2003 Posts: 3
|
Posted: Wed Jul 21, 2004 8:14 pm Post subject: |
|
|
@boots: thanks for that. after looking over that, I have to agree with you that that method would be significantly faster than the constant alternative. I have another project that I'm working on that this would work great with. Thanks again! |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Wed Jul 21, 2004 8:20 pm Post subject: |
|
|
@cod3x: of course, profiling and benchmarking is the only way to measure which method is truly faster in your usage pattern. My instinct is that the config files will perform better, but that doesn't make it necessarily so |
|
Back to top |
|
szen Smarty Rookie
Joined: 23 Dec 2003 Posts: 17
|
|
Back to top |
|
kills Smarty Elite
Joined: 28 May 2004 Posts: 493
|
|
Back to top |
|
timurv Smarty Rookie
Joined: 07 Sep 2004 Posts: 8 Location: Russia, Kazan
|
Posted: Fri Sep 17, 2004 11:35 am Post subject: 2AZTEK |
|
|
I use xml method for translation storage.
And use simple smarty block function like {t}{/t}
May be it's offtop, but:
Code: | {$smarty.request.error|default:"Default error string"} |
and how to translate "Default error string" string? |
|
Back to top |
|
kills Smarty Elite
Joined: 28 May 2004 Posts: 493
|
Posted: Fri Sep 17, 2004 11:41 am Post subject: Re: 2AZTEK |
|
|
timurv wrote: | I use xml method for translation storage.
And use simple smarty block function like {t}{/t}
May be it's offtop, but:
Code: | {$smarty.request.error|default:"Default error string"} |
and how to translate "Default error string" string? |
you can do something like this:
EN-CONF:
Code: |
DefaultErrorMsg = "Default error string"
|
DE-CONF:
Code: |
DefaultErrorMsg = "Standard error"
|
.
.
.
TPL:
Code: | {$smarty.request.error|default:#DefaultErrorMsg#} |
only include the right config on the head of your phpscript:
[php:1:d720d2858a]
$smarty->config_load('DE-CONF');
[/php:1:d720d2858a]
@see: http://smarty.php.net/manual/en/api.config.load.php |
|
Back to top |
|
AZTEK Smarty Pro
Joined: 16 Apr 2003 Posts: 235 Location: Purdue University
|
Posted: Sat Sep 18, 2004 2:05 pm Post subject: |
|
|
You could probably do something like Code: | {capture assign=string}{t}Default error string{/t}{/capture}
{$smarty.request.error|default:$string} |
_________________ "Imagine a school with children that can read and write, but with teachers who cannot, and you have a metaphor of the Information Age in which we live." -Peter Cochrane |
|
Back to top |
|
kaiska Smarty n00b
Joined: 20 Sep 2004 Posts: 3 Location: France, Paris
|
Posted: Mon Sep 20, 2004 9:22 am Post subject: |
|
|
Hi,
I use this multilingual template solution ({t}{/t}) but I don't understand how to make cache work with it. If I cache the french page, the I switch to italian, the page shown is ever in french. I would really apreciate any help
Thanx in advance ! |
|
Back to top |
|
AZTEK Smarty Pro
Joined: 16 Apr 2003 Posts: 235 Location: Purdue University
|
Posted: Mon Sep 20, 2004 11:05 am Post subject: |
|
|
You need to use the current language in the cacheid. So [php:1:54254210d4]$smarty->display('blah.tpl')[/php:1:54254210d4] would become [php:1:54254210d4]$smarty->display('blah.tpl', $lang)[/php:1:54254210d4] _________________ "Imagine a school with children that can read and write, but with teachers who cannot, and you have a metaphor of the Information Age in which we live." -Peter Cochrane |
|
Back to top |
|
Dr DLP Smarty Rookie
Joined: 03 Oct 2004 Posts: 5 Location: France
|
Posted: Sun Oct 03, 2004 3:32 pm Post subject: |
|
|
Hi
This seems very complicated!
I really prefer using lang_keys :
Code: | $lang = array();
include("languages/lang_".$base_language.".php");
$smarty->assign('lang_key',$lang); |
and for instance, in languages/lang_french.php :
Code: | $lang[0] = 'titre';
$lang[1] = 'Bonjour'; |
and in languages/lang_english.php :
Code: | $lang[1] = 'title';
$lang[0] = 'Hello'; |
So I don't have to care anymore of the user language, I just use $lang[] in the templates file |
|
Back to top |
|
s0undt3ch Smarty Rookie
Joined: 11 Nov 2004 Posts: 5
|
Posted: Thu Nov 11, 2004 10:56 am Post subject: |
|
|
I'm using your scrip Andre, Thanks for the help!!!!
For now I've just changed ## for ___, so it becomes more readable.
Once again Thanks!,
Pedro. |
|
Back to top |
|
|