Jump to content

Multilingual Application


Marcel1993

Recommended Posts

Hey guys,

 

I am looking for a possibily to create a multilingual application. The languages I want to provide are English, German, and Spainish. At first I thougth it is going to be very easy. I just create a extra table for the language-contents.

 

ENGLISH GERMAN SPANISH

TABLE    TISCH    MESA

 

So far so good - but what will be if there is a phrase with included variables? I think in English it is quiet easy to form correct sentences. In German and Spanish there are some specifications what lead to garbled sentences.

 

So LANGUAGE_PART_1 VARIABLE_1 LANGUAGE_PART_2 LANGUAGE_PART_2 wouldn't work as desired.

 

Can I make PHP just set in a place any variable? So when I've got the sentence "At the moment there are #NUMBER_OF_TABLES# tables available", "Momentan sind #NUMBER_OF_TABLES# Tische verfügbar" or "Actualmente hay #NUMBER_OF_TABLES# mesas disponibles".

 

In this case PHP is supposed to set in #NUMBER_OF_TABLES# the variable $number_of_tables.

 

Perhaps there are some other ways for developing a multilingual app.

Thanks a lot for helping  ::)

Link to comment
Share on other sites

I use something called gettext. It is able to deal with the scenarios you have described. Basically, whenever you output a line that requires translating, you use the _("my text goes here") function. Then you are able to scan the source code which will generate a list of phrases that need translated. It can also deal with dynamic phrases that may be singular or plural.

$num = 5;
sprintf(ngettext("At the moment there is only %d table available", "At the moment there are %d tables available", $num), $num);

Link to comment
Share on other sites

I think Zend Framework has a good translation component. You don't need to use the whole framework, just that one class (usually).

 

1. don't store translations in the database - use files with $variables

 

You can see quite a few multilingual applications do this. They will have:

 

english.php


$text['122'] = 'a piece of english text!';
$text['123'] = 'another etc';

 

You can go a step further and use descriptive array keys. The important part is that the data be stored in an array. Your app will then include english.php or italian.php and the relevant language array is available for your app.

 

2. you might want to look around for some automatic translation scripts. (I think ZF doe this, not sure). Of course, this would require the use of services which translate text for each piece. However, I have seen people use links which will translate the existing page and I'm sure you've used babelfish before.

 

Guideline would be: small strings, use a language file. Large bodies of text, use a web translation service api.

 

Hope that helps.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.