Class for working with localization of texts.
| Properties | |
|---|---|
|
protected
|
Internal variable for storing the paths of the additional localization files. |
|
static
protected
|
Internal variable for storing the current context. |
|
protected
|
Internal variable for storing the cookie path. |
|
static
protected
|
Internal array for storing the list of country name translations. |
|
static
protected
|
Internal variable for storing the current language. |
|
protected
|
Internal variable for storing the state whether the dictionary is loaded or not. |
|
static
protected
|
Internal array for storing the list of language name translations. |
|
protected
|
Internal variable for storing the path with the localization files. |
|
static
protected
|
Internal array for storing the list of supported languages. |
|
static
protected
|
Internal array for storing the list of text translations. |
|
protected
|
Internal variable for storing the state whether the APCU should be used. |
|
protected
|
Internal variable for storing the state whether the last selected language can be stored to cookie. |
|
protected
|
Internal variable for storing the fallback language. |
|
protected
|
Internal variable for storing the state whether the E_USER_NOTICE is triggered in the case of missing translations. |
| 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). |
Internal variable for storing the paths of the additional localization files.
Internal variable for storing the current context.
Internal variable for storing the cookie path.
Internal array for storing the list of country name translations.
Internal variable for storing the current language.
Internal variable for storing the state whether the dictionary is loaded or not.
Internal array for storing the list of language name translations.
Internal variable for storing the path with the localization files.
Internal array for storing the list of supported languages.
Internal array for storing the list of text translations.
Internal variable for storing the state whether the APCU should be used.
Internal variable for storing the state whether the last selected language can be stored to cookie.
Internal variable for storing the fallback language.
If set and a translation is missing on a language, the translation on this language will be used.
Internal variable for storing the state whether the E_USER_NOTICE is triggered in the case of missing translations.
Adds additional localization files to the dictionary.
| Name | Pass type | Value type | Default value | Description |
|---|---|---|---|---|
| $localization_file | by value | string |
The path of the additional localization file. |
It might throw an exception in the case of any errors.
This function should detect the current language based on cookies, browser languages etc.
Priority:
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.
Adds additional translations to the dictionary.
| Name | Pass type | Value type | Default value | Description |
|---|---|---|---|---|
| $dictionary | by value | array |
The array with additional translations. |
It might throw an exception in the case of any errors.
Returns the current context.
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 the current context.
Tries to find the country code by the given name.
| Name | Pass type | Value type | Default value | Description |
|---|---|---|---|---|
| $country_name | by value | string |
The name of the country in any supported language. |
Returns the country code if it could be found, otherwise an empty string.
Provides the list of countries for the given language in the form "code" => "translation".
| 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 true if the country list is successfully retrieved, otherwise false.
Provides the text translation for the country name by the code for the given language.
| 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 the translation text for the country name or the $code if no translation is found.
Returns the current language.
Returns the current language ISO code.
Returns the fallback language. If set and a translation is missing on a language, the translation on this language will be used.
Returns the fallback language.
Tries to find the language code by the given name.
| Name | Pass type | Value type | Default value | Description |
|---|---|---|---|---|
| $lang_name | by value | string |
The name of the language in any supported language. |
Returns the language code if it could be found, otherwise an empty string.
Provides the list of languages for the given language in the form "code" => "translation".
| 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 true if the language list is successfully retrieved, otherwise false.
Provides the text translation for the language name by the code for the given language.
| 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 the translation text for the language name or the $code if no translation is found.
Returns the list of supported languages.
Returns the list of supported languages.
Checks whether the text translation for the text ID for the given language exists.
| 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 true if the translation exists, otherwise false.
Initializes the language manager with parameters.
| Name | Pass type | Value type | Default value | Description |
|---|---|---|---|---|
| $parameters | by value | array |
Settings for logging as an associative array in the form key => value:
|
It might throw an exception in the case of any errors.
This is function for loading the translations from the source JSON file.
It might throw the following exceptions in the case of any errors:
Sets the current context.
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.
| Name | Pass type | Value type | Default value | Description |
|---|---|---|---|---|
| $context | by value | string |
The name of the context. |
Sets the current language.
| Name | Pass type | Value type | Default value | Description |
|---|---|---|---|---|
| $language | by value | string |
The language ISO code to be set. |
Provides the text translation for the text ID for the given language.
| 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 the translation text or the $default_text/$text_id if no translation is found.
It might throw exceptions in the case of any errors.
Provides the text translation for the text ID for the given language if the translation exists.
Otherwise, it returns the text ID and emits no warning.
| 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 the translation text or the $default_text/$text_id if no translation is found.
It might throw exceptions in the case of any errors.
Checks whether the country code is valid (has translation).
| 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 true if the country code is valid (has translation), otherwise false.
Checks whether the language code is valid (has translation).
| 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 true if the language code is valid (has translation), otherwise false.