Documentation

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
access

protected

static

$_language

language

protected static string $_language = 'en'
Tags
access

protected

static

$_languageFallback

language fallback

protected static string $_languageFallback = 'en'
Tags
access

protected

static

$_languageLabels

language labels

protected static array<string|int, mixed> $_languageLabels = array()
Tags
access

protected

static

$_path

path to language files

protected static string $_path = ''
Tags
access

protected

static

$_translations

translation cache

protected static array<string|int, mixed> $_translations = array()
Tags
access

protected

static

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
access

public

static
Return values
string

encode()

encode HTML entities for output into an HTML5 document

public static encode(string $string) : string
Parameters
$string : string
Tags
access

public

static
Return values
string

getAvailableLanguages()

get list of available translations based on files found

public static getAvailableLanguages() : array<string|int, mixed>
Tags
access

public

static
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
access

public

static
Return values
array<string|int, mixed>

getLanguage()

get currently loaded language

public static getLanguage() : string
Tags
access

public

static
Return values
string

getLanguageLabels()

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
access

public

static
Return values
array<string|int, mixed>

isRtl()

determines if the current language is written right-to-left (RTL)

public static isRtl() : bool
Tags
access

public

static
Return values
bool

loadTranslations()

loads translations

public static loadTranslations() : mixed

From: https://stackoverflow.com/questions/3770513/detect-browser-language-in-php#3771447

Tags
access

public

static

setLanguageFallback()

set the default language

public static setLanguageFallback(string $lang) : mixed
Parameters
$lang : string
Tags
access

public

static

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
access

public

static
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
access

protected

static
Return values
string

_getPath()

get language file path

protected static _getPath([string $file = '' ]) : string
Parameters
$file : string = ''
Tags
access

protected

static
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
access

protected

static
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
Tags
access

protected

static
Return values
float

        
On this page

Search results