Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the best method to build "multilingual" script in php?

I am building a website and it need to be in 7 languages? I was wondering if there is a good practice can be applied to get multilingual php script?

  • Easy for me
  • Easy for the translators

Also what do you think , should I Store it in DB , XML or in PHP file?

like image 969
Sulaiman Avatar asked Jan 19 '09 13:01

Sulaiman


People also ask

How do I add PHP multilingual support to my website?

Ways to add multi-language support to a website There are various ways to enable Multi-language support for an application. By having duplicate pages with the same content in the required languages. By managing language configuration (localization) with files containing texts in different languages.

How can I translate a PHP language?

php class Translator { private $language = 'en'; private $lang = array(); public function __construct($language){ $this->language = $language; } private function findString($str) { if (array_key_exists($str, $this->lang[$this->language])) { echo $this->lang[$this->language][$str]; return; } echo $str; } private ...


1 Answers

There are plenty of options for storing translations:

  • TMX: A relatively new XML format for translations. Seems to be gaining in popularity.
  • Gettext is another open format for translations. Been the de-facto standard for a long time.
  • ini files - easy to edit, very simple format
  • PHP files (arrays) - easy to edit for PHP programmers, good performance
  • CSV format - relatively simple to use.

I'd suggest you use something like Zend_Translate which supports multiple adapters and provides a basic approach to embedding translations in your application.

like image 86
Eran Galperin Avatar answered Oct 06 '22 02:10

Eran Galperin