views:

77

answers:

5

Hi,

I'm developing a website that will be available in different languages. It is a LAMP (Linux, Apache, MySQL, PHP) setup, and it makes use of Smarty, mostly for the template engine.
The way we currently translate is by a self-written smarty plugin, which will recognize certain tags in the HTML files, and will find the corresponding tag in an earlier defined language file.

The HTML could look as follows:

<p>Hi, welcome to $#gamedesc;!</p>

And the language file could look like this:

gamedesc:Poing 2009$;
welcome:this is another tag$;

Which would then output

<p>Hi, welcome to Poing 2009!</p>


This system is very basic, but it is pretty hard to control, if I f.e. would like to keep track of what has been translated so far, or give certain users the rights to translate only certain tags.
I've been looking at some alternative ways to approach this, by either replacing the text-file with XML files which could store some extra meta-data, or by perhaps storing all the texts in the database, and retrieving it there.
My question is, what would be the best way to make this system both maintainable and perform well with high user-traffic? Are there perhaps any (lightweight) plugins I could take a look at?

+3  A: 

Maybe taking a look to gettext lib could help you get some hints http://php.net/manual/en/book.gettext.php hope it helps!

markcial
+1  A: 

You will need to have a table in your database that you can use to store strings of text, each with an composite ID. the composite ID will be made up of language ID and text node ID.

You will need to give the user a chance to select a preferred language. You should make sure that you either have a default "this has not been translated" for every language you use, or a default language that your entire site can be vied in.

For every bit of text with in your web site, rather then store the text with in the page, you just assign it an ID.

When serving the page, look up the text node ID and preferred language ID and load that string of text, or the string for the default.

thecoshman
That's pretty close to one idea I had been playing with. However, on a high-traffic website, wouldn't this turn out to be a massive database-load?
Jasper De Bruijn
If you are worried about database load, you could create a system for caching pages or parts of them, but it depends how dynamic are informations being displayed and how many pages/languages you have.
Kjir
May be another option then, could be to do it via either server of client side code. On each an every page, you have each section of text repeated for every language, all set to display:none except the one you want, which you use code to clear the display property for. This solution provides a perfect ZERO database load. If done server side will allow the files to keep small (when transferred) if done client side saves server load, but at the cost of bandwidth.EDIT: You need to think about what part exactly you want to be efficient. Is it server load you need efficinet, page load times etc
thecoshman
In the end it would be best if everything is efficient :) for this particular application, we will have over 20 different languages, so sending all the texts might be a bit too much traffic. I think Kjir's idea, about caching the pages in the different languages is probably the best for my application.
Jasper De Bruijn
It would be very difficult to have *everything* efficient. I mean, you can it relatively efficient, but some where you have to give something. Storing the languages is inefficient use of server space. The efficient solution is to provide just one language and let the user translate it them selves.Sending all the languages to the user and letting JS translate it is an inefficient use of bandwidth, should do it server side.using PHP/ASP is inefficient use of server power.I could go on, point is, you have to chose what is most important to you.
thecoshman
+3  A: 

You could give a shot at gettext. It is the way it is done in most C/C++ linux applications and it is an extension to PHP too. The idea is not very different from what you're already doing, but there are tools that ease the mantainance of translations (i.e. poedit).

For user rights to translations, gettext won't be of much help, I think you'll need to do it on your own or look at some frameworks if they have smarter solutions.

Kjir
Thanks, this seems to me like an approach that is comparable to my current set-up, but with enough extra features to make it more maintanable. I like the fact that there are existing tools for it.
Jasper De Bruijn
You could also give a shot at Zend Framework's Zend_Translate: http://tinyurl.com/yl28xqy
Kjir
Also look at the page where it speaks about adapters for Zend_Translate, there are a list of file formats commonly used and it may help you find a solution that suits your needs perfectly.
Kjir
A: 

Looking around at web stuff today I came across this website: http://translateth.is/

It looks simple to use... copy paste in some javascript.

PaulELI
Yeah, it's based on the Google Translate API. Although there has been alot of improvement lately, I wouldn't depend on machine translation for any serious websites.
Jasper De Bruijn
+1  A: 

in our project, http://pkp.sfu.ca/ojs, we use XML files to store translation key-value pairs. Browse our code: http://github.com/pkp/pkp-lib/blob/master/classes/i18n/PKPLocale.inc.php

We use that class to read the XML files for each locale and in our code we use Locale::translate('locale.key.name');. Similar to gettext, but using an XML file for easier updating.

pocketfullofcheese
thanks, it looks as if there are some usefull components in that code! The logging of missing keys f.e.
Jasper De Bruijn