Elgg  Version master
Public Member Functions | Protected Member Functions | Protected Attributes | 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 $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 ($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 (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 ($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

 $allowed_languages = null
 

Detailed Description

Translator.

Use elgg()->translator

Since
1.10.0

Definition at line 16 of file Translator.php.

Constructor & Destructor Documentation

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

Constructor.

Parameters
Config$configElgg config
LocaleService$localelocale service

Definition at line 77 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 193 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 305 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 251 of file Translator.php.

Elgg\I18n\Translator::ensureTranslationsLoaded ( string  $language)
protected

Make sure translations are loaded.

Parameters
string$languageLanguage
Returns
void

Definition at line 684 of file Translator.php.

Elgg\I18n\Translator::getAllowedLanguages ( )

Returns an array of allowed languages as configured by the site admin.

Returns
string[]
Since
3.3

Definition at line 618 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 577 of file Translator.php.

Elgg\I18n\Translator::getCurrentLanguage ( )

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

Returns
string

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

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

Definition at line 458 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 494 of file Translator.php.

Elgg\I18n\Translator::getLanguagePaths ( )

Returns a unique array with locations of translation files.

Returns
array

Definition at line 673 of file Translator.php.

Elgg\I18n\Translator::getLoadedTranslations ( )

Get a map of all loaded translations.

Returns
array

Definition at line 91 of file Translator.php.

Elgg\I18n\Translator::getMissingLanguageKeys ( string  $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 527 of file Translator.php.

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

Load cached or include a language file by its path.

Parameters
string$pathPath to file
Returns
bool

Definition at line 412 of file Translator.php.

Elgg\I18n\Translator::languageKeyExists ( string  $key,
string  $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 557 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.

Parameters
string$languageLanguage code
Returns
void

Definition at line 326 of file Translator.php.

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

Registers a path for potential translation files.

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

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

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 354 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 434 of file Translator.php.

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

Sets current system language.

Parameters
string$languageLanguage code
Returns
void

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

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 105 of file Translator.php.

Member Data Documentation

Elgg\I18n\Translator::$allowed_languages = null
protected

Definition at line 48 of file Translator.php.


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