You want to distribute your PHP-Gtk application on your webpage
and make it reach a large number of people. The only problem
between your application and all the people is not the
functionality; your app is perfect in this way:
It is the language.
Even if some people don't or don't want to realize: There are
lots of people out there which would use
your program but don't speak your language or the language
in which your program is. It would be nonsense to ignore them.
The solution is easy: Translate the program. Just find a
person who speaks the target language and who is willing
to translate all the things your program contains.
But the next step: How do you - technically -
translate your program?. There are many ideas
how to do this:
Take the program sources (and glade files), make a copy and
translate them. This is the worst method: If you want to
extend your program you will have to change every single
file of the 20 translated versions.
Even worse: The translator does not have to be a programmer,
and requiring him to change the sources can cause serious
problems with the code: Does the translator know how to
deal with escape sequences? What if the translator accidently
removes a end-quote? The program just won't run, and you
will have a nice time searching bugs in all the translated
Using a big array which contains all the texts. Put it in a
translation file for each language, and include the right one
when the program starts. This has the advantage that translation
and code are segregated strictly, and the translator will have
an easy job. Just what if you are using glade files for
your GUI definitions? You would have to make a copy of each
glade file and translate it; causing the same problems as the
first option. Or you load every single widget and change the
text of it. This would require a function in your application
which knew every single widget and the string in the big
translation array it should apply.
Using the text as normal in the sources, but having it and
the glade files translated automatically. Impossible?
No, the gettext extension of php makes this scenario real.
This tutorial shows how to translate your apps the most easy
way using the gettext extension of php. It covers normal
string translation as well as the translation of glade files
and shows a solution if the gettext extension is not available
on the user's system.
Example 3.1. The first and worst translation method
echo '<title>Shopping cart</title>';
echo 'Copying file ' . $strFile1 . ' to ' . $strFile2;
echo 'Kopiere Datei ' . $strFile1 . ' nach ' . $strFile2;
Example 3.2. The second method
$arTranslation = array(
'title' => 'Shopping cart',
'copy_1' => 'Copying file ',
'copy_2' => ' to '
$arTranslation = array(
'title' => 'Einkaufswagen',
'copy_1' => 'Kopiere Datei ',
'copy_2' => ' nach '
echo '<title>' . $arTranslation['title'] . '</title>';
echo $arTranslation['copy_1'] . $strFile1 . $arTranslation['copy_2'] . $strFile2;
Example 3.3. Using gettext
echo '<title>' . _('Shopping cart') . '</title>';
echo sprintf( _('Copying file %s to %s'), $strFile1, $strFile2);