View previous topic :: View next topic |
Author |
Message |
Serzhik Smarty Rookie
Joined: 12 Mar 2004 Posts: 18 Location: Kyiv, Ukraine
|
Posted: Fri Mar 12, 2004 1:10 pm Post subject: |
|
|
AZTEK, I found you method better then others! Respect! And thanx for it! |
|
Back to top |
|
AZTEK Smarty Pro
Joined: 16 Apr 2003 Posts: 235 Location: Purdue University
|
Posted: Fri Mar 12, 2004 1:48 pm Post subject: |
|
|
Serzhik wrote: | AZTEK, I found you method better then others! Respect! And thanx for it! |
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 |
|
shaka Smarty n00b
Joined: 16 Mar 2004 Posts: 1
|
Posted: Tue Mar 16, 2004 1:18 pm Post subject: Translate-block doesn't work for all strings |
|
|
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 |
|
sagi Smarty Regular
Joined: 30 Jul 2003 Posts: 43
|
Posted: Tue Mar 16, 2004 1:51 pm Post subject: |
|
|
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 |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Tue Mar 16, 2004 3:30 pm Post subject: |
|
|
@shaka: perhaps override the provided default modifier with your own that can handle translations? |
|
Back to top |
|
Justin Smarty Regular
Joined: 07 May 2003 Posts: 38 Location: Vilnius, Lithuania
|
|
Back to top |
|
DinoM Smarty n00b
Joined: 17 Mar 2004 Posts: 4
|
Posted: Wed Mar 17, 2004 8:08 am Post subject: |
|
|
AZTEK wrote: | Serzhik wrote: | AZTEK, I found you method better then others! Respect! And thanx for it! |
I am glad some people find it usefull. |
AZTEK, I would like to use your method too . 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 |
|
AZTEK Smarty Pro
Joined: 16 Apr 2003 Posts: 235 Location: Purdue University
|
Posted: Wed Mar 17, 2004 11:06 am Post subject: |
|
|
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 |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Wed Mar 17, 2004 11:27 am Post subject: |
|
|
sorry, why would you turn on caching and then don't cache the translated texts? |
|
Back to top |
|
AZTEK Smarty Pro
Joined: 16 Apr 2003 Posts: 235 Location: Purdue University
|
Posted: Wed Mar 17, 2004 11:37 am Post subject: |
|
|
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 |
|
DinoM Smarty n00b
Joined: 17 Mar 2004 Posts: 4
|
Posted: Wed Mar 17, 2004 11:47 am Post subject: |
|
|
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 ?
Thanks,
Dino |
|
Back to top |
|
AZTEK Smarty Pro
Joined: 16 Apr 2003 Posts: 235 Location: Purdue University
|
Posted: Wed Mar 17, 2004 2:23 pm Post subject: |
|
|
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 |
|
xces Smarty Regular
Joined: 09 Apr 2004 Posts: 77
|
Posted: Wed Apr 28, 2004 7:41 am Post subject: |
|
|
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 |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Wed Apr 28, 2004 8:08 am Post subject: |
|
|
@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 |
|
xces Smarty Regular
Joined: 09 Apr 2004 Posts: 77
|
Posted: Thu Apr 29, 2004 6:56 am Post subject: |
|
|
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 |
|
|