Manual Reference Source Test
import Language from 'clinical6/src/helpers/Language.js'
public class | source

Language

Expression Extends:

class Language extends aggregate(LanguageModel, Helper)

Helper class representing a Language.

Static Member Summary

Static Public Members
public static get

Constructor Summary

Public Constructor
public

constructor(json: Object, getTranslations: Boolean)

Constructor for Language.

Member Summary

Private Members
private

Method Summary

Public Methods
public

Synchronizes the language information with the server and sets it to this._translations

public

Returns the translation for the language based on the 'key'.

Static Public Members

public static get type: String source

Public Constructors

public constructor(json: Object, getTranslations: Boolean) source

Constructor for Language. Can be used to represent a language, translate a key to text, and pull back translations from the server, storing it in this._translations.

Params:

NameTypeAttributeDescription
json Object
  • optional

Object containing response described in LangaugeModel

getTranslations Boolean
  • optional
  • default: false

If true, pull back translations from server

Private Members

private _translations: Object source

Public Methods

public getTranslations(): Promise source

Synchronizes the language information with the server and sets it to this._translations

Return:

Promise

Returns a key/value object with the key being the word and value being the translation.

Example:

const lang = new Language({ iso: 'en' });
lang.getTranslations();
const lang = new Language({ iso: 'en' }, true);
// automatically calls lang.getTranslations();

Test:

public translate(key: String): String source

Returns the translation for the language based on the 'key'.

Params:

NameTypeAttributeDescription
key String
  • nullable: false

The key corresponding to the translation.

Return:

String

The value correspondingto the translation.

Example:

const lang = new Language({ iso: 'en' }, true);
console.log(lang.translate('welcome_description'));
languageService.getLanguages().then((languages: Language[]) => {
  languages[0].getTranslations() // will get translations for the language;
    .then(()=>{
      console.log(languages[0].translate('welcome_text'));
    });
});