Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular + Electron with ngx-translate

I have an Angular application and now a desktop version of it is also needed. I managed it to run the application in electron and everything works as expected.

But the localization does not work. In the electron- application I only see the localization- keys which points to the actual translation in the localization files.

I mainly translate the text in Angular like this:

{{ "localization-key" | translate }}

And the translations as json-files are based in assets/i18n/

Does someone has an idea how to get the localization work?

like image 441
yannick Avatar asked Oct 15 '25 20:10

yannick


1 Answers

I also had this problem. I found the solution in the 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 { }

If you used default TranslateHttpLoader for loader.useFactory, you see this error:i18n for wrong configuration of loader.factory for electron

like image 111
Halil Oymacı Avatar answered Oct 18 '25 10:10

Halil Oymacı



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!