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 ... 5, 6, 7 ... 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
toma
Smarty Regular


Joined: 25 Apr 2003
Posts: 62

PostPosted: Thu May 29, 2003 4:35 pm    Post subject: Reply with quote

I'm not sure there are any tips for multilanguage support that arn't covered in this amazingly long topic or in the documentation for the multilanguage tools discussed herein.

Did you have a specific question? If you want to know which way is best I'm sure everyone will tell you "MY way is best". Unfortunatly, there's so many possible ways to approach a new project that actually finding the MY way that works best for you isn't always easy.
Back to top
View user's profile Send private message Visit poster's website
thuree
Smarty n00b


Joined: 29 May 2003
Posts: 3

PostPosted: Thu May 29, 2003 11:31 pm    Post subject: Reply with quote

Hej,
Yes I am aware of the fact the there are many solutions.
Especially since reading all posts in this thread.
A lot of very good ones I think. I learned quite a bit by reading them, thanks. Smile

I have a few questions Question though..

1) I take it you store words and sentences in gettext, MySQL or XML, but how about long paragraphs - say 20 sentences. Do you store the sentences or paragraphs?
2) How is the performance if I choose to store single words (Home, Company, Cancel etc etc) in MySQL? Or I should load these popular words once, and then store them in session variables?
3) And this question perhaps do not belong here...
I am debating of using PHP and Smarty, and MySQL as a database, versus going for a more fully XML solution. Building up all the documents/pages in XML (since most of them are static) and then perhaps using Cocoon to present them.

Thanks
Back to top
View user's profile Send private message Visit poster's website
anzenews
Smarty Rookie


Joined: 04 Jun 2003
Posts: 15

PostPosted: Thu Jun 05, 2003 7:55 am    Post subject: xgettext Reply with quote

Hi!

Just my humble opinion on topic... I like block.t solution, though it doesn't solve all of the problems - for instance date formats should be language-specific. But there is one BIG problem - it doesn't use some external utility to extract strings, instead it sets $development to true and waits for all possible strings to surface. It would be much easier to just write a script that whould extract all of the strings between '{t}' and '{/t}' in non-greedy manner - that is what xgettext does for C, C++, Java,... Which brings me to the point. If such a solution was officially supported by Smarty (hint,hint... Smile ) maybe we could build support for template translation to xgettext? In my opinion we should seek STANDARD solution. XML? Well, gettext is supported on numerous Un*x sistems and is becoming standard for this task, so why invent another, especially since it works and is efficient. Babelfish? Still can be used for translating, but preferably a program that handles .po files...

As for the date formats - they could be solved in date_format plugin...

Just my 2 cents, hope that someday a (good) solution will be embedded in Smarty engine...

Have fun!
Back to top
View user's profile Send private message
flaimo
Smarty n00b


Joined: 06 Jun 2003
Posts: 2
Location: where the sun hits the sky

PostPosted: Fri Jun 06, 2003 2:17 am    Post subject: Reply with quote

I’ve written a i18n class i18n too where you can choose between, flat text files, Gettext files or a MySQL DB as a backend. I would like to provide some sort of smarty plugin, so users are able to use the class with smarty for example with {t}translate_string{/t}. I’ve read the article on Smarty Wiki, but I don’t really like to put the language object in a global variable. Is there a way to keep it all inside a class which extends the smarty class? I’m quite new to smarty, so I’m not familiar with the internal architecture of the smarty classes.

At the moment I’m using smarty and my i18n class on my homepage separated and have to create different cache id’s manually. The classes can be downloaded at http://sourceforge.net. (Tutorial | PHPDoku). My homepage is flaimo.com
Back to top
View user's profile Send private message Visit poster's website
brodie
Smarty n00b


Joined: 27 Jun 2003
Posts: 4

PostPosted: Fri Jun 27, 2003 1:59 am    Post subject: langselect Reply with quote

Hi all,

I created another solution to this that I have been using on my website. It is more suited to a fairly static website (i.e. not a blog). You can see a demo of it working and download the code from http://jellycan.com/langselect/

I'm using it now in a commercial website using English, Japanese and German translations. The main advantage of it is that the localized versions of the pages are stored in compiled form - once the page is compiled there is no extra hit for the localized text.

If it suits your purpose then great. If you do end up using it, then let me know - it'd be great to get feedback.

Cheers,
Brodie
Back to top
View user's profile Send private message
fabhren
Smarty Rookie


Joined: 29 Jun 2003
Posts: 9

PostPosted: Thu Jul 03, 2003 4:43 pm    Post subject: Call-time pass-by-reference has been deprecated Reply with quote

AZTEK's choice is just beautifull and works dandy. I built a small plugin and it works fine except with a warning and a notice dumped on the error log.

One concerns the block AZTEK published :
[Thu Jul 03 17:33:25 2003] [error] PHP Warning: Call-time pass-by-reference has been deprecated - argument passed by value; If you would like to pass it by reference, modify the declaration of xml_parse_into_struct(). If you would like to enable call-time pass-by-reference, you can set allow_call_time_pass_reference to true in your INI file. However, future versions may not support this any longer. in (xxxxx)\libs\smarty\plugins\block.translate.php on line 85
[php:1:40b414c0f9]
81 function getXmlTree($file) {
82 $data = implode("", file($file));
83 $xml = xml_parser_create();
84 xml_parser_set_option($xml, XML_OPTION_SKIP_WHITE, 1);
85 xml_parse_into_struct($xml, $data, &$vals, &$index);
86 xml_parser_free($xml);
87
88 $tree = array();
89 $i = 0;
90 array_push($tree, array('tag' => $vals[$i]['tag'], 'attributes' => $vals[$i]['attributes'], 'children' => getChildren($vals, $i)));
91
92 return $tree;
93 }
[/php:1:40b414c0f9]


If anyone knows the workaround plz post.

The other maybe something to do with smarty loading the plugins:
[Thu Jul 03 17:33:25 2003] [error] PHP Notice: Undefined offset: 3 in d(xxxxx)\libs\smarty\Smarty.Class.php on line 2460

Is there anything mystic on building plugins that may clean this notice ?

Thx in advance[list=][/list][list=][/list]
Back to top
View user's profile Send private message
AZTEK
Smarty Pro


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

PostPosted: Thu Jul 03, 2003 5:42 pm    Post subject: Reply with quote

Use[php:1:9c9197a4b3]function getXmlTree($file) {
$data = implode("", file($file));
$xml = xml_parser_create();
xml_parser_set_option($xml, XML_OPTION_SKIP_WHITE, 1);
xml_parse_into_struct($xml, $data, $vals, $index);
xml_parser_free($xml);

$tree = array();
$i = 0;
array_push($tree, array('tag' => $vals[$i]['tag'], 'attributes' => $vals[$i]['attributes'], 'children' => getChildren($vals, $i)));

return $tree;
}[/php:1:9c9197a4b3]instead it won't throw that notices

Also when I made my plugin smarty never threw an error on loading for me I use[php:1:9c9197a4b3]<?php
$xml = array();

function smarty_block_translate($params, $string, &$smarty) {
foreach($params as $key => $value) {
$params["%$key"] = $value;
unset($params[$key]);
}
print(t($string, $params));
}

function t($string, $args = array()) {
global $xml;

if(empty($xml)) {
if(file_exists("locale/{$_GET['lang']}.xml")) {
$xml = getXmlTree("locale/{$_GET['lang']}.xml");
} else {
return strtr($string, $args);
}
}

foreach($xml[0]['children'] as $tag) {
if($tag['tag'] == "MESSAGE") {
if($tag['children'][0]['value'] == $string) {
if($tag['children'][1]['value'] != "") {
return strtr($tag['children'][1]['value'], $args);
}
}
}
}

return strtr($string, $args);
}

function getChildren($vals, &$i) {
$children = array();

if(!isset($vals[$i]['attributes'])) {
$vals[$i]['attributes'] = "";
}

while(++$i < count($vals)) {
if(!isset($vals[$i]['attributes'])) {
$vals[$i]['attributes'] = "";
}

if(!isset($vals[$i]['value'])) {
$vals[$i]['value'] = "";
}

switch ($vals[$i]['type']) {
case 'complete':
array_push($children, array('tag' => $vals[$i]['tag'], 'attributes' => $vals[$i]['attributes'], 'value' => $vals[$i]['value']));
break;
case 'open':
array_push($children, array('tag' => $vals[$i]['tag'], 'attributes' => $vals[$i]['attributes'], 'children' => getChildren($vals, $i)));
break;
case 'close':
return $children;
break;
}
}

return $children;
}

function getXmlTree($file) {
$data = implode("", file($file));
$xml = xml_parser_create();
xml_parser_set_option($xml, XML_OPTION_SKIP_WHITE, 1);
xml_parse_into_struct($xml, $data, $vals, $index);
xml_parser_free($xml);

$tree = array();
$i = 0;
array_push($tree, array('tag' => $vals[$i]['tag'], 'attributes' => $vals[$i]['attributes'], 'children' => getChildren($vals, $i)));

return $tree;
}
?>[/php:1:9c9197a4b3] named as block.translate.php
_________________
"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
Chavez
Smarty Rookie


Joined: 08 Jul 2003
Posts: 6

PostPosted: Tue Jul 08, 2003 11:48 am    Post subject: Reply with quote

First of all: nice thread! It has helped me a lot.

I have one question though. AZTEK's XML method, there has to be performance issues passing these strings around, right?

I don't know if it would be a faster solution or not but wouldn’t it be better to write an Smarty plugin that’s - extract the blocks ({t}some text{/t} and then uses gettext instead of the XML solution.

Wouldn’t that be a faster solution or am I mistaken?
Back to top
View user's profile Send private message
AZTEK
Smarty Pro


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

PostPosted: Tue Jul 08, 2003 5:46 pm    Post subject: Reply with quote

Either way your still passing strings arround. My method only parses the language file once per request which ups on memory but makes it a hell of alot faster. Plus PHP's XML parsing is pretty fast already. Plus I knew many many people have had trouble getting gettext and PHP to work correctly so I decided for a project that is to be released gettext wouldn't suffice.
_________________
"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
flaimo
Smarty n00b


Joined: 06 Jun 2003
Posts: 2
Location: where the sun hits the sky

PostPosted: Tue Jul 08, 2003 6:12 pm    Post subject: Reply with quote

another point when using gettext is that you can't use more that one language per page or you'll get weird results. when using xml i would cache the serialized translation array, which is even faster.
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: Tue Jul 08, 2003 8:10 pm    Post subject: Reply with quote

flaimo wrote:
when using xml i would cache the serialized translation array, which is even faster.


Which is what the global variable $xml is for Smile
_________________
"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
Chavez
Smarty Rookie


Joined: 08 Jul 2003
Posts: 6

PostPosted: Sat Jul 12, 2003 2:50 pm    Post subject: Reply with quote

Hi again!

I have this foreach section in one of my templates:

Code:
{foreach item=ad_lang from=$memberPreferences.ad}
<option value="{$ad_lang}">{translate}{$ad_lang}{/translate}</option>
{/foreach}


How do I make the template behave the way I want? I guess that the translate-block is processed before variable assignment, right? Would it be possible to use a postfilter to translate the output of my PHP script? Any tips (and code of course) would be appreciated.
Back to top
View user's profile Send private message
mzanier_XTC
Smarty Regular


Joined: 04 May 2003
Posts: 38

PostPosted: Sun Jul 20, 2003 7:18 pm    Post subject: Reply with quote

hi there,
i got some questions )
i want to use multi languages files for my templates like this::
i store my language files in::
( 1 language file for each template file)
/templates/current/language/deu
/templates/current/language/esp
/templates/current/language/eng
..
..
the language files should contain the txt and aliases (like i used it php)
define('TEXT_LALAL','hello world');
and echo TEXT_LALAL;
.
now i want to use the same aliases in my template file, and smarty should get the right prhases from the lang file.
any1 got an idead how i can solve this ?

like this::


in template::
{config_load file="language/{$language}/mysite.conf"}
{$lang.TEXT_LALAL}

how should my config file look like, that the tpl can parse the $lang array from it ?

any ideas ?
thx
_________________
[quote]
http://www.xt-commerce.com
Back to top
View user's profile Send private message Visit poster's website
sagi
Smarty Regular


Joined: 30 Jul 2003
Posts: 43

PostPosted: Mon Aug 11, 2003 3:11 pm    Post subject: Reply with quote

Okay, because none of the solutions here is complete I decided to write my own smarty wrapper for gettext.

You can see what I've done so far here:
http://beep.boom.org.il/~sagi/smarty/smarty_gettext.phps

It currently supports arguments and plural handling:
- I decided to use %arg to represent the arguments - so the first argument is %1, the 2nd is %2, and so on (using sprintf-style might be too complicated for translators, and using variable names like $name might mix up in various languages). To assign arguments you just list them with any key, all that matters is their order, for example:
{t name="sagi" age=18}my name is %1 and i'm %2 years old{/t}

- Plural handling is done by giving the plural version as a parameter named 'plural' and the single version as the block content. The counter is called "count", or the first argument will be used if is not set.

for example:
{t plural="%1 files" files=5}%1 file{/t}

Will output "1 file" if files=1, or %1 files otherwise.

You can use the same function inside your PHP code by calling translate(text, params) where text is the block content and params is array with the parameters.

I'm currently working on a script that scans the template files and dumps the strings inside C gettext() calls so the gettext tools such as xgettext can use the strings from smarty.

I would like to hear your opinion..
Back to top
View user's profile Send private message
fbronx
Smarty Rookie


Joined: 28 May 2003
Posts: 11
Location: Stekene, Belgium

PostPosted: Thu Aug 21, 2003 7:38 pm    Post subject: Reply with quote

sagi wrote:

I'm currently working on a script that scans the template files and dumps the strings inside C gettext() calls so the gettext tools such as xgettext can use the strings from smarty.

Could it be possible to use the poedit program for this?
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 ... 5, 6, 7 ... 13, 14, 15  Next
Page 6 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