I18n
in package
I18n
provides internationalization tools like translation, browser language detection, etc.
Table of Contents
Properties
- $_availableLanguages : array<string|int, mixed>
- available languages
- $_language : string
- language
- $_languageFallback : string
- language fallback
- $_languageLabels : array<string|int, mixed>
- language labels
- $_path : string
- path to language files
- $_translations : array<string|int, mixed>
- translation cache
Methods
- _() : string
- translate a string, alias for translate()
- encode() : string
- encode HTML entities for output into an HTML5 document
- getAvailableLanguages() : array<string|int, mixed>
- get list of available translations based on files found
- getBrowserLanguages() : array<string|int, mixed>
- detect the clients supported languages and return them ordered by preference
- getLanguage() : string
- get currently loaded language
- getLanguageLabels() : array<string|int, mixed>
- get list of language labels
- isRtl() : bool
- determines if the current language is written right-to-left (RTL)
- loadTranslations() : mixed
- loads translations
- setLanguageFallback() : mixed
- set the default language
- translate() : string
- translate a string
- _getMatchingLanguage() : string
- compares two language preference arrays and returns the preferred match
- _getPath() : string
- get language file path
- _getPluralForm() : int
- determines the plural form to use based on current language and given number
- _matchLanguage() : float
- compare two language IDs and return the degree they match
Properties
$_availableLanguages
available languages
protected
static array<string|int, mixed>
$_availableLanguages
= array()
Tags
$_language
language
protected
static string
$_language
= 'en'
Tags
$_languageFallback
language fallback
protected
static string
$_languageFallback
= 'en'
Tags
$_languageLabels
language labels
protected
static array<string|int, mixed>
$_languageLabels
= array()
Tags
$_path
path to language files
protected
static string
$_path
= ''
Tags
$_translations
translation cache
protected
static array<string|int, mixed>
$_translations
= array()
Tags
Methods
_()
translate a string, alias for translate()
public
static _(string|array<string|int, mixed> $messageId, mixed ...$args) : string
Parameters
- $messageId : string|array<string|int, mixed>
- $args : mixed
-
one or multiple parameters injected into placeholders
Tags
Return values
stringencode()
encode HTML entities for output into an HTML5 document
public
static encode(string $string) : string
Parameters
- $string : string
Tags
Return values
stringgetAvailableLanguages()
get list of available translations based on files found
public
static getAvailableLanguages() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>getBrowserLanguages()
detect the clients supported languages and return them ordered by preference
public
static getBrowserLanguages() : array<string|int, mixed>
From: https://stackoverflow.com/questions/3770513/detect-browser-language-in-php#3771447
Tags
Return values
array<string|int, mixed>getLanguage()
get currently loaded language
public
static getLanguage() : string
Tags
Return values
stringgetLanguageLabels()
get list of language labels
public
static getLanguageLabels([array<string|int, mixed> $languages = array() ]) : array<string|int, mixed>
Only for given language codes, otherwise all labels.
Parameters
- $languages : array<string|int, mixed> = array()
Tags
Return values
array<string|int, mixed>isRtl()
determines if the current language is written right-to-left (RTL)
public
static isRtl() : bool
Tags
Return values
boolloadTranslations()
loads translations
public
static loadTranslations() : mixed
From: https://stackoverflow.com/questions/3770513/detect-browser-language-in-php#3771447
Tags
setLanguageFallback()
set the default language
public
static setLanguageFallback(string $lang) : mixed
Parameters
- $lang : string
Tags
translate()
translate a string
public
static translate(string|array<string|int, mixed> $messageId, mixed ...$args) : string
Parameters
- $messageId : string|array<string|int, mixed>
- $args : mixed
-
one or multiple parameters injected into placeholders
Tags
Return values
string_getMatchingLanguage()
compares two language preference arrays and returns the preferred match
protected
static _getMatchingLanguage(array<string|int, mixed> $acceptedLanguages, array<string|int, mixed> $availableLanguages) : string
From: https://stackoverflow.com/questions/3770513/detect-browser-language-in-php#3771447
Parameters
- $acceptedLanguages : array<string|int, mixed>
- $availableLanguages : array<string|int, mixed>
Tags
Return values
string_getPath()
get language file path
protected
static _getPath([string $file = '' ]) : string
Parameters
- $file : string = ''
Tags
Return values
string_getPluralForm()
determines the plural form to use based on current language and given number
protected
static _getPluralForm(int $n) : int
From: https://docs.translatehouse.org/projects/localization-guide/en/latest/l10n/pluralforms.html
Parameters
- $n : int
Tags
Return values
int_matchLanguage()
compare two language IDs and return the degree they match
protected
static _matchLanguage(string $a, string $b) : float
From: https://stackoverflow.com/questions/3770513/detect-browser-language-in-php#3771447
Parameters
- $a : string
- $b : string