Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The gettext system echoes strings from a set of binary files that are created from source text files containing the translations in different languages for the same sentence.</p> <p>The lookup key is the sentence in a "base" language.</p> <p>in your source code you will have something like</p> <pre><code>echo _("Hello, world!"); </code></pre> <p>for each language you will have a corresponding text file with the key and the translated version (note the %s that can be used with printf functions)</p> <pre><code>french msgid "Hello, world!" msgstr "Salut, monde!" msgid "My name is %s" msgstr "Mon nom est %s" italian msgid "Hello, world!" msgstr "Ciao, mondo!" msgid "My name is %s" msgstr "Il mio nome è %s" </code></pre> <p>These are the main steps you need to go through for creating your localizations</p> <ul> <li>all your text output must use gettext functions (gettext(), ngettext(), _())</li> <li>use xgettext (*nix) to parse your php files and create the base .po text file</li> <li>use <a href="http://www.poedit.net/" rel="noreferrer">poedit</a> to add translation texts to the .po files</li> <li>use msgfmt (*nix) to create the binary .mo file from the .po file</li> <li>put the .mo files in a directory structure like</li> </ul> <p>locale/de_DE/LC_MESSAGES/myPHPApp.mo</p> <p>locale/en_EN/LC_MESSAGES/myPHPApp.mo</p> <p>locale/it_IT/LC_MESSAGES/myPHPApp.mo</p> <p>then you php script must set the locale that need to be used</p> <p>The example from the php manual is very clear for that part</p> <pre><code>&lt;?php // Set language to German setlocale(LC_ALL, 'de_DE'); // Specify location of translation tables bindtextdomain("myPHPApp", "./locale"); // Choose domain textdomain("myPHPApp"); // Translation is looking for in ./locale/de_DE/LC_MESSAGES/myPHPApp.mo now // Print a test message echo gettext("Welcome to My PHP Application"); // Or use the alias _() for gettext() echo _("Have a nice day"); ?&gt; </code></pre> <p>Always from the php manual look <a href="http://zez.org/article/articleview/42/2/" rel="noreferrer">here</a> for a good tutorial</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload