28 lines
792 B
TypeScript
Raw Normal View History

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