import { Injectable } from '@angular/core' ; import { BehaviorSubject } from 'rxjs' ; import * as LANGUAGE_EN from './form-language/en.json' ; import * as LANGUAGE_ES from './form-language/es.json' ; /**
 * Form language service
 */ @ Injectable ( ) export class FormLanguageService { set language ( languageId ) { this . getLanguage ( languageId ) ; } get language ( ) : string { return this . language$ . value . id ; } language$ : BehaviorSubject < any > = new BehaviorSubject ( LANGUAGE_EN ) ; languages : Array < any > = [ LANGUAGE_EN , LANGUAGE_ES ] ; param id getLanguage ( id ) { let language = null ; if ( id ) { language = this . languages . find ( lang => lang . id === id ) ; } if ( ! language ) { language = LANGUAGE_EN ; } this . language$ . next ( language ) ; } }