import { PortalService } from './portal.service' ; import { StartupInfo } from './../models/portal' ; import { TranslateService } from '@ngx-translate/core' ; import { Observable } from 'rxjs/Observable' ; import { Headers , Response } from '@angular/http' ; export class LanguageServiceHelper { public static getLanguageAndRuntime ( startupInfo , runtime ) { let lang = 'en' ; runtime = runtime ? runtime : 'default' ; if ( PortalService . inIFrame ( ) ) { lang = startupInfo . effectiveLocale . split ( '.' ) [ 0 ] ; } return { lang : lang , runtime : runtime , } ; } public static setTranslation ( stringResources , lang , ts ) { ts . setDefaultLang ( 'en' ) ; ts . setTranslation ( 'en' , stringResources . en ) ; if ( stringResources . lang ) { ts . setTranslation ( lang , stringResources . lang ) ; } ts . use ( lang ) ; } public static getApiControllerHeaders ( ) { const headers = new Headers ( ) ; headers . append ( 'Content-Type' , 'application/json' ) ; headers . append ( 'Accept' , 'application/json,*/*' ) ; return headers ; } public static retry ( error ) { return error . scan ( ( errorCount , err ) => { if ( errorCount >= 10 ) { throw err ; } else { return errorCount + 1 ; } } , 0 ) . delay ( 1000 ) ; } }