PHP 클래스 Elgg\I18n\Translator

부터: 1.10.0
파일 보기 프로젝트 열기: elgg/elgg 1 사용 예제들

공개 메소드들

메소드 설명
__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.