Elgg  Version 3.0
Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
Elgg\I18n\Translator Class Reference

Translator. More...

Inheritance diagram for Elgg\I18n\Translator:
Elgg\I18n\NullTranslator

Public Member Functions

 __construct (Config $config, LocaleService $localService)
 Constructor. More...
 
 getLoadedTranslations ()
 Get a map of all loaded translations. More...
 
 translate ($message_key, array $args=[], $language="")
 Given a message key, returns an appropriately translated full-text string. More...
 
 addTranslation ($country_code, $language_array, $ensure_translations_loaded=true)
 Add a translation. More...
 
 getCurrentLanguage ()
 Get the current system/user language or "en". More...
 
 setCurrentLanguage ($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 ($language)
 Load both core and plugin translations. More...
 
 registerTranslations ($path, $load_all=false, $language=null)
 When given a full path, finds translation files and loads them. More...
 
 reloadAllTranslations ()
 Reload all translations from all registered paths. More...
 
 getInstalledTranslations ($calculate_completeness=false)
 Return an array of installed translations as an associative array "two letter code" => "native language name". More...
 
 getLanguageCompleteness ($language)
 Return the level of completeness for a given language code (compared to english) More...
 
 getMissingLanguageKeys ($language)
 Return the translation keys missing from a given language, or those that are identical to the english version. More...
 
 languageKeyExists ($key, $language= 'en')
 Check if a given language key exists. More...
 
 getAvailableLanguages ()
 Returns an array of all available language keys. More...
 
 registerLanguagePath ($path)
 Registers a path for potential translation files. More...
 

Static Public Member Functions

static getAllLanguageCodes ()
 Returns an array of language codes. More...
 
static normalizeLanguageCode ($code)
 Normalize a language code (e.g. More...
 

Protected Member Functions

 includeLanguageFile ($path)
 Load cached or include a language file by its path. More...
 
 getLanguagePaths ()
 Returns a unique array with locations of translation files. More...
 

Detailed Description

Translator.

Use elgg()->translator

Since
1.10.0

Definition at line 15 of file Translator.php.

Constructor & Destructor Documentation

Elgg\I18n\Translator::__construct ( Config  $config,
LocaleService  $localService 
)

Constructor.

Parameters
Config$configElgg config
LocaleService$localServicelocale service

Definition at line 69 of file Translator.php.

Member Function Documentation

Elgg\I18n\Translator::addTranslation (   $country_code,
  $language_array,
  $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');

Parameters
string$country_codeStandard country code (eg 'en', 'nl', 'es')
array$language_arrayFormatted array of strings
bool$ensure_translations_loadedEnsures translations are loaded before adding the language array (default: true)
Returns
bool Depending on success

Definition at line 177 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.

Returns
void

Definition at line 266 of file Translator.php.

Elgg\I18n\Translator::detectLanguage ( )

Detect the current system/user language or false.

Returns
false|string The language code (eg "en") or false if not set

Definition at line 235 of file Translator.php.

static Elgg\I18n\Translator::getAllLanguageCodes ( )
static

Returns an array of language codes.

Returns
array

Definition at line 622 of file Translator.php.

Elgg\I18n\Translator::getAvailableLanguages ( )

Returns an array of all available language keys.

Triggers a hook to allow plugins to add/remove languages

Returns
array
Since
3.0

Definition at line 541 of file Translator.php.

Elgg\I18n\Translator::getCurrentLanguage ( )

Get the current system/user language or "en".

Returns
string The language code for the site/user or "en" if not set

Definition at line 205 of file Translator.php.

Elgg\I18n\Translator::getInstalledTranslations (   $calculate_completeness = false)

Return an array of installed translations as an associative array "two letter code" => "native language name".

Parameters
boolean$calculate_completenessSet to true if you want a completeness postfix added to the language text
Returns
array

Definition at line 422 of file Translator.php.

Elgg\I18n\Translator::getLanguageCompleteness (   $language)

Return the level of completeness for a given language code (compared to english)

Parameters
string$languageLanguage
Returns
float

Definition at line 458 of file Translator.php.

Elgg\I18n\Translator::getLanguagePaths ( )
protected

Returns a unique array with locations of translation files.

Returns
array

Definition at line 594 of file Translator.php.

Elgg\I18n\Translator::getLoadedTranslations ( )

Get a map of all loaded translations.

Returns
array

Definition at line 83 of file Translator.php.

Elgg\I18n\Translator::getMissingLanguageKeys (   $language)

Return the translation keys missing from a given language, or those that are identical to the english version.

Parameters
string$languageThe language
Returns
mixed

Definition at line 491 of file Translator.php.

Elgg\I18n\Translator::includeLanguageFile (   $path)
protected

Load cached or include a language file by its path.

Parameters
string$pathPath to file
Returns
bool

Definition at line 376 of file Translator.php.

Elgg\I18n\Translator::languageKeyExists (   $key,
  $language = 'en' 
)

Check if a given language key exists.

Parameters
string$keyThe translation key
string$languageThe specific language to check
Returns
bool
Since
1.11

Definition at line 521 of file Translator.php.

Elgg\I18n\Translator::loadTranslations (   $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.

Parameters
string$languageLanguage code
Returns
void

Definition at line 287 of file Translator.php.

static Elgg\I18n\Translator::normalizeLanguageCode (   $code)
static

Normalize a language code (e.g.

from Transifex)

Parameters
string$codeLanguage code
Returns
string

Definition at line 636 of file Translator.php.

Elgg\I18n\Translator::registerLanguagePath (   $path)

Registers a path for potential translation files.

Parameters
string$pathpath to a folder that contains translation files
Returns
void

Definition at line 585 of file Translator.php.

Elgg\I18n\Translator::registerTranslations (   $path,
  $load_all = false,
  $language = null 
)

When given a full path, finds translation files and loads them.

Parameters
string$pathFull path
bool$load_allIf true all languages are loaded, if false only the current language + en are loaded
string$languageLanguage code
Returns
bool success

Definition at line 318 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.

Returns
void

Definition at line 398 of file Translator.php.

Elgg\I18n\Translator::setCurrentLanguage (   $language = null)

Sets current system language.

Parameters
string$languageLanguage code
Returns
void

Definition at line 224 of file Translator.php.

Elgg\I18n\Translator::translate (   $message_key,
array  $args = [],
  $language = "" 
)

Given a message key, returns an appropriately translated full-text string.

Parameters
string$message_keyThe short message code
array$argsAn array of arguments to pass through vsprintf().
string$languageOptionally, the standard language code (defaults to site/user default, then English)
Returns
string Either the translated string, the English string, or the original language string.

Definition at line 98 of file Translator.php.


The documentation for this class was generated from the following file: