TranslationHelper
The TranslationHelper offers functionality needed when working with translations.
import { TranslationHelper } from '@archibald/core';
key
This method get the key of a translation.
import { TranslationHelper } from '@archibald/core';
const key = TranslationHelper.key(PARAMETERS);
Parameters
| Name | Type | Description |
|---|---|---|
| keyX | DefaultMessageCode | string | An object containing the code of the translation and additional params or the code. |
| params | DefaultMessageParamsType | Either an Array of strings | numbers or object with key value pair. |
translate
This method gets a translated message.
import { TranslationHelper } from '@archibald/core';
const message = TranslationHelper.translate(PARAMETERS);
// translate({"test": "{0} is {1} message!"}, 'test', ['This', 'some'])
// => 'This is some message!'
// translate({"test": "{this} is {some} message!"}, 'test', {this: 'This', some: 'some'})
// => 'This is some message!'
// translate({"test": "{0} is {1} message!"}, {code: 'test', params: ['This', 'some']})
// => 'This is some message!'
// translate({"test": "{this} is {some} message!"}, {code: 'test', params: {this: 'This', some: 'some'})
// => 'This is some message!'
Parameters
| Name | Type | Optional | Description |
|---|---|---|---|
| messages | DefaultMessage | An object that contains all messages. | |
| keyX | DefaultMessageCode | string | An object containing the code of the translation and additional params or the code. | |
| params | DefaultMessageParamsType | ✔️ | Params that should be added to the text. |
| allowEmptyString | boolean | ✔️ | Allow empty strings. |
Additional functions
messageFormat
This method formats a message with params.
import { messageFormat } from '@archibald/core';
const message = messageFormat(PARAMETERS);
Parameters
| Name | Type | Description |
|---|---|---|
| text | string | A message to format. |
| params | any | Params that should be added to the text. |