RE: translating in different languages
| From: | Roel Vanhout | Date: | Mon, 05 Mar 2001 20:34:55 +0000 |
| Subject: | RE: translating in different languages | ||
| References: | 1 2 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-311@lists.php.net to get a copy of this message | ||
On Mon, Mar 05, 2001 at 11:41:50AM +0100, Alain Fontaine wrote:
> > I think that translations would be a natural thing to integrate into
> > a template system, in the end, translating is a display issue: you
> > just want your texts to show up in another language, without having
> > to worry about more.
> Translating text is not really a display issue in my eyes. Let's put
> it this way: text belongs more to the 'content' layer of the site than
> to the 'presentation' layer of the site.
Ok, I guess this depends on how you look at it. In my opinion (being a
programmer), I prefer to not have to worry about assigning values for
every string in the template. I would like more to be able to select a
language in my program for the $smarty object, and not worry about it
any more. My code is already long enough without having to add a minimum
of (x * 2) (where x is the number of strings in every template, which in
my case can easily be 20 or more) lines to my code.
> there's no problem at all with using stphp and smarty together,
> for
I agree, but see above for my comment about this. On the other hand, it
would be not problem to use both Smarty's translation functionality for
the easy strings ('simple' strings and simple substitution) and stphp to
do the 'hard' things like numbering et all. As I see, in stphp someone
would have to write functions to make the numbering and plural forms of
strings anyway. That person would be the programmer, which would fit
nicely: the programmer works with the translators for the hard things,
and the translators can easily translate the rest on their own.
> > Stphp doesn't look as convenient to me. It's ok for sites with a few
> > pages, but putting
> > eval (ST ("TheThreeMusketeers", "\$string", "en")); echo
> > "<p><b>$string</b>";
> > in templates will not make it look better, and make the job of
> > template editors harder.
> You're right, using stphp that way will break the concept of
> templates, and that's definitely not the way to do it. But look at it
> this way, for instance: A smarty template would contain the
> {ErrorMessage} placeholder, like this:
> -- <HTML> <BODY> <h1>{ErrorMessage}</h1> </BODY> </HTML> --
> The PHP code could look like this:
> -- eval (ST ("ErrorMessage", "\$string", $languageID));
> $mySmarty->Assign("ErrorMessage",$string);
> $mySmarty->Display("template.tpl"); --
> Voila! Isn't this easy ? $languageID would be a variable stored in the
> user's session: "fr" or "en" or "de", and so on (I've
> done it that way
> at least).
Ok, but there would be a need for a two lines of code for every string
in the template, while the other solution would be like this:
$mySmarty->language = $languageId;
$mySmarty->display("template.tpl");
, and this once for the whole script.
> > [cut] of string substitutions. Also, with stphp and gettext you are
> > limited to storing the translations in files, while it would in some
> > places be easier to use a database.
> stphp does support DBM files, which offer excellent speed for this
> kind of things. I've used stphp on a site with 4 languages and over
> 4000 strings, and it just flies. As for the reason to use a database,
> I don't really see why? You will never do anything else on the string
> table than
Yes, indeed. I had a look at stphp today, and it does provide multiple
ways of accessing the strings. But it would be trivial to write a dbm
driver for the other way of translating, and still giving people the
possibility to use a database (I like databases more for my situation as
it makes it easy to synchronize the translation files over the whole
pool of database servers with replication. Otherwise I'd have to copy
the translation files to every web server every time an entry changes,
or rely on something as nfs to mount them from a shared drive, which is
not very reliable nor networkload-friendly, to put it mildly).
> for instance. I don't see the need of a database for that kind of
> operation. Performance certainly is NOT a reason, because at the very
> base, your db tables are also stored as files on disk (most of the
> time, anyway).
I agree that performance would be not affected (I would say that a
database is a lot slower then dbm or even plain text files), but this is
not an issue with Smarty: by making a 'compiled' version of the script
for every language, there needs to be only database/file access for the
first time a script is called. After this, the cached version is used
and no performance penalty whatsoever is taken. While with stphp, there
would have to be a lookup for every string, every time a script is
called. I would say that a native smarty solution here is not only more
performant, but even necessary on a big site.
I do agree that the way stphp handles variables is very flexible, and I
want to use their design in my implementation as well. This will however
mean that it will take a day longer (maybe a few days) before I have
code that is actually worth releasing :-)
I do not see a need to implement something like the function calls in
stphp, this would defeat the speed gain of the compiled scripts. I
suggest that people who need this flexibility use stphp, combined with
native smarty translation like I described a few paragraphs earlier.
> I think this is a very interesting discussion, and I'm waiting for
> your comments ;).
Please let me know what you think :-)
cheers,
.roel
--
ALL YOUR BASE ARE BELONG TO US