问题描述
运行NG Build生成PWA方案后,找不到transloc翻译的i18n文件。我寻找文件指向的位置,但没有找到。
正确的网址是 http://localhost/mydomain/assets/i18n/en-US.json
transloco-root.module.ts 配置
import { HttpClient } from '@angular/common/http';
import {
TRANSLOCO_LOADER,Translation,TranslocoLoader,TRANSLOCO_CONfig,translocoConfig,TranslocoModule
} from '@ngneat/transloco';
import { Injectable,NgModule } from '@angular/core';
import { environment } from '../environments/environment';
@Injectable({ providedIn: 'root' })
export class TranslocoHttpLoader implements TranslocoLoader {
constructor(private http: HttpClient) {}
getTranslation(lang: string) {
return this.http.get<Translation>(`./assets/i18n/${lang}.json`);
}
}
@NgModule({
exports: [ TranslocoModule ],providers: [
{
provide: TRANSLOCO_CONfig,useValue: translocoConfig({
availableLangs: ['en-US','pt-BR'],defaultLang: 'en-US',fallbackLang: 'en-US',missingHandler: {
useFallbackTranslation: true,logMissingKey: false
},reRenderOnLangChange: true,prodMode: environment.production,})
},{ provide: TRANSLOCO_LOADER,useClass: TranslocoHttpLoader }
]
})
export class TranslocoRootModule {}