2019-09-24 09:03:36 +09:00
|
|
|
import { TranslateLoader } from '@ngx-translate/core';
|
|
|
|
import { Observable } from 'rxjs';
|
2019-11-11 18:09:47 +09:00
|
|
|
import { NativeService } from '@ucap-webmessenger/native';
|
2019-09-24 09:03:36 +09:00
|
|
|
import { take, map } from 'rxjs/operators';
|
2019-11-13 11:48:39 +09:00
|
|
|
import { Injectable } from '@angular/core';
|
2019-09-24 09:03:36 +09:00
|
|
|
|
2019-11-13 11:48:39 +09:00
|
|
|
@Injectable({
|
|
|
|
providedIn: 'root',
|
|
|
|
})
|
2019-11-11 18:09:47 +09:00
|
|
|
export class TranslateLoaderService implements TranslateLoader {
|
2019-09-24 09:03:36 +09:00
|
|
|
constructor(
|
2019-11-11 18:09:47 +09:00
|
|
|
private nativeService: NativeService,
|
2019-09-24 09:03:36 +09:00
|
|
|
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'));
|
2019-09-24 09:03:36 +09:00
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|