I have to develop a pretty simple php website so I don’t need framework.
But it’s must support multi language (EN/FR/CHINESE).
I have looked for php built in system and I found two ways :
- intl module from php5.3 (http://php.net/manual/fr/book.intl.php)
- gettext (http://php.net/manual/fr/book.gettext.php)
I have no experience in i18n without framework, so any advices about what’s the simplest way to support multi language ?
At end I just need a function that search translation into file (one file by language).
EQ :
trans('hello');
=> en.yaml (yaml or not, it’s an example)
hello: "Hello world!"
=> fr.yaml
hello: "Bonjour tout le monde !"
And if possible I prefer Pure PHP implementations
Although
ext/gettextandext/intlare both related to i18 (internationalization),gettextdeals with translation whileintldeals with internationalizing things like number and date display, sorting orders and transliteration. So you’d actually need both for a complete i18-solution. Depending on your needs you may come up with an home-brew solution relying on the extensions mentioned above or your use components provided by some framework:Zend_TranslateZend_LocaleIf you only need translation and the site is simple enough, perhaps your simple solution (reading a translation configuration file into an PHP array, using a simple function to retrieve a token) might be the easiest.
The most simple solution I can think of is: