Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

This class provides methods returning translated messages. This  This class has no constructor; methods can be accessed using the s_i18n global object.

getMessage(msgKey, config, callback)


This method returns a string containing a message in a the user language for a specified string. If this string does not have localization for the current language, or it does not exist at all, the method returns the msgKey value.

The msgKey parameter should pass the string for translation, and the callback parameter is the function that will be executed after the server response.

note

Please note that this method is asynchronous; for better performing, use the await keyword like shown in the code example below.

Parameter(s):

NameTypeMandatoryDefault Value
msgKeyStringYN
configObjectN''
callback
functionYN
FunctionNN


The config parameter is implemented as an object containing three other parameters:

NameTypeMandatoryDefault Value
languageStringN''
categoryStringN'app'
paramsObjectN''

The language parameter can take on values specified in the Languages (sys_language) dictionary. If it is not specified, then the current user's language is used when the method called.

The category parameter can take on values specified in the Category field of the Source Message (source_message) table record.

The params parameter provides an object service to aggregate the language and category parameter values and to keep the placeholder values from the msgKey parameter (see the code example below).

Note

Generally, the config parameter is non-mandatory, so you can use callback functions to get translations:

Code Block
languagejs
themeEclipse
titlegetMessage
await s_i18n.getMessage('Description', (response) => {console.log(response)});
// Description



Note

Please note that this method is asynchronous; for better performing, use the await keyword like shown in the code example below.


Return:

TypeDescription
VoidStringThis method does not return a valuereturns a message, optionally translated in the language specified.


Example:

Code Block
languagejs
themeEclipse
titlegetMessage
linenumberstrue
if (!s_form.getValue('condition') && !s_form.getValue('script')) {
  await s_i18n.getMessage('Specify conditions in "Condition" [condition] or "Script" [script] fieldsfield.', (response) => {
    s_form.addErrorMessage(response);
  });
  return false;
}


Code Block
languagejs
themeEclipse
titlegetMessage
linenumberstrue
const serviceNameValue = 'Email';
s_i18n.getMessage('Sorry, {serviceName} Service Is Temporarily Unavailable', {params: {"serviceName": serviceNameValue}, language: "en", category: "app"}, (response) => console.log(response));

// Sorry, Email Service Is Temporarily Unavailable

getMessages(msgKeys, config, callback)


This method returns an array of strings that contains messages in a user language. If these strings do not have localization for the current language, or they do not exist at all, the method returns msgKey string values.

 keyword like shown in the code example below

The msgKeys parameter should pass the array of strings for translation, and the callback parameter is the function that will be executed after the server response.

NotePlease note that this method is asynchronous; for better performing, use the await

.


Parameter(s):

NameTypeMandatoryDefault Value
msgKeys
msgKey
Array of strings
StringYN
configObjectN''
callback
functionYN
FunctionNN


The config parameter is implemented as an object containing three other parameters:

NameTypeMandatoryDefault Value
languageStringN''
categoryStringN'app'
paramsObjectN''

The language parameter can take on values specified in the Languages (sys_language) dictionary. If it is not specified, then the current user's language is used when the method called.

The category parameter can take on values specified in the Category field of the Source Message (source_message) table record.

The params parameter provides an object service to aggregate the language and category parameter values and to keep the placeholder values from the msgKey parameter (see the code example below).


Note

Please note that this method is asynchronous; for better performing, use the await keyword like shown in the code example below.


Return:

TypeDescription
VoidArray of stringsThis method does not return a valuereturns an array of messages, optionally translated into the language specified.


Example:

Code Block
languagejs
themeEclipse
titlegetMessages
linenumberstrue
const data = {};
const btnTitles = ['Accept', 'Cancel'];
await s_i18n.getMessages(btnTitles, (response) => {
  [data.acceptBtnTitle, data.cancelBtnTitle] = response;
});
console.log(JSON.stringify(data));

// {"acceptBtnTitle":"Accept","cancelBtnTitle":"Cancel"}


Note

Please note that if you use the same placeholders for different messages, then the getMessages() method output will contain the same values on their place.

Code Block
languagejs
themeEclipse
titlegetMessages
linenumberstrue
const dayOfWeek = ['Monday', 'Wednesday', 'Friday'];
s_i18n.getMessages(dayOfWeek, {language: 'ru'}, (response) => {console.log(response.join('-'))});

// Понедельник-Среда-Пятница



Table of Contents
absoluteUrltrue
classfixedPosition