PHP Class Habari\Locale

Provides translation services.
Afficher le fichier Open project: habari/system Class Usage Examples

Méthodes publiques

Méthode Description
__run_loadfile_test ( $filename ) DO NOT USE THIS FUNCTION.
__run_plural_test ( $header ) DO NOT USE THIS FUNCTION.
_e ( ) Echo a version of the string translated into the current locale
_n ( string $singular, string $plural, string $count, string $domain = 'habari' ) : string Return a singular or plural string translated into the current locale based on the count provided
_ne ( string $singular, string $plural, string $count, string $domain = 'habari' ) Echo singular or plural version of the string, translated into the current locale, based on the count provided
_t ( string $text, array $args = [], string $domain = 'habari' ) : string Return a version of the string translated into the current locale
_u ( string $text, string $domain = 'habari' ) : string Given a string translated into the current locale, return the untranslated string.
get ( ) : string Return the current locale
get_messages ( string $domain = 'habari' ) : array Return the entire message catalog for a domain as an array
list_all ( ) : array. function list_all Retrieves an array of the Habari locales that are installed
load_pluggable_domain ( string $domain, string $base_dir ) : boolean Load translations for a given domain and base directory for a pluggable object.
set ( string $locale = null ) Sets the locale for Habari.
set_system_locale ( ) : string Set system locale.
translate_xml ( SimpleXMLElement $parent, SimpleXMLElement $child, string $ns = 'http://www.w3.org/XML/1998/namespace', null | string $locale = null ) Return a translated value of a SimpleXml object value based on the locale and namespace

Private Methods

Méthode Description
get_plural_function ( $header )
load_domain ( string $domain ) : boolean Load translations for a given domain.
load_file ( string $domain, string $file ) : boolean Load translations from a given file.

Method Details

__run_loadfile_test() public static méthode

This function is only to be used by the test case for the Locale class!
public static __run_loadfile_test ( $filename )

__run_plural_test() public static méthode

This function is only to be used by the test case for the Locale class!
public static __run_plural_test ( $header )

_e() public static méthode

Echo a version of the string translated into the current locale
public static _e ( )

_n() public static méthode

Return a singular or plural string translated into the current locale based on the count provided
public static _n ( string $singular, string $plural, string $count, string $domain = 'habari' ) : string
$singular string The singular form
$plural string The plural form
$count string The count
$domain string (optional) The domain to search for the message
Résultat string The appropriately translated string

_ne() public static méthode

Echo singular or plural version of the string, translated into the current locale, based on the count provided
public static _ne ( string $singular, string $plural, string $count, string $domain = 'habari' )
$singular string The singular form
$plural string The plural form
$count string The count
$domain string (optional) The domain to search for the message

_t() public static méthode

Return a version of the string translated into the current locale
public static _t ( string $text, array $args = [], string $domain = 'habari' ) : string
$text string The text to echo translated
$args array
$domain string (optional) The domain to search for the message
Résultat string The translated string

_u() public static méthode

Given a string translated into the current locale, return the untranslated string.
public static _u ( string $text, string $domain = 'habari' ) : string
$text string The translated string
$domain string (optional) The domain to search for the message
Résultat string The untranslated string

get() public static méthode

Return the current locale
public static get ( ) : string
Résultat string The current locale.

get_messages() public static méthode

Return the entire message catalog for a domain as an array
public static get_messages ( string $domain = 'habari' ) : array
$domain string (optional) The domain to return
Résultat array The array of locale messages

list_all() public static méthode

function list_all Retrieves an array of the Habari locales that are installed
public static list_all ( ) : array.
Résultat array.

load_pluggable_domain() public static méthode

Translations are stored in gettext-style .mo files. The internal workings of the file format are not entirely meant to be understood.
public static load_pluggable_domain ( string $domain, string $base_dir ) : boolean
$domain string the domain to load
$base_dir string the base directory in which to find the translation files
Résultat boolean true if data was successfully loaded, false otherwise

set() public static méthode

Sets the locale for Habari.
public static set ( string $locale = null )
$locale string A language code like 'en' or 'en-us' or 'x-klingon', will be lowercased

set_system_locale() public static méthode

The problem is that every platform has its own way to designate a locale, so for German you could have 'de', 'de_DE', 'de_DE.UTF-8', 'de_DE.UTF-8@euro' (Linux) or 'DEU' (Windows), etc.
public static set_system_locale ( ) : string
Résultat string the locale that was picked, or false if an error occurred

translate_xml() public static méthode

Return a translated value of a SimpleXml object value based on the locale and namespace
public static translate_xml ( SimpleXMLElement $parent, SimpleXMLElement $child, string $ns = 'http://www.w3.org/XML/1998/namespace', null | string $locale = null )
$parent SimpleXMLElement The parent node of the node we are translating
$child SimpleXMLElement The child node we're trying to translate
$ns string The namespace to use for the lang attribute of the node to be translated
$locale null | string The locale we want to translate into