The user can define the interface language of a web application.
This module allow to choose the language to display by using the user prefs proposed by its browser and the application's translations available.
The selected choice can also be stored in a cookie to overwrite the automatic process
// Language
$language = new Domframework\Language ();
// The application name is used to choose the
// locale/fr_FR.UTF8/LC_MESSAGES/application.po file.
// The second parameter is the cookie name.
$lang = $language->activeLanguage ("application", "application-Language");
// Define the default value if none can be automatically detected from the
// user preferences.
if ($lang === "C") $lang = "fr_FR";
Namespace Domframework
/** Language class : change the messages
/** Language cache directory
/** The complete stack of language selection@param string $package
The package name (package.(po|mo) files)@param string $languageCookie
The name of the cookie saved in the browser@param string $forcedLanguage
The name of a forced language@return
string The language with format fr_FR to be used
/** Start the Gettext support with the cached file .mo provided as parameter@param string $moFile
The .mo file@param string $languageCode
The language code to use@param integer $category
the LC_ type to use@param string|null $repLocale
The locale directory. Use "./locale" if not provided
/** This function manage the cache of $package.mo files as Apache cache them It return the directory to use@param string $languageCode
Language with format "fr_FR"@param string|null $package
The package name of the soft ($package.mo file). "messages" by default@param string|null $category
The folder name LC_MESSAGES by default@param string|null $repLocale
The folder where all the locales are stored
/** Return the language recorded in the Cookie. Check if this language is@param string $cookieName
The cookie name@param string|null $repLocale
The directory use to store the locale files allowed@return
string The language allowed or FALSE
/** Set the cookie with a TTL of one month@param string $cookieName
The name of the cookie@param string $languageCode
Language to store@param string $sitepath
The site path
/** Return the language name from the language Ex. : $languageCode=fr_FR, return France@param string $languageCode
Language with format "fr_FR"@return
string Then language name
/** Choose the best language in the browser list and which is available in locale path@param string|null $repLocale
Directory where are stored the translations@param string|null $languageCode
The coding langugage of the soft@return
string The choosed locale whithout charset (like fr_FR)
/**
Return the language subtag for the language
http://www.iana.org/assignments/language-subtag-registry/
language-subtag-registry
@param string $languageCode
The language code to convert
/**
Return an array with all the languages available in the $repLocale dir
The languages are in the format 'en_US' without the codeset.
@param string|null $repLocale
The directory use to store the locale files
Return FALSE if there is an error