next-ucap-messenger/projects/ucap-webmessenger-app/src/app/app-translate.module.ts

47 lines
1.0 KiB
TypeScript
Raw Normal View History

2019-09-18 06:02:21 +00:00
import { NgModule } from '@angular/core';
import { TranslateModule, TranslateLoader } from '@ngx-translate/core';
2019-12-24 02:41:50 +00:00
import {
UCAP_NATIVE_SERVICE,
NativeService,
NativeType
} from '@ucap-webmessenger/native';
2019-12-18 04:44:26 +00:00
import { environment } from '../environments/environment';
export function createTranslateLoader(nativeService: NativeService) {
2019-12-24 02:41:50 +00:00
let prefix: string;
switch (nativeService.type()) {
case NativeType.Browser:
prefix = '/assets/i18n/';
break;
case NativeType.Electron:
prefix = environment.production
2020-01-02 05:26:14 +00:00
? '/dist/ucap-webmessenger-app/assets/i18n/'
2019-12-24 02:41:50 +00:00
: '/projects/ucap-webmessenger-app/src/assets/i18n/';
break;
default:
break;
}
return nativeService.getTranslateLoader(prefix, '.json');
}
2019-09-18 06:02:21 +00:00
@NgModule({
imports: [
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useFactory: createTranslateLoader,
deps: [UCAP_NATIVE_SERVICE]
}
})
],
2019-09-18 06:02:21 +00:00
exports: []
})
export class AppTranslateModule {}