The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

French Translation -- What is the easiest way?

I'm doing front end development for a very busy web development company here in Canada and we often do fairly large websites that require French Translation.

Currently we are using a system that is very time consuming to implement the french content in the PHP pages.

Here is an example of how we are including the content. Basically, there is a cookie variable stored that keeps the user's preference of French or English. The HTML with content looks something like this: (a rudimentary example)

So, the PHP code that gets the "label", pulls the label text out of the database. The database has two entries for each label. One for each language.

The reason this is time consuming is that, when I do the front end (HTML, CSS), I have to cut and paste every section of content and save them all into different entries in the DB.

So since this would be very difficult and time consuming, when I cut the content out of the HTML, I bring a lot of the HTML with it. So the HTML ends up being inside the getLabel code, as opposed to what you see above. So it would look like this:

Code:

<body>
<?=$page->getLabel('HOME_CONTENT')?>
</body>

So while example #2 is much easier to implement initially, I imagine it is much worse when doing updates to the HTML, since you have to actually go into the DB and edit the HTML right in there.

So my question is, is there an easier way to do this without duplicating the entire website and doing updates in two different directories, or without doing updates to multiple entries in the DB, as shown above?

That's really just a particular implementation. It doesn't solve Louistar's problem, as I understand it. Unless there's something more to Zend_Translate, that I don't know of?

To address the question; I don't think there's an easy way, but you can at least do a couple of things. First, since you're going to write $page->getLabel() a lot, do yourself a favor and wrap it in a shorter function. If you use gettext, then it's done for you already, otherwise you can just invent your own. I use two underscores, eg. __("HOME_TITLE").

Another thing you can so, is to use the English phrase as the label. So instead of __("HOME_TITLE"), you would write __("Frontpage"). Since you already have the content in English, it would be much faster to change it.

Once you have this done, do write a script which logs all missed calls to __() by inserting an empty record in the database. You can now easily get a list of words/phrases that need to be translated.

Another thing you can so, is to use the English phrase as the label. So instead of __("HOME_TITLE"), you would write __("Frontpage"). Since you already have the content in English, it would be much faster to change it.

The problem with this, as opposed to the labels approach, is that the french phrase remains linked with the english one, so that if you change it from "Frontpage" to "Welcome" you have to update the links.

BTW multilanguage problems were one of the reasons why makrell was invented. This is how I do it:

If you use gettext, then it's done for you already, otherwise you can just invent your own. I use two underscores, eg. __("HOME_TITLE").

Notice that all symbols starting with two underscores are reserved for PHP. My advice is to use either t() or l() or anything else that's short.

Originally Posted by stereofrog

The problem with this, as opposed to the labels approach, is that the french phrase remains linked with the english one, so that if you change it from "Frontpage" to "Welcome" you have to update the links.

No you create a new locale that links the english in the source code to the english you want it to be. Eg. you change the Frontpage to Welcome in the english .mo file (in case of gettext) but leave the text Frontpage in the application itself. This doesn't break the application an requires a minimal .mo file.

A word of warning on gettext though; the setlocale function is not thread-safe so if you'll have to change the locale dynamically don't use it. See setlocale() for more information.

kyberfabrikken: Yes, that is just a particular implementation. But as far as I understood Loiusstart needed to be pointed in the direction of a scalable and maintainable solution for his problem. This is one of them.

I agree with kyberfabrikken, I am afraid there is no easy way. The selected approach seems to me both hard to scale and maintain. If these are important elements for your page, I would consider a complete refactoring. Using databased for translating static text seems like a poor idea to me, and makes it hard to maintain (both translations and code) and challenging performance wise .

If you were using gettext for this you would have two (or more if several people are translating at the same time) files to work on, and poedit would easily tell you if there are any changes made to the translation etc. It is also very easy to add several languages since on only need to create the translation file and start translating.

No you create a new locale that links the english in the source code to the english you want it to be. Eg. you change the Frontpage to Welcome in the english .mo file (in case of gettext) but leave the text Frontpage in the application itself.

Yes, like kyber said, it defaults to printing the label. However, any changes you make to the text happen in the translation files instead of the source-code. (That is, unless the changes should break).

Another thing you can so, is to use the English phrase as the label. So instead of __("HOME_TITLE"), you would write __("Frontpage"). Since you already have the content in English, it would be much faster to change it.

Hi, K. Thanks for the response. What exactly do you mean by the above? I don't see how that would make any difference. The text "HOME_TITLE" is actually just a custom name for the label that holds the actual content. So why would it matter to change it to say "Frontpage"?

Hi, K. Thanks for the response. What exactly do you mean by the above? I don't see how that would make any difference. The text "HOME_TITLE" is actually just a custom name for the label that holds the actual content. So why would it matter to change it to say "Frontpage"?

Thanks,

Louis.

Because that way you always have a user friendly 'backup' text that you can display. This means that you don't necessarily need to have a complete translation before shipping. It's also easier for the translators because they already have a complete text (instead of some arbitrary label).

Because that way you always have a user friendly 'backup' text that you can display. This means that you don't necessarily need to have a complete translation before shipping. It's also easier for the translators because they already have a complete text (instead of some arbitrary label).

Also, the work process changes from:
Find all localised text in file. For each, make up a label and then cut it out, replace with the label and finally paste label + localised text into external file.

sorry to waste a post without content, but it would only let me add one tag to the thread (wtf...why?) so i'm going to use the word i18n and internationalization so people on the internets can find this thread by searching.