PHP Prepare your site for multilingual versions.
When you decide to have a multilingual version of your site, it is much easier if all your strings are ready for translation.
PHP Prepare your site for multilingual versions.
When you decide to have a multilingual version of your site, it is much easier if all your strings are ready for translation.
Simon Tite 6:25 am on November 8, 2009
This knowledge is probably somewhat out-dated, it only applies if you don’t have the php “gettext” module installed. After a recent upgrade of my system to PHP5 and Ubuntu Karmic, this seems to be enabled by default, but I’m not sure when this changed. Sorry if this information has confused anyone. (lesson learned: don’t apply two major updates at the same time!)
However, IF the gettext module is NOT installed (check the phpinfo results), then:-
Create the following “dummy” function:-
As you can see, this function effectively does nothing yet. However, the function “_” is a standard name used in internationalisation to signify “this is a string to be translated”, and you should use this throughout your site wherever you output a string to the user, Example:
When you install some translation management software (.po .mo files), you can then replace the function _ to call the appropriate translation substitution software.
If you have the gettext function already installed, just be sure that all your output strings are passed through the function _(”string to be translated”), and it will use the untranslated string by default, if you have supplied no translations.
This is well worth doing if there is any possibility you might eventually want a multilingual site, it will save you a lot of time later on.