The PHP adapter

The I18NEdit source code distribution contains the PHP script i18n.inc.php It makes Java-style localisation property bundles available to any PHP4-driven website. From i18n.inc.php"s introductional comment:

i18n.inc.php provides simple localization for PHP-driven web sites. It uses Java-style .properties files for storage of localized bits.

I18N can be used on any PHP4-driven web site. It works with files only, needs no database. It is very flexible and can be used totally independent from the design parts of the site. It supports the global variable $lang, which can contain the current locale.

I18N creates the file names with the translated strings from "$SCRIPT_NAME" by exchanging the extension (e.g. ".php") with "_p_XY.properties" and (by default) prepending the path "/i18n" to it. So, if the .php file is stored in /path/to/root/subdir/index.php, the .properties files would be /path/to/root/i18n/subdir/index_p_de.properties, /path/to/root/i18n/subdir/index_p_en.properties etc. The complete distinction between script directories and properties files directories is done by design, so you can pass the files to-be-translated to someone else without including the scripts very easily.

I18N works with Java-style properties files. It supports locales with language or with language and country where languages and countries are abbrevated by there appropriate 2-char ISO codes, e.g. "de" means "German" where "de_DE" means "German/Germany". "de_AT" would be "German/Austria".

To define the available locales of a site, put a file "i18n.ini" into its root directory and define the locales line-by-line. First entry in each line is the locales description ("en", "de_CH", or "fr_CH"). It can be followed by any other locales acting as substitution for non-existing keys. Note however, that I18N loads the language-only locale as default substitution for each combined language-country locale, e.g. if you define "de AT", "de" will be chosen as substitution automatically. Substitues are queried in the defined order if a key's localisation cannot be found in the primary locale.

Example i18n.ini

de_DE
de_AT
en de

This means: The site is available in three locales: German/Germany, German/Austria, and English. For English, generic German is taken as substitute. Lets look at two lines of index.php:

Example index.php

$i18n→echolocalized("@month.jan");
$i18n→echolocalized("@month.feb");

The following three files do exist:

Example index p de.properties

month.jan=Januar
month.feb=Februar

Example index p de AT.properties

month.jan=Jänner

Example index p en.properties

month.jan=January

Combining all these inputs, the following output will emerge if different locales are set (e.g. through the $lang variable):

Output of index.php

Note that as there is no special file for "de_DE", I18N automatically falls back on the "de" file, while for the "de_AT" case, it takes the special notion Austrians are used to for January. February is taken from the "de" file for both, "de_DE" and "de_AT", and even for the "en" locale. The later one is due to "de" being explicitly defined as substitution locale for "en".

Usage examples

I18NEdit has been used to make the complete cantamen website multilingual.