PHP - how to translate a website into several languages?

I have a website that is currently in English; I want to be able to switch to another language when the user clicks on another language (there are small country flag icons on the site). The way I'm currently trying to work with arrays, for example:

$english = array('index', array('h1' => 'this is some h1 text', 'h2' => 'this is some h2 text')); $japanese = array('index', array('h1' => 'ไธ–็•Œไบคๆ›ใธใฎๆญ“่ฟŽ', 'h2' => ไธ–็•Œไบคๆ›ใธใฎ')); print $english[index][h1]; print $japanese[index][h2]; 

As you can see, if I did this for every single page in a separate language, that would be an insane amount of code. What other method can I try?

+3
php internationalization translation
source share
4 answers

Given that you are looking for full i18n support that will ultimately lead to l10n support, I would suggest writing your page in a PHP framework that supports these things out of the box.

Personally, I only did translations using the Symfony platform. They use a combination of the i18n table extension in the database for content and XLIFF files to translate the interface. It was transparent enough as soon as it was configured, and using the framework avoids the need to write all this support manually.

I also know that i18n is supported in Zend, CakePHP, and Code Igniter.

+5
source share
  • Content database (or file I assume)
  • Record per page for each language
  • Language referenced by identifier
  • Identifier set in the $ _SESSION variable
  • Not necessarily remembered in a cookie for subsequent visits.

I used this system with a custom CMS @ www.grandhall.eu . This is especially interesting when you need to consider things like brochures and other downloads.

+1
source share

I suggest connecting your site to the Windows Live API or Google Translate API. I don't know about Google, but the Windows Live API seems very easy to use.

http://msdn.microsoft.com/en-us/magazine/dd569750.aspx

This, or you can write out all the content on the page in two languages, save them as in different tables in the "content" database, then change which table is loaded when the user clicks the language change button. Now, most of your hard work will be to rewrite content in both languages.

-2
source share

You can simply use the Google translate api:

http://code.google.com/apis/ajaxlanguage/

This has tons of documentation, and there are examples of how to use it on a Google Playground:

http://code.google.com/apis/ajax/playground/

Just go to ajax> translation

-4
source share

All Articles