Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

best way to build a multi-language site with smarty
Goto page Previous  1, 2, 3 ... 9, 10, 11 ... 13, 14, 15  Next
 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Tips and Tricks
View previous topic :: View next topic  
Author Message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Wed Jul 21, 2004 4:05 pm    Post subject: Reply with quote

@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
View user's profile Send private message
AZTEK
Smarty Pro


Joined: 16 Apr 2003
Posts: 235
Location: Purdue University

PostPosted: Wed Jul 21, 2004 4:29 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
cod3x
Smarty n00b


Joined: 03 Nov 2003
Posts: 3

PostPosted: Wed Jul 21, 2004 6:24 pm    Post subject: Reply with quote

@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. Smile
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Wed Jul 21, 2004 6:34 pm    Post subject: Reply with quote

@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
View user's profile Send private message
cod3x
Smarty n00b


Joined: 03 Nov 2003
Posts: 3

PostPosted: Wed Jul 21, 2004 8:14 pm    Post subject: Reply with quote

@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
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Wed Jul 21, 2004 8:20 pm    Post subject: Reply with quote

@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 Smile
Back to top
View user's profile Send private message
szen
Smarty Rookie


Joined: 23 Dec 2003
Posts: 17

PostPosted: Sun Sep 05, 2004 5:01 am    Post subject: Reply with quote

I use this:
http://smarty.incutio.com/?page=SmartyMultilanguageSupport
But i want to use ##L_EXAMPLE## in template and directly in PHP is ther any way to do this?
Back to top
View user's profile Send private message
kills
Smarty Elite


Joined: 28 May 2004
Posts: 493

PostPosted: Mon Sep 06, 2004 6:39 am    Post subject: Reply with quote

have a try:

$smarty->config->YourConfWar
http://smarty.php.net/manual/en/language.config.variables.php

not tested yet
Back to top
View user's profile Send private message
timurv
Smarty Rookie


Joined: 07 Sep 2004
Posts: 8
Location: Russia, Kazan

PostPosted: Fri Sep 17, 2004 11:35 am    Post subject: 2AZTEK Reply with quote

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
View user's profile Send private message
kills
Smarty Elite


Joined: 28 May 2004
Posts: 493

PostPosted: Fri Sep 17, 2004 11:41 am    Post subject: Re: 2AZTEK Reply with quote

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
View user's profile Send private message
AZTEK
Smarty Pro


Joined: 16 Apr 2003
Posts: 235
Location: Purdue University

PostPosted: Sat Sep 18, 2004 2:05 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
kaiska
Smarty n00b


Joined: 20 Sep 2004
Posts: 3
Location: France, Paris

PostPosted: Mon Sep 20, 2004 9:22 am    Post subject: Reply with quote

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 Smile
Thanx in advance !
Back to top
View user's profile Send private message Visit poster's website
AZTEK
Smarty Pro


Joined: 16 Apr 2003
Posts: 235
Location: Purdue University

PostPosted: Mon Sep 20, 2004 11:05 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Dr DLP
Smarty Rookie


Joined: 03 Oct 2004
Posts: 5
Location: France

PostPosted: Sun Oct 03, 2004 3:32 pm    Post subject: Reply with quote

Hi Smile

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 Smile
Back to top
View user's profile Send private message Visit poster's website
s0undt3ch
Smarty Rookie


Joined: 11 Nov 2004
Posts: 5

PostPosted: Thu Nov 11, 2004 10:56 am    Post subject: Reply with quote

andre wrote:
So I am using http://smarty.incutio.com/?page=SmartyMultilanguageSupport as meantioned above. Ehh... I'm using it because I wrote the script Wink

It works quite well for me and it's fast. If somebody needs some help just post your questions in the forum.

bye,
Andre


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
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Tips and Tricks All times are GMT
Goto page Previous  1, 2, 3 ... 9, 10, 11 ... 13, 14, 15  Next
Page 10 of 15

 
Jump to:  
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
Protected by Anti-Spam ACP