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 ... 7, 8, 9 ... 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
Serzhik
Smarty Rookie


Joined: 12 Mar 2004
Posts: 18
Location: Kyiv, Ukraine

PostPosted: Fri Mar 12, 2004 1:10 pm    Post subject: Reply with quote

AZTEK, I found you method better then others! Respect! And thanx for it! Wink
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
AZTEK
Smarty Pro


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

PostPosted: Fri Mar 12, 2004 1:48 pm    Post subject: Reply with quote

Serzhik wrote:
AZTEK, I found you method better then others! Respect! And thanx for it! Wink

I am glad some people find it usefull.
_________________
"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
shaka
Smarty n00b


Joined: 16 Mar 2004
Posts: 1

PostPosted: Tue Mar 16, 2004 1:18 pm    Post subject: Translate-block doesn't work for all strings Reply with quote

I think this problem applies for most Smarty i18n techniques. Using {t}Translatable string{/t} works fine, but who said all text can be surrounded by tags? What about attribute values?

I just started using the gettext method myself and ran into problems when using the default-modifier. I want to do: {$variable|default:"{t}Translatable string{/t}"}. Is there some smart(y) way to do this? Of course I can put the value in a variable in php or something, but then the whole point of the modifier is gone.
Back to top
View user's profile Send private message
sagi
Smarty Regular


Joined: 30 Jul 2003
Posts: 43

PostPosted: Tue Mar 16, 2004 1:51 pm    Post subject: Reply with quote

Personally I feel all variables should be translated in the PHP level.

The only other exception is |default like you say. Perhaps you could just use a regular {if}. It is also possible to add "assign" option for the block function.

Sagi
Back to top
View user's profile Send private message
boots
Administrator


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

PostPosted: Tue Mar 16, 2004 3:30 pm    Post subject: Reply with quote

@shaka: perhaps override the provided default modifier with your own that can handle translations?
Back to top
View user's profile Send private message
Justin
Smarty Regular


Joined: 07 May 2003
Posts: 38
Location: Vilnius, Lithuania

PostPosted: Tue Mar 16, 2004 6:42 pm    Post subject: Reply with quote

or perhaps you could use smarty prefilters. there are some examples about such solution in this theme and in http://smarty.incutio.com/?page=SmartyMultilanguageSupport
_________________
http://www.baubas.net
Back to top
View user's profile Send private message Visit poster's website
DinoM
Smarty n00b


Joined: 17 Mar 2004
Posts: 4

PostPosted: Wed Mar 17, 2004 8:08 am    Post subject: Reply with quote

AZTEK wrote:
Serzhik wrote:
AZTEK, I found you method better then others! Respect! And thanx for it! Wink

I am glad some people find it usefull.


AZTEK, I would like to use your method too Very Happy . But have some question regarding the cache.

If I turn the cache on, the page cannot displayed correctly. Look like it is still displaying the cached version. Is there a anyway to get around this ?

Regards
Dino
Back to top
View user's profile Send private message
AZTEK
Smarty Pro


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

PostPosted: Wed Mar 17, 2004 11:06 am    Post subject: Reply with quote

You will need to change your call to $smarty->register_block so that the third parameter is false meaning the output of the block is not cacheable. I just added that to my original post.
_________________
"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
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Wed Mar 17, 2004 11:27 am    Post subject: Reply with quote

sorry, why would you turn on caching and then don't cache the translated texts?
Back to top
View user's profile Send private message Send e-mail Visit poster's website
AZTEK
Smarty Pro


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

PostPosted: Wed Mar 17, 2004 11:37 am    Post subject: Reply with quote

messju wrote:
sorry, why would you turn on caching and then don't cache the translated texts?

Your right a much better way would be to use the locale string as part of a cache id.
_________________
"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
DinoM
Smarty n00b


Joined: 17 Mar 2004
Posts: 4

PostPosted: Wed Mar 17, 2004 11:47 am    Post subject: Reply with quote

AZTEK wrote:
You will need to change your call to $smarty->register_block so that the third parameter is false meaning the output of the block is not cacheable. I just added that to my original post.


AZTEK, Thanks for your input.

Okay, words between {trans}{/trans} will be skipped on the cache. But what are the advantage of my site being cached or not to be cached ?

I know it gave us better performance on the reponse time and the time on loading page being faster which was cached already.

But if I turn the third flag to "false", then all the content will be skipped for caching. And will this make the $smarty->cache=true become useless. Since most of the contents has been skipped.

Now, if I use "$smarty->display('index.tpl',$_GET['lang']);" then page will be fully cached and generated different id by the $lang. Would this approach better than skip caching translated wording ? Rolling Eyes

Thanks,
Dino
Back to top
View user's profile Send private message
AZTEK
Smarty Pro


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

PostPosted: Wed Mar 17, 2004 2:23 pm    Post subject: Reply with quote

Yea the approch by which you use the locale string as a cache id is much more useful then to just skip caching translated words entirely. Its what I would do.
_________________
"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
xces
Smarty Regular


Joined: 09 Apr 2004
Posts: 77

PostPosted: Wed Apr 28, 2004 7:41 am    Post subject: Reply with quote

I ain't sure it has allready been posted here, but i am building a CMS using smarty. Because i am still building this and i am adding a lot of translations i have thought of your implementation aztek but i decided to make my own.

Basicly what i have done is this; I made 3 tables in the database they are build up like this:
Code:

CREATE TABLE `cms_language` (
  `languageid` bigint(20) NOT NULL auto_increment,
  `language` varchar(20) NOT NULL default '',
  `mnemonic` char(3) NOT NULL default '',
  `countrycode` varchar(5) NOT NULL default '',
  PRIMARY KEY  (`languageid`)
) TYPE=MyISAM;

CREATE TABLE `cms_text` (
  `textid` bigint(20) NOT NULL auto_increment,
  `moduleid` bigint(20) NOT NULL default '0',
  `variable` tinytext NOT NULL,
  PRIMARY KEY  (`textid`)
) TYPE=MyISAM;

CREATE TABLE `cms_text_trans` (
  `textid` bigint(20) NOT NULL default '0',
  `languageid` bigint(20) NOT NULL default '0',
  `translation` text NOT NULL
) TYPE=MyISAM;


For example; i have this text in my template:
[html_tl mod.photos.category.index.txtWelcome]

The output filter looks at this and finds (i am using regexp for this) that it has to search for the variable category.index.txtWelcome of the module mod.photos. Then the module id is searched up and it creates an sql statement which fetches the translation out of cms_text_trans for the current langauge and module and variable.

If the translation is not found in the current language then languageid "1" is used (e.g. 1 is my own native language, dutch). This means there is always some text.

I made a smarty_get_prefetched function which i call from my source, and an output filter which translates [html_tl mod.photos.category.index.txtWelcome] to the welcome text of my choice, and [java_tl mod.photos.category.index.txtWelcome] to thesame text but then addslashed() so i can use this in the javascript messages.

A lot of querys...
Because each time a page is loaded the entire set of strings is loaded for that specific module i am thinking of caching (e.g. compiling) them. I want to accheive this using the "SHOW TABLE STATUS " command. If this is other then the compiled string array i rebuild the array and overwrite the previous one in the database/session. This way, i only have to fetch the strings when they change.

Love to hear your thoughts about this...
Back to top
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Wed Apr 28, 2004 8:08 am    Post subject: Reply with quote

@xces:

if your "[here.the.variable.tag]" are just in the template, you can translate your templates at compiletime:
- use the selected language as compile_id
- transform your tags to the translated text in a pre-filter
done

if you also have these tags in the php, things get a little more complicated.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
xces
Smarty Regular


Joined: 09 Apr 2004
Posts: 77

PostPosted: Thu Apr 29, 2004 6:56 am    Post subject: Reply with quote

Hmz, so you are saying that it is possible to create compiled templates for each language. That is interesting I did not know that. That means i don't have to do the caching of mysql.

Secondly, i am using this from within my PHP tags, but that is very rarely. I could think of a way to skip that and just use the templates for the variables.

edit:
Actually, looking at prefilters right now, i did it all wrong :0 The way it works right now is ok, but not perfect;
Because right now i have:
- Run PHP code and assign translated text to smarty
- Run a postfilter to replace all remaining translations

This all could be done like this:
- Run PHP code and assign translated text to smarty
- Run a prefilter to replace all remaining translations, because postfilter is kinda obsolete here.

Right?

(but)

Why i assign the translated text from within PHP:
For example, i have this string in the database:
"This album was last edited by %s on %s at %s."

Eventually, this will be replaced by this:
"This album was last edited by me on 28-04-2004 at 18:24"

Is there a way to change this so my templates will hold all the translation strings? I could try to use a

Some remaining questions:
- Right now i have force_compile to true, because i am developing, but is this really needed? When i change a translation of a variable and i don't have force_compile on but do have compile_check on, does smarty recognize the changes?
- Can you explain some more on the compile_id, this is kinda "not yet" documented enough for me to understand it correctly.
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 ... 7, 8, 9 ... 13, 14, 15  Next
Page 8 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