Interface: ILanguageManager

Interface for localization support.

Extends

Known implementations

Authors

Oleg Schildt

Package

Source code

 

Methods
public

Adds additional localization files to the dictionary.

public

This function should detect the current language based on cookies, browser languages etc.

public

Adds additional translations to the dictionary.

public

Returns the current context.

public

Tries to find the country code by the given name.

public

Provides the list of countries for the given language in the form "code" => "translation".

public

Provides the text translation for the country name by the code for the given language.

public

Returns the current language.

public

Returns the fallback language. If set and a translation is missing on a language, the translation on this language will be used.

public

Tries to find the language code by the given name.

public

Provides the list of languages for the given language in the form "code" => "translation".

public

Provides the text translation for the language name by the code for the given language.

public

Returns the list of supported languages.

public

Checks whether the text translation for the text ID for the given language exists.

public

Initializes the language manager with parameters.

public

This is function for loading the translations from the source JSON file.

public

Sets the current context.

public

Sets the current language.

public

Provides the text translation for the text ID for the given language.

public

Provides the text translation for the text ID for the given language if the translation exists.

public

Checks whether the country code is valid (has translation).

public

Checks whether the language code is valid (has translation).


Method: ILanguageManager::addLocalizationFile()

public function addLocalizationFile(string $localization_file): void;

Adds additional localization files to the dictionary.

Parameters

Name Pass type Value type Default value Description
$localization_file by value string

The path of the additional localization file.

Returns

void

Throws

\Exception

It might throw an exception in the case of any errors.

Authors

Oleg Schildt

Source code


Method: ILanguageManager::detectLanguage()

public function detectLanguage(): void;

This function should detect the current language based on cookies, browser languages etc.

Details

Some applications may consist of two parts - administration console and public site. A usual example is a CMS system.

For example, you are using administration console in English and editing the public site for German and French. When you open the public site for preview in German or French, you want it to be open in the corresponding language, but the administration console should remain in English.

With the help of $context, you are able to maintain different languages for different parts of your application. If you do not need the $context, just do not specify it.

Returns

void

Authors

Oleg Schildt

Source code


Method: ILanguageManager::extendDictionary()

public function extendDictionary(array $dictionary): void;

Adds additional translations to the dictionary.

Parameters

Name Pass type Value type Default value Description
$dictionary by value array

The array with additional translations.

Returns

void

Throws

\Exception

It might throw an exception in the case of any errors.

Authors

Oleg Schildt

Source code


Method: ILanguageManager::getContext()

public function getContext(): string;

Returns the current context.

Details

Some applications may consist of two parts - administration console and public site. A usual example is a CMS system.

For example, you are using administration console in English and editing the public site for German and French. When you open the public site for preview in German or French, you want it to be open in the corresponding language, but the administration console should remain in English.

With the help of $context, you are able to maintain different languages for different parts of your application. If you do not need the $context, just do not specify it.

Returns

string

Returns the current context.

Authors

Oleg Schildt

Source code


Method: ILanguageManager::getCountryCode()

public function getCountryCode(string $country_name): string;

Tries to find the country code by the given name.

Parameters

Name Pass type Value type Default value Description
$country_name by value string

The name of the country in any supported language.

Returns

string

Returns the country code if it could be found, otherwise an empty string.

Authors

Oleg Schildt

Source code

See also


Method: ILanguageManager::getCountryList()

public function getCountryList(array &$country_list, string $lng = "", array $display_first = []): bool;

Provides the list of countries for the given language in the form "code" => "translation".

Parameters

Name Pass type Value type Default value Description
$country_list by reference array

Target array where the country list should be loaded.

$lng by value string ""

The language. If it is not specified, the default language is used.

$display_first by value array []

List of the country codes to be displayed first in the order, they appear in the list.

Returns

bool

Returns true if the country list is successfully retrieved, otherwise false.

Authors

Oleg Schildt

Source code

See also


Method: ILanguageManager::getCountryName()

public function getCountryName(string $code, string $lng = ""): string;

Provides the text translation for the country name by the code for the given language.

Parameters

Name Pass type Value type Default value Description
$code by value string

Country ISO code (uppercase, e.g. US, DE, FR).

$lng by value string ""

The language. If it is not specified, the default language is used.

Returns

string

Returns the translation text for the country name or the $code if no translation is found.

Authors

Oleg Schildt

Source code

See also


Method: ILanguageManager::getCurrentLanguage()

public function getCurrentLanguage(): string;

Returns the current language.

Returns

string

Returns the current language ISO code.

Authors

Oleg Schildt

Source code

See also


Method: ILanguageManager::getFallbackLanguage()

public function getFallbackLanguage(): string;

Returns the fallback language. If set and a translation is missing on a language, the translation on this language will be used.

Returns

string

Returns the fallback language.

Authors

Oleg Schildt

Source code


Method: ILanguageManager::getLanguageCode()

public function getLanguageCode(string $lang_name): string;

Tries to find the language code by the given name.

Parameters

Name Pass type Value type Default value Description
$lang_name by value string

The name of the language in any supported language.

Returns

string

Returns the language code if it could be found, otherwise an empty string.

Authors

Oleg Schildt

Source code

See also


Method: ILanguageManager::getLanguageList()

public function getLanguageList(array &$language_list, string $lng = "", array $display_first = []): bool;

Provides the list of languages for the given language in the form "code" => "translation".

Parameters

Name Pass type Value type Default value Description
$language_list by reference array

Target array where the language list should be loaded.

$lng by value string ""

The language. If it is not specified, the default language is used.

$display_first by value array []

List of the language codes to be displayed first in the order, they appear in the list.

Returns

bool

Returns true if the language list is successfully retrieved, otherwise false.

Authors

Oleg Schildt

Source code

See also


Method: ILanguageManager::getLanguageName()

public function getLanguageName(string $code, string $lng = ""): string;

Provides the text translation for the language name by the code for the given language.

Parameters

Name Pass type Value type Default value Description
$code by value string

Language ISO code (lowercase, e.g. en, de, fr).

$lng by value string ""

The language. If it is not specified, the default language is used.

Returns

string

Returns the translation text for the language name or the $code if no translation is found.

Authors

Oleg Schildt

Source code

See also


Method: ILanguageManager::getSupportedLanguages()

public function getSupportedLanguages(): array;

Returns the list of supported languages.

Returns

array

Returns the list of supported languages.

Authors

Oleg Schildt

Source code


Method: ILanguageManager::hasTranslation()

public function hasTranslation(string $text_id, string $lng = ""): bool;

Checks whether the text translation for the text ID for the given language exists.

Parameters

Name Pass type Value type Default value Description
$text_id by value string

Text ID

$lng by value string ""

The language. If it is not specified, the default language is used.

Returns

bool

Returns true if the translation exists, otherwise false.

Authors

Oleg Schildt

Source code


Method: ILanguageManager::init()

public function init(array $parameters): void;

Initializes the language manager with parameters.

Parameters

Name Pass type Value type Default value Description
$parameters by value array

The parameters may vary for each language manager.

Returns

void

Throws

\Exception

It might throw an exception in the case of any system errors.

Overrides

Authors

Oleg Schildt

Source code


Method: ILanguageManager::loadDictionary()

public function loadDictionary(): void;

This is function for loading the translations from the source JSON file.

Returns

void

Throws

\Exception

It might throw the following exceptions in the case of any errors:

  • if the translation file is invalid.

Authors

Oleg Schildt

Source code


Method: ILanguageManager::setContext()

public function setContext(string $context): void;

Sets the current context.

Details

Some applications may consist of two parts - administration console and public site. A usual example is a CMS system.

For example, you are using administration console in English and editing the public site for German and French. When you open the public site for preview in German or French, you want it to be open in the corresponding language, but the administration console should remain in English.

With the help of $context, you are able to maintain different languages for different parts of your application. If you do not need the $context, just do not specify it.

Parameters

Name Pass type Value type Default value Description
$context by value string

The name of the context.

Returns

void

Authors

Oleg Schildt

Source code

See also


Method: ILanguageManager::setCurrentLanguage()

public function setCurrentLanguage(string $language): void;

Sets the current language.

Parameters

Name Pass type Value type Default value Description
$language by value string

The language ISO code to be set.

Returns

void

Authors

Oleg Schildt

Source code

See also


Method: ILanguageManager::text()

public function text(string $text_id, string $lng = "", string $default_text = ""): string;

Provides the text translation for the text ID for the given language.

Parameters

Name Pass type Value type Default value Description
$text_id by value string

Text ID

$lng by value string ""

The language. If it is not specified, the default language is used.

$default_text by value string ""

The default text to be used if there is no translation.

Returns

string

Returns the translation text or the $default_text/$text_id if no translation is found.

Authors

Oleg Schildt

Source code


Method: ILanguageManager::try_text()

public function try_text(string $text_id, string $lng = ""): string;

Provides the text translation for the text ID for the given language if the translation exists.

Details

Otherwise, it returns the text ID and emits no warning.

Parameters

Name Pass type Value type Default value Description
$text_id by value string

Text ID

$lng by value string ""

The language. If it is not specified, the default language is used.

Returns

string

Returns the translation text or the $default_text/$text_id if no translation is found.

Authors

Oleg Schildt

Source code


Method: ILanguageManager::validateCountryCode()

public function validateCountryCode(string $code, string $lng = ""): bool;

Checks whether the country code is valid (has translation).

Parameters

Name Pass type Value type Default value Description
$code by value string

Country ISO code (uppercase, e.g. US, DE, FR).

$lng by value string ""

The language. If it is not specified, the default language is used.

Returns

bool

Returns true if the country code is valid (has translation), otherwise false.

Authors

Oleg Schildt

Source code

See also


Method: ILanguageManager::validateLanguageCode()

public function validateLanguageCode(string $code, string $lng = ""): bool;

Checks whether the language code is valid (has translation).

Parameters

Name Pass type Value type Default value Description
$code by value string

Language ISO code (lowercase, e.g. en, de, fr).

$lng by value string ""

The language. If it is not specified, the default language is used.

Returns

bool

Returns true if the language code is valid (has translation), otherwise false.

Authors

Oleg Schildt

Source code

See also