CIDSPHERE.COM

A blog about technology, photography and some other things you don’t care

Translation technique within a web application

May 12th, 2009. Published under Technology. 6 Comments.

I want to precise something before starting on the subject. I don’t search for tools to store my translation memory since I’m already using the component Zend_Translate of Zend_Framework which is great! What I’m searching is a technique to translate phrases with word coming from a database.

Here is an example of my problem. I want to translate the phrase « Delete the {obj} » where {obj} can be anyone of these words : project, component, activity, task. All these words are in a table and can change in time and I want to use them in other context. In english, that’s fairly simple, you just have to replace {obj} with the word you want to use in your page.

But in french you can’t do just that, you have to deal with the gender of words. For example, the same phrase in french looks like « Supprimer {pronoun} {obj} » where {pronoun} is « le » for the word « project », « la » for « composante » and « tâche », finally « l’ » for the word « activité ».

And this is just one example! What should I do when I add some plural form in the mix ? And what happen with other languages like portuguese and spanish? The worst thing about that is that I can’t find anyting about that in Google…

I have some solution in mind but I want to know how other people are doing it before doing my own implementation. When I have something, I will post my solution here.

6 Comments

pothibo  on May 12th, 2009

Well, maybe you should do some extensive work on the google translator, but I would try to get a XML parser working with http://translate.google.com.

I did some small testing and you get pretty much what you wanted. I think the XML parser could be pretty easy to implement since the full query lies in the url ie:
http://translate.google.com/translate_t?hl=fr#en|fr|Delete%20the%20activity

So the only thing you’d need would be to take your dynamic string and send it to the translator

XaV'S  on May 12th, 2009

Honestly, i think the problem are the variables should not use variables to build the message. The risk to do this is to need to handle each languages in your code, and this smell really bad for the maintenance after.

My opinion is you should only use variable to show user-values in messages (Example : “Delete user {username}?”). Yes, you may have more messages strings to handle, but you will save a lot of work when the moment to handle translations. And finally, you have a better code because you don’t have to build the string, depending of the language, so after is more easy to do maintenance.

(Sorry, my English is really poor).

gserale  on May 12th, 2009

I agree on what XaV’S said:

You cannot implement such a method for the translation. It’s too complicated for what it’s meant for. I honestly think that the best thing to do is to translate each sentence in the desired language.

Otherwise, pothibo’s solution seems to be relevant, but again, that’s far much more complicated.

It’s up you, depending on the time you want to spend on it! ;]

Sylvain Filteau  on May 12th, 2009

@Xav I think you’re correct about the fact that it would be really hard to maintain, but the thing is that those elements must feel like it’s hardcoded in the application. This list isn’t editable by the user, only by the administrators of the system (me).

But maybe the tradeoff would worth it… I’ll reevaluate that tomorrow.

@pothibo could be a good solution but only in our build process. But I don’t like to rely on Google for this kind of stuff.

XaV'S  on May 12th, 2009

@Sylvain : Especially if only you can edit the actions, you will save a lot of time to create a separate message for this action in same time you add it in your database!

pothibo  on May 13th, 2009

create a separate table on your database where you store all the string with %s as your php variable and then organize it to show the proper string for each value.

Kinda long and tedious but it could work.

Leave a Comment