我正在尝试"@ngneat/transloco": ^2.17.1"
在我的应用程序中使用 i18n 。早些时候工作正常,但我不知道突然发生了什么,突然我收到此错误消息Unable to load translation and all the fallback languages, did you misspelled the scope name?
,但我无法找出问题所在。
我尝试在Codesandbox中创建类似的应用程序,但它工作正常。我的应用程序中有相同类型的代码,但它似乎不起作用。如果有任何解决方法,请帮忙。
这是我的 Transloco 配置:
@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', 'es'],
defaultLang: 'en',
// Remove this option if your application doesn't support changing language in runtime.
reRenderOnLangChange: true,
prodMode: environment.production,
})
},
{ provide: TRANSLOCO_LOADER, useClass: TranslocoHttpLoader }
]
})
export class TranslocoRootModule {}
Run Code Online (Sandbox Code Playgroud)
当我尝试使用翻译方法进行翻译时,它第一次不起作用。
constructor(
private translate: TranslocoService
) {
console.log('<< …
Run Code Online (Sandbox Code Playgroud)