Skip to main content

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

NameTypeDescription
keyXDefaultMessageCode | stringAn object containing the code of the translation and additional params or the code.
paramsDefaultMessageParamsTypeEither 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

NameTypeOptionalDescription
messagesDefaultMessageAn object that contains all messages.
keyXDefaultMessageCode | stringAn object containing the code of the translation and additional params or the code.
paramsDefaultMessageParamsType✔️Params that should be added to the text.
allowEmptyStringboolean✔️Allow empty strings.

Additional functions

messageFormat

This method formats a message with params.

import { messageFormat } from '@archibald/core';

const message = messageFormat(PARAMETERS);

Parameters

NameTypeDescription
textstringA message to format.
paramsanyParams that should be added to the text.