Marcel1993 Posted December 11, 2010 Share Posted December 11, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/221353-multilingual-application/ Share on other sites More sharing options...
BlueSkyIS Posted December 11, 2010 Share Posted December 11, 2010 the only thing I have to contribute is that you might want to keep your language options in files instead of in the database to reduce data query overhead and reduce effort required to add new languages. Quote Link to comment https://forums.phpfreaks.com/topic/221353-multilingual-application/#findComment-1145935 Share on other sites More sharing options...
Marcel1993 Posted December 11, 2010 Author Share Posted December 11, 2010 Thanks, that's a very important aspect - I think I'll write it in files Quote Link to comment https://forums.phpfreaks.com/topic/221353-multilingual-application/#findComment-1145936 Share on other sites More sharing options...
phpian Posted December 11, 2010 Share Posted December 11, 2010 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); Quote Link to comment https://forums.phpfreaks.com/topic/221353-multilingual-application/#findComment-1145941 Share on other sites More sharing options...
Anti-Moronic Posted December 12, 2010 Share Posted December 12, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/221353-multilingual-application/#findComment-1145943 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.