PHP Class Habari\Locale

Provides translation services.
Show file Open project: habari/system Class Usage Examples

Public Methods

Method 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

Method 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 method

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 method

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

_e() public static method

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

_n() public static method

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
return string The appropriately translated string

_ne() public static method

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 method

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
return string The translated string

_u() public static method

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
return string The untranslated string

get() public static method

Return the current locale
public static get ( ) : string
return string The current locale.

get_messages() public static method

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
return array The array of locale messages

list_all() public static method

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

load_pluggable_domain() public static method

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
return boolean true if data was successfully loaded, false otherwise

set() public static method

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 method

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
return string the locale that was picked, or false if an error occurred

translate_xml() public static method

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