I18n
in package
I18n and l10n class
Tags
Table of Contents
Properties
- $content : array<string|int, mixed>
- Language content, keyed by source string. Each value is either the translated output string, or an array of alternate outputs (keyed by their 'alt' name when named, otherwise numerically).
- $directory : string|null
- Directory with language files in it
- $language : string|null
- Default system language
- $locale : string
- Default system locale
Methods
- __() : string
- Return the translated string
- __construct() : mixed
- Constructor
- _e() : void
- Echo the translated string
- getLanguage() : string
- Get current language setting
- getLanguages() : array<string|int, mixed>
- Get languages from the language files in the directory
- getLocale() : string
- Get current locale setting
- loadFile() : void
- Load language content from an XML or JSON file
- getJsonLanguages() : array<string|int, mixed>
- Get language info from a single JSON language file
- getXmlLanguages() : array<string|int, mixed>
- Get language info from a single XML language file
- loadCurrentLanguage() : void
- Get language content from the current language/locale's file, if it exists
- loadJsonFile() : void
- Load language content from a JSON file into $content
- loadXmlFile() : void
- Load language content from an XML file into $content
- translate() : string
- Translate and return the string
Properties
$content
Language content, keyed by source string. Each value is either the translated output string, or an array of alternate outputs (keyed by their 'alt' name when named, otherwise numerically).
protected
array<string|int, mixed>
$content
= []
$directory
Directory with language files in it
protected
string|null
$directory
= null
$language
Default system language
protected
string|null
$language
= null
$locale
Default system locale
protected
string
$locale
= null
Methods
__()
Return the translated string
public
__(string $str[, string|array<string|int, mixed>|null $params = null ][, mixed $variation = null ]) : string
Parameters
- $str : string
- $params : string|array<string|int, mixed>|null = null
- $variation : mixed = null
Return values
string__construct()
Constructor
public
__construct([string|null $lang = null ][, string|null $dir = null ]) : mixed
Instantiate the I18n object
Parameters
- $lang : string|null = null
- $dir : string|null = null
_e()
Echo the translated string
public
_e(string $str[, string|array<string|int, mixed>|null $params = null ][, mixed $variation = null ]) : void
Parameters
- $str : string
- $params : string|array<string|int, mixed>|null = null
- $variation : mixed = null
getLanguage()
Get current language setting
public
getLanguage() : string
Return values
stringgetLanguages()
Get languages from the language files in the directory
public
static getLanguages(string $dir) : array<string|int, mixed>
Parameters
- $dir : string
Tags
Return values
array<string|int, mixed>getLocale()
Get current locale setting
public
getLocale() : string
Return values
stringloadFile()
Load language content from an XML or JSON file
public
loadFile(string $langFile) : void
Parameters
- $langFile : string
Tags
getJsonLanguages()
Get language info from a single JSON language file
protected
static getJsonLanguages(string $file) : array<string|int, mixed>
Parameters
- $file : string
Return values
array<string|int, mixed>getXmlLanguages()
Get language info from a single XML language file
protected
static getXmlLanguages(string $file) : array<string|int, mixed>
Parameters
- $file : string
Tags
Return values
array<string|int, mixed>loadCurrentLanguage()
Get language content from the current language/locale's file, if it exists
protected
loadCurrentLanguage() : void
Tags
loadJsonFile()
Load language content from a JSON file into $content
protected
loadJsonFile(string $langFile) : void
Parameters
- $langFile : string
loadXmlFile()
Load language content from an XML file into $content
protected
loadXmlFile(string $langFile) : void
Parameters
- $langFile : string
Tags
translate()
Translate and return the string
protected
translate(string $str[, string|array<string|int, mixed>|null $params = null ][, mixed $variation = null ]) : string
Parameters
- $str : string
- $params : string|array<string|int, mixed>|null = null
- $variation : mixed = null