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.
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¶
language
-string
: Language to use (en, fr, it, …)
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
setMultipleLanguageTranslations¶
translateService.setMultipleLanguageTranslations(translations);
Set translations for multiple languages
Parameters¶
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¶
language
-string
: Language to set translations fortranslations
-any
: Translations to add.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¶
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¶
key
-string|any
: Key to translate or an object that contains key and translateOptions paramsoptions
-any
: translation options
Returns¶
Promise
returns void
: resolved when done
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¶
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¶
key
-string
: key to addtranslation
-string
: value for the key
getCurrentLang¶
translateServic.getCurrentLang();
Returns the current language.
Returns¶
string
: The current language key
watchTranslationUpdate¶
translateService.watchTranslationUpdate(callback);
Adds a translation update watcher.
Don’t forget to unsubscribe on component destroy.
Parameters¶
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
}