Angular + Electron 和 ngx-translate
Angular + Electron with ngx-translate
我有一个 Angular 应用程序,现在还需要它的桌面版本。我设法 运行 在 electron 中应用,一切都按预期工作。
但是本地化不起作用。在电子应用程序中,我只看到本地化键,它指向本地化文件中的实际翻译。
我主要翻译Angular中的文字是这样的:
{{ "localization-key" | translate }}
并且 json 文件的翻译基于 assets/i18n/
有人知道如何进行本地化吗?
现在可以使用了。问题是我使用了 ngx-translate 的 Http-Loader,它在 electron 中不起作用。
所以我实现了 TranslateUniversalLoader,就像提到的这个线程的最后一个 post:https://github.com/ngx-translate/core/issues/754
我也遇到了这个问题。我在 offical documentation of ngx-translate.
中找到了解决方案
If you want to configure a custom TranslateLoader while using AoT
compilation, Ionic or Electron, you must use an exported function
instead of an inline function.
export function createTranslateLoader(http: HttpClient) {
return new TranslateHttpLoader(http, './assets/i18n/', '.json');
}
@NgModule({
imports: [
BrowserModule,
HttpClientModule,
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useFactory: (createTranslateLoader),
deps: [HttpClient]
}
})
],
bootstrap: [AppComponent]
})
export class AppModule { }
如果您对 loader.useFactory
使用默认值 TranslateHttpLoader
,您会看到此错误:
我有一个 Angular 应用程序,现在还需要它的桌面版本。我设法 运行 在 electron 中应用,一切都按预期工作。
但是本地化不起作用。在电子应用程序中,我只看到本地化键,它指向本地化文件中的实际翻译。
我主要翻译Angular中的文字是这样的:
{{ "localization-key" | translate }}
并且 json 文件的翻译基于 assets/i18n/
有人知道如何进行本地化吗?
现在可以使用了。问题是我使用了 ngx-translate 的 Http-Loader,它在 electron 中不起作用。
所以我实现了 TranslateUniversalLoader,就像提到的这个线程的最后一个 post:https://github.com/ngx-translate/core/issues/754
我也遇到了这个问题。我在 offical documentation of ngx-translate.
中找到了解决方案If you want to configure a custom TranslateLoader while using AoT compilation, Ionic or Electron, you must use an exported function instead of an inline function.
export function createTranslateLoader(http: HttpClient) {
return new TranslateHttpLoader(http, './assets/i18n/', '.json');
}
@NgModule({
imports: [
BrowserModule,
HttpClientModule,
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useFactory: (createTranslateLoader),
deps: [HttpClient]
}
})
],
bootstrap: [AppComponent]
})
export class AppModule { }
如果您对 loader.useFactory
使用默认值 TranslateHttpLoader
,您会看到此错误: