PHP Класс Elgg\I18n\Translator

С версии: 1.10.0
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
__construct ( ) Initializes new translator
addTranslation ( string $country_code, array $language_array ) : boolean Add a translation.
detectLanguage ( ) : string Detect the current system/user language or false.
getAllLanguageCodes ( ) : array Returns an array of language codes.
getCurrentLanguage ( ) : string Get the current system/user language or "en".
getInstalledTranslations ( ) : array Return an array of installed translations as an associative array "two letter code" => "native language name".
getLanguageCompleteness ( string $language ) : integer Return the level of completeness for a given language code (compared to english)
getMissingLanguageKeys ( string $language ) : mixed Return the translation keys missing from a given language, or those that are identical to the english version.
languageKeyExists ( string $key, string $language = 'en' ) : boolean Check if a given language key exists
loadTranslations ( string $language = null ) Load both core and plugin translations
normalizeLanguageCode ( string $code ) : string Normalize a language code (e.g. from Transifex)
registerPluginTranslations ( string $path ) : boolean Registers translations in a directory assuming the standard plugin layout.
registerTranslations ( string $path, boolean $load_all = false, string $language = null ) : boolean When given a full path, finds translation files and loads them
reloadAllTranslations ( ) : void Reload all translations from all registered paths.
translate ( string $message_key, array $args = [], string $language = "" ) : string Given a message key, returns an appropriately translated full-text string

Приватные методы

Метод Описание
ensureTranslationsLoaded ( string $language ) : void Make sure translations are loaded
loadPluginTranslations ( string $language ) : void Load plugin translations for a language

Описание методов

__construct() публичный Метод

Initializes new translator
public __construct ( )

addTranslation() публичный Метод

Translations are arrays in the Zend Translation array format, eg: $english = array('message1' => 'message1', 'message2' => 'message2'); $german = array('message1' => 'Nachricht1','message2' => 'Nachricht2');
public addTranslation ( string $country_code, array $language_array ) : boolean
$country_code string Standard country code (eg 'en', 'nl', 'es')
$language_array array Formatted array of strings
Результат boolean Depending on success

detectLanguage() публичный Метод

Detect the current system/user language or false.
public detectLanguage ( ) : string
Результат string The language code (eg "en") or false if not set

getAllLanguageCodes() публичный статический Метод

Returns an array of language codes.
public static getAllLanguageCodes ( ) : array
Результат array

getCurrentLanguage() публичный Метод

Get the current system/user language or "en".
public getCurrentLanguage ( ) : string
Результат string The language code for the site/user or "en" if not set

getInstalledTranslations() публичный Метод

Return an array of installed translations as an associative array "two letter code" => "native language name".
public getInstalledTranslations ( ) : array
Результат array

getLanguageCompleteness() публичный Метод

Return the level of completeness for a given language code (compared to english)
public getLanguageCompleteness ( string $language ) : integer
$language string Language
Результат integer

getMissingLanguageKeys() публичный Метод

Return the translation keys missing from a given language, or those that are identical to the english version.
public getMissingLanguageKeys ( string $language ) : mixed
$language string The language
Результат mixed

languageKeyExists() публичный Метод

Check if a given language key exists
С версии: 1.11
public languageKeyExists ( string $key, string $language = 'en' ) : boolean
$key string The translation key
$language string The specific language to check
Результат boolean

loadTranslations() публичный Метод

By default this loads only English and the language of the logged in user. The optional $language argument can be used to load translations on-demand in case we need to translate something to a language not loaded by default for the current request.
public loadTranslations ( string $language = null )
$language string Language code

normalizeLanguageCode() публичный статический Метод

Normalize a language code (e.g. from Transifex)
public static normalizeLanguageCode ( string $code ) : string
$code string Language code
Результат string

registerPluginTranslations() публичный Метод

Registers translations in a directory assuming the standard plugin layout.
public registerPluginTranslations ( string $path ) : boolean
$path string Without the trailing slash.
Результат boolean Success

registerTranslations() публичный Метод

When given a full path, finds translation files and loads them
public registerTranslations ( string $path, boolean $load_all = false, string $language = null ) : boolean
$path string Full path
$load_all boolean If true all languages are loaded, if false only the current language + en are loaded
$language string Language code
Результат boolean success

reloadAllTranslations() публичный Метод

This is only called by functions which need to know all possible translations.
public reloadAllTranslations ( ) : void
Результат void

translate() публичный Метод

Given a message key, returns an appropriately translated full-text string
public translate ( string $message_key, array $args = [], string $language = "" ) : string
$message_key string The short message code
$args array An array of arguments to pass through vsprintf().
$language string Optionally, the standard language code (defaults to site/user default, then English)
Результат string Either the translated string, the English string, or the original language string.