FLP-i18n 2.1b2 review

Download
by rbytes.net on

i18n is a collection of PHP classes for managing multilanguage webpages

License: Free for non-commercial use
File size: 0K
Developer: flaimo
0 stars award from rbytes.net

i18n is a collection of PHP classes for managing multilanguage webpages. Translation strings can be stored in flat text files, precompiled gettext files or a mysql database.

The i18n package is a punch of classes for internationalization. It gives you the possibility to maintain multilanguage webpages more easily. The translation strings are stored in flat text files, special Gettext files which are basically precompiled translation files or in a MySQL database. And it works independently from PHP’s setlocale function.

First, to avoid problems, make sure that for all pages that use the package you start and end your scripts with:

ob_start();
session_start();

and

ob_end_flush();

Getting the language:

Let’s start with one of the base classes, the language class. It’s propose is to determinate the preferred locale of the user, by looking at the HTTP_ACCEPT_LANGUAGE header an the users IP address.

First create a new object:

include('class.Language.inc.php');
$lg = new Language();

Let’s say the user has set his browser to “German – Austria” (de-at). Now get your information with those methods:

$lg->getLocale() outputs de_at (the hyphen is replaced with an underscore)
$lg->getLang() outputs de
$lg->getCountry() outputs at

Of course some users have set more than one locale. To get those informations use:

$lg->getUserRawArray() to get an array with all locales accepted by the user
$lg->getUserLangArray() for all Languages
$lg->getUserCountryArray() for all countries

But what if the user has set no specific country code or no locale information could be found at all? That’s where the default values kick in. Stuff like this is saved in the i18n_settings.ini file:

[Language]
default_locale = "en"
default_language = "en"
default_country = "us"

To retrieve those settings in your script use

$lg->getDefaultLocale()
$lg->getDefaultLanguage()
$lg->getDefaultCountry()

But there are much more settings for the package you can change in the i18n_settings.ini file:

* The method for getting the translations (normal text files, Gettext files, MySQL),
* The extensions for the translation files
* The database connection settings
* If translation errors should be shown or not

You can also force a specific locale to overrule all other locale sources when you create a language object:

$lg_gb = new Language('en_gb');

FLP-i18n 2.1b2 keywords