EvanTranslationService

Source translate

I18N utility functions. Make it possible to share i18n through all applications. The I18N service uses ngx translate to handle translations in services and templates.

  1. monthShortNames - Array<string>: array of the 12 translated short names of the months

setLanguage

translateService.setLanguage(language);

Set to the translation service the default language to en and the language to use.

Parameters

  1. language - string: Language to use (en, fr, it, …)

Example

this.translateService.setLanguage('en')

reloadTranslations

translateService.reloadTranslations();

Reload all translations for the current language (triggers ui recalculation, if the ApplicationRef change detection is enabled)

Returns

Promise returns void: resolved when done

Example

translateService.reloadTranslations();

setMultipleLanguageTranslations

translateService.setMultipleLanguageTranslations(translations);

Set translations for multiple languages

Parameters

  1. translations - any: Translations objects wrapped by language keys { en : { ‘hello’ : ‘Hello’ }, de : { ‘hello’ : ‘Hallo’ } }

Example

this.translateService.setMultipleLanguageTranslations({
  en : { 'hello' : 'Hello' },
  de : { 'hello' : 'Hallo' }
});

setTranslation

initializedModule.setTranslation(language, translations, disableEvent);

Adds translations to the shared translate service

Parameters

  1. language - string: Language to set translations for
  2. translations - any: Translations to add.
  3. disableEvent - boolean: dont trigger translation update event

Example

this.translateservice.setTranslation('en', {
  'key1': 'translated 1',
  'key2': 'translated 2'
})

setTranslationToCurrentLanguage

translateService.setTranslationToCurrentLanguage(translations);

Adds translations to the current language service

Parameters

  1. translations - any: Translations to add.

Example

this.translateservice.setTranslationToCurrentLanguage({
  'key1': 'translated 1',
  'key2': 'translated 2'
})

instant

translateService.instant(key, options);

Returns an translated key instant, synchroniously

Parameters

  1. key - string|any: Key to translate or an object that contains key and translateOptions params
  2. options - any: translation options

Returns

Promise returns void: resolved when done

Example

translateService.instant('key1', { param1: '...' })

getTranslatedDescription

translateService.getTranslatedDescription(dapp);

Use I18N object from DApp and add an translated property to the DApp, where translations for the current language are saved.

Parameters

  1. dapp - any: The options used for calling

Returns

any: The translated dapp description.

Example

Usage: have a look into the description service, getDescription function


addSingleTranslation

translateService.addSingleTranslation(arguments);

Adds a single translation to the current language.

Parameters

  1. key - string: key to add
  2. translation - string: value for the key

Example

this.translateservice.addSingleTranslation('key1', 'translated 1')

getCurrentLang

translateServic.getCurrentLang();

Returns the current language.

Returns

string: The current language key

Example

this.translateservice.getCurrentLang()

watchTranslationUpdate

translateService.watchTranslationUpdate(callback);

Adds a translation update watcher.

Don’t forget to unsubscribe on component destroy.

Parameters

  1. callback - Function: function that is called, when translations were added

Returns

Function: call to unsubscribe

Example

const clearFunc = this.translateservice.watchTranslationUpdate(() => {
  console.log('translations added!')
}))

ngOnDestroy() {
  clearFunc
}