Class lajax\translatemanager\helpers\Language
Inheritance | lajax\translatemanager\helpers\Language |
---|---|
Available since version | 1.1 |
Language helper.
Inserts the necessary JavaScripts for client side multilingual support into the content.
For translating one-dimensional arrays.
For translating database tables.
Public Methods
Method | Description | Defined By |
---|---|---|
a() | Translating one-dimensional array. | lajax\translatemanager\helpers\Language |
d() | For translating language elements stored in a database. | lajax\translatemanager\helpers\Language |
getCategories() | Returns the category of LanguageSource in an associative array. | lajax\translatemanager\helpers\Language |
isEnabledTranslate() | Determines whether the translation mode is active. | lajax\translatemanager\helpers\Language |
registerAssets() | Registering JavaScripts for client side multilingual support. | lajax\translatemanager\helpers\Language |
saveMessage() | Saveing new language element by category. | lajax\translatemanager\helpers\Language |
t() | lajax\translatemanager\helpers\Language |
Method Details
Translating one-dimensional array.
e.g.:
$array = [
'hello' => 'Hello {name}!',
'hi' => 'Hi {name}',
];
$params = [
'hello' => [
'name' => 'World',
],
'hi' => [
'name' => 'Jenny',
],
];
$result = \lajax\translatemanager\helpers\Language::a($array, $params);
The result:
[
'hello' => 'Hello World',
'hi' => 'Hi Jenny',
]
Translating multi-dimensional array. e.g.:
$array = [
self::GENDER_MALE => [
self::MATERIALSTATUS_MARRIED => 'Mr. {name}',
self::MATERIALSTATUS_SINGLE => 'Mr. {name}'
],
self::GENDER_FEMALE => [
self::MATERIALSTATUS_MARRIED => 'Mrs. {name}',
self::MATERIALSTATUS_SINGLE => 'Miss {name}'
]
];
$params = [
self::GENDER_MALE => [
self::MATERIALSTATUS_MARRIED => [
'name' => 'Smith'
],
self::MATERIALSTATUS_SINGLE => [
'name' => 'Stark'
]
],
self::GENDER_FEMALE => [
self::MATERIALSTATUS_MARRIED => [
'name' => 'Smith'
],
self::MATERIALSTATUS_SINGLE => [
'name' => 'Potts'
]
]
];
$result = \lajax\translatemanager\helpers\Language::a($array, $params);
The result:
[
self::GENDER_MALE => [
self::MATERIALSTATUS_MARRIED => 'Mr. Smith',
self::MATERIALSTATUS_SINGLE => 'Mr. Stark'
],
self::GENDER_FEMALE => [
self::MATERIALSTATUS_MARRIED => 'Mrs. Smith',
self::MATERIALSTATUS_SINGLE => 'Miss Potts'
]
]
public static array a ( $array, $params = [], $language = null ) | ||
$array | array | One-dimensonal or Multi-dimensional array to be translated. |
$params | array | List of parameters to be changed. |
$language | string | Language of translation. |
return | array | The translated array. |
---|
For translating language elements stored in a database.
Enable translating databases in config before use. e.g.:
'modules' => [
'translatemanager' => [
'class' => 'lajax\translatemanager\Module',
'tables' => [
[
'connection' => 'db',
'table' => 'language',
'columns' => ['name', 'name_ascii'],
],
[
'connection' => 'db',
'table' => 'product',
'columns' => ['name', 'description'],
]
]
]
]
public static string d ( $message, $params = [], $language = null ) | ||
$message | string | Language element stored in database. |
$params | array | Parameters to be changed. |
$language | string | Language of translation. |
return | string | Translated language element. |
---|
Returns the category of LanguageSource in an associative array.
public static array getCategories ( ) |
Determines whether the translation mode is active.
public static boolean isEnabledTranslate ( ) |
Registering JavaScripts for client side multilingual support.
public static void registerAssets ( ) |
Saveing new language element by category.
public static void saveMessage ( $message, $category = 'database' ) | ||
$message | string | Language element save in database. |
$category | string | The message category. |
public static string t ( $category, $message, $params = [], $language = null ) | ||
$category | string | The message category. |
$message | string | The message to be translated. |
$params | array | The parameters that will be used to replace the corresponding placeholders in the message. |
$language | string | The language code (e.g. |
return | string | The translated message. |
---|