import { TranslateLoader } from '@ngx-translate/core'; import { Observable } from 'rxjs'; import { NativeService, UCAP_NATIVE_SERVICE } from '@ucap-webmessenger/native'; import { take, map } from 'rxjs/operators'; import { FileUtil } from '@ucap-webmessenger/core'; import { Injectable, Inject } from '@angular/core'; @Injectable({ providedIn: 'root' }) export class TranslateBrowserLoader implements TranslateLoader { constructor( @Inject(UCAP_NATIVE_SERVICE) private nativeService: NativeService, private prefix: string = '/assets/i18n/', private suffix: string = '.json' ) {} /** * Gets the translations from the server */ public getTranslation(lang: string): Observable { return this.nativeService .readFile(`${this.prefix}${lang}.${this.suffix}`) .pipe( take(1), map(buffer => { return JSON.parse(buffer.toString('utf-8')); }) ); } }