The 2006-12-19 at 15:19 by Loïc d'Anterroches filed under PHP: Hypertext Preprocessor.
Yesterday I took a look at gettext to be used in the core of the next version of Plume CMS. I was ready to use it until I discovered some annoying things:
Check the comments on the gettext PHP manual page to see all the problems you can have. As Plume CMS is supposed to be used in a non controlled environment, I had to find another solution. Looking around, I found a nice gettext benchmark. The results from the benchmark together with the interesting comments can be summarized as:
The solution I found is basically to reuse the approach of the current Plume CMS translation system and extend it. At the moment, the translation system does not support plural forms, so I created it. The partial implementation is available in Pluf. Pluf is the MVC framework that will be used as the core of the next release of Plume CMS. Now you can do the following:
// Translate a single string
echo __('Hello World!');
// Translate a plural form
echo sprintf(_n('Here is %d apple.', 'Here are %d apples.', $n), $n);
The file storing the translations is an easy to read and write .ini like file and the framework will automatically cache the strings in a dynamically generated PHP file ready for inclusion and parsing by the PHP tokenizer, thus really fast.
Here is an example of a .lang file:
# -*- coding: utf-8 -*- # (C) 2004-2006 Cédric Arrabie, Loïc d'Anterroches ;Welcome on the Plume CMS installation Bienvenue sur l'assistant d'installation de Plume CMS ;Next Suivant ;Nothing to see here. p;You have some things to see here. 0;Rien à voir ici. 1;Une chose à voir ici. 2;Plusieurs choses à voir ici.
Basically, we will be able to use it like gettext and ngettext. Of course it is a very simple approach and I am not an expert in internationalization, but today Plume CMS is already translated in several languages and this approach is just improving the current approach, so basically translators will be happy (I hope).
Comments from readers