PHP Class PrivateBin\I18n

provides internationalization tools like translation, browser language detection, etc.
ファイルを表示 Open project: privatebin/privatebin Class Usage Examples

Protected Properties

Property Type Description
$_availableLanguages array available languages
$_language string language
$_languageFallback string language fallback
$_languageLabels array language labels
$_path string path to language files
$_translations array translation cache

Public Methods

Method Description
_ ( string $messageId ) : string translate a string, alias for translate()
getAvailableLanguages ( ) : array get list of available translations based on files found
getBrowserLanguages ( ) : array detect the clients supported languages and return them ordered by preference
getLanguage ( ) : string get currently loaded language
getLanguageLabels ( array $languages = [] ) : array get list of language labels
loadTranslations ( ) : void loads translations
setLanguageFallback ( string $lang ) : void set the default language
translate ( string $messageId ) : string translate a string

Protected Methods

Method Description
_getMatchingLanguage ( array $acceptedLanguages, array $availableLanguages ) : string compares two language preference arrays and returns the preferred match
_getPath ( string $file = '' ) : string get language file path
_getPluralForm ( integer $n ) : integer determines the plural form to use based on current language and given number
_matchLanguage ( string $a, string $b ) : float compare two language IDs and return the degree they match

Method Details

_() public static method

translate a string, alias for translate()
public static _ ( string $messageId ) : string
$messageId string
return string

_getMatchingLanguage() protected static method

From: https://stackoverflow.com/questions/3770513/detect-browser-language-in-php#3771447
protected static _getMatchingLanguage ( array $acceptedLanguages, array $availableLanguages ) : string
$acceptedLanguages array
$availableLanguages array
return string

_getPath() protected static method

get language file path
protected static _getPath ( string $file = '' ) : string
$file string
return string

_getPluralForm() protected static method

From: http://localization-guide.readthedocs.org/en/latest/l10n/pluralforms.html
protected static _getPluralForm ( integer $n ) : integer
$n integer
return integer

_matchLanguage() protected static method

From: https://stackoverflow.com/questions/3770513/detect-browser-language-in-php#3771447
protected static _matchLanguage ( string $a, string $b ) : float
$a string
$b string
return float

getAvailableLanguages() public static method

get list of available translations based on files found
public static getAvailableLanguages ( ) : array
return array

getBrowserLanguages() public static method

From: https://stackoverflow.com/questions/3770513/detect-browser-language-in-php#3771447
public static getBrowserLanguages ( ) : array
return array

getLanguage() public static method

get currently loaded language
public static getLanguage ( ) : string
return string

getLanguageLabels() public static method

Only for given language codes, otherwise all labels.
public static getLanguageLabels ( array $languages = [] ) : array
$languages array
return array

loadTranslations() public static method

From: https://stackoverflow.com/questions/3770513/detect-browser-language-in-php#3771447
public static loadTranslations ( ) : void
return void

setLanguageFallback() public static method

set the default language
public static setLanguageFallback ( string $lang ) : void
$lang string
return void

translate() public static method

translate a string
public static translate ( string $messageId ) : string
$messageId string
return string

Property Details

$_availableLanguages protected_oe static_oe property

available languages
protected static array $_availableLanguages
return array

$_language protected_oe static_oe property

language
protected static string $_language
return string

$_languageFallback protected_oe static_oe property

language fallback
protected static string $_languageFallback
return string

$_languageLabels protected_oe static_oe property

language labels
protected static array $_languageLabels
return array

$_path protected_oe static_oe property

path to language files
protected static string $_path
return string

$_translations protected_oe static_oe property

translation cache
protected static array $_translations
return array