Elgg
Version master
|
Public Member Functions | |
__construct (protected Config $config, protected LocaleService $locale) | |
Constructor. More... | |
getLoadedTranslations () | |
Get a map of all loaded translations. More... | |
translate (string $message_key, array $args=[], string $language= '') | |
Given a message key, returns an appropriately translated full-text string. More... | |
addTranslation (string $country_code, array $language_array, bool $ensure_translations_loaded=true) | |
Add a translation. More... | |
getCurrentLanguage () | |
Get the current system/user language or 'en'. More... | |
setCurrentLanguage (string $language=null) | |
Sets current system language. More... | |
detectLanguage () | |
Detect the current system/user language or false. More... | |
bootTranslations () | |
Ensures all needed translations are loaded. More... | |
loadTranslations (string $language) | |
Load both core and plugin translations. More... | |
registerTranslations (string $path, bool $load_all=false, string $language=null) | |
When given a full path, finds translation files and loads them. More... | |
reloadAllTranslations () | |
Reload all translations from all registered paths. More... | |
getInstalledTranslations (bool $calculate_completeness=false) | |
Return an array of installed translations as an associative array "two letter code" => "native language name". More... | |
getLanguageCompleteness (string $language) | |
Return the level of completeness for a given language code (compared to english) More... | |
getMissingLanguageKeys (string $language) | |
Return the translation keys missing from a given language, or those that are identical to the english version. More... | |
languageKeyExists (string $key, string $language= 'en') | |
Check if a given language key exists. More... | |
getAvailableLanguages () | |
Returns an array of all available language keys. More... | |
getAllowedLanguages () | |
Returns an array of allowed languages as configured by the site admin. More... | |
registerLanguagePath (string $path) | |
Registers a path for potential translation files. More... | |
getLanguagePaths () | |
Returns a unique array with locations of translation files. More... | |
Protected Member Functions | |
includeLanguageFile (string $path) | |
Load cached or include a language file by its path. More... | |
ensureTranslationsLoaded (string $language) | |
Make sure translations are loaded. More... | |
Protected Attributes | |
array | $translations = [] |
string | $defaultPath |
string | $current_language = null |
array | $allowed_languages |
array | $language_paths = [] |
bool | $was_reloaded = false |
Elgg\I18n\Translator::__construct | ( | protected Config | $config, |
protected LocaleService | $locale | ||
) |
Constructor.
Config | $config | Elgg config |
LocaleService | $locale | locale service |
Definition at line 52 of file Translator.php.
Elgg\I18n\Translator::addTranslation | ( | string | $country_code, |
array | $language_array, | ||
bool | $ensure_translations_loaded = true |
||
) |
Add a translation.
Translations are arrays in the Zend Translation array format, eg:
$english = array('message1' => 'message1', 'message2' => 'message2'); $german = array('message1' => 'Nachricht1','message2' => 'Nachricht2');
string | $country_code | Standard country code (eg 'en', 'nl', 'es') |
array | $language_array | Formatted array of strings |
bool | $ensure_translations_loaded | Ensures translations are loaded before adding the language array (default: true) |
Definition at line 162 of file Translator.php.
Elgg\I18n\Translator::bootTranslations | ( | ) |
Ensures all needed translations are loaded.
This loads only English and the language of the logged in user.
Definition at line 269 of file Translator.php.
Elgg\I18n\Translator::detectLanguage | ( | ) |
Detect the current system/user language or false.
Definition at line 219 of file Translator.php.
|
protected |
Make sure translations are loaded.
string | $language | Language |
Definition at line 636 of file Translator.php.
Elgg\I18n\Translator::getAllowedLanguages | ( | ) |
Returns an array of allowed languages as configured by the site admin.
Definition at line 569 of file Translator.php.
Elgg\I18n\Translator::getAvailableLanguages | ( | ) |
Returns an array of all available language keys.
Triggers an event to allow plugins to add/remove languages
Definition at line 530 of file Translator.php.
Elgg\I18n\Translator::getCurrentLanguage | ( | ) |
Get the current system/user language or 'en'.
Definition at line 189 of file Translator.php.
Elgg\I18n\Translator::getInstalledTranslations | ( | bool | $calculate_completeness = false | ) |
Return an array of installed translations as an associative array "two letter code" => "native language name".
boolean | $calculate_completeness | Set to true if you want a completeness postfix added to the language text |
Definition at line 423 of file Translator.php.
Elgg\I18n\Translator::getLanguageCompleteness | ( | string | $language | ) |
Return the level of completeness for a given language code (compared to english)
string | $language | Language |
Definition at line 459 of file Translator.php.
Elgg\I18n\Translator::getLanguagePaths | ( | ) |
Returns a unique array with locations of translation files.
Definition at line 625 of file Translator.php.
Elgg\I18n\Translator::getLoadedTranslations | ( | ) |
Elgg\I18n\Translator::getMissingLanguageKeys | ( | string | $language | ) |
Return the translation keys missing from a given language, or those that are identical to the english version.
string | $language | The language |
Definition at line 486 of file Translator.php.
|
protected |
Load cached or include a language file by its path.
string | $path | Path to file |
Definition at line 377 of file Translator.php.
Elgg\I18n\Translator::languageKeyExists | ( | string | $key, |
string | $language = 'en' |
||
) |
Check if a given language key exists.
string | $key | The translation key |
string | $language | The specific language to check |
Definition at line 510 of file Translator.php.
Elgg\I18n\Translator::loadTranslations | ( | string | $language | ) |
Load both core and plugin translations.
The $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.
string | $language | Language code |
Definition at line 290 of file Translator.php.
Elgg\I18n\Translator::registerLanguagePath | ( | string | $path | ) |
Registers a path for potential translation files.
string | $path | path to a folder that contains translation files |
Definition at line 606 of file Translator.php.
Elgg\I18n\Translator::registerTranslations | ( | string | $path, |
bool | $load_all = false , |
||
string | $language = null |
||
) |
When given a full path, finds translation files and loads them.
string | $path | Full path |
bool | $load_all | If true all languages are loaded, if false only the current language + en are loaded |
string | $language | Language code |
Definition at line 317 of file Translator.php.
Elgg\I18n\Translator::reloadAllTranslations | ( | ) |
Reload all translations from all registered paths.
This is only called by functions which need to know all possible translations.
Definition at line 399 of file Translator.php.
Elgg\I18n\Translator::setCurrentLanguage | ( | string | $language = null | ) |
Sets current system language.
string | $language | Language code |
Definition at line 208 of file Translator.php.
Elgg\I18n\Translator::translate | ( | string | $message_key, |
array | $args = [] , |
||
string | $language = '' |
||
) |
Given a message key, returns an appropriately translated full-text string.
string | $message_key | The short message code |
array | $args | An array of arguments to pass through vsprintf(). |
string | $language | Optionally, the standard language code (defaults to site/user default, then English) |
Definition at line 77 of file Translator.php.
|
protected |
Definition at line 26 of file Translator.php.
|
protected |
Definition at line 24 of file Translator.php.
|
protected |
Definition at line 22 of file Translator.php.
|
protected |
Definition at line 42 of file Translator.php.
|
protected |
Definition at line 20 of file Translator.php.
|
protected |
Definition at line 44 of file Translator.php.