import { Injectable } from '@angular/core' ; import { TranslateService } from '@ngx-translate/core' ; @ Injectable ( { providedIn : 'root' , } ) export class HsLanguageService { language : string ; constructor ( private TranslateService ) { } public param { string } lang description setLanguage ( lang ) { this . language = lang ; this . TranslateService . use ( lang ) ; } public returns { string } description getCurrentLanguageCode ( ) { if ( typeof this . language == 'undefined' || this . language == '' ) { return 'en' ; } return this . language . substr ( 0 , 2 ) . toLowerCase ( ) ; } public returns { Object } description listAvailableLanguages ( ) { const language_code_name_map = { 'en' : 'English' , 'cs' : 'Česky' , 'fr' : 'Français' , 'lv' : 'Latviski' , 'nl' : 'Nederlands' , 'sk' : 'Slovensky' , } ; const langs = [ { key : 'en' , name : 'English' } ] ; for ( const lang of this . TranslateService . getLangs ( ) ) { if ( language_code_name_map . hasOwnProperty ( lang ) && langs . filter ( ( l ) => l . key == lang ) . length == 0 ) { langs . push ( { key : lang , name : language_code_name_map [ lang ] } ) ; } } return langs ; } param str param params returns getTranslation ( str , params ? ) { return this . TranslateService . instant ( str , params ) ; } param module param text param params returns getTranslationIgnoreNonExisting ( module , text , params ? ) { const tmp = this . getTranslation ( module + '.' + text , params || undefined ) ; if ( tmp . includes ( module + '.' ) ) { return text ; } return tmp ; } }