rbalet / ngx-translate-multi-http-loader

A loader for ngx-translate that loads translations with http calls
MIT License
77 stars 15 forks source link

Use with angular 14 #14

Closed mtabaj closed 2 years ago

mtabaj commented 2 years ago

When I use as your documentation

`export function HttpLoaderFactory(http: HttpClient) { return new MultiTranslateHttpLoader(http, [ {prefix: "./assets/translate/core/", suffix: ".json"}, {prefix: "./assets/translate/shared/", suffix: ".json"}, ]); }

There is an error`

TS2345: Argument of type 'import("F:/baps/baps_14/node_modules/@angular/common/http/http").HttpClient' is not assignable to parameter of type 'import("F:/baps/baps_14/node_modules/ngx-translate-multi-http-loader/node_modules/@angular/common/http/index").HttpClient'.   Types have separate declarations of a private property 'handler'.

Help please

denniske commented 2 years ago

I am not sure what is the issue. If somebody has an idea please create PR. @mtabaj If you need a workaround just copy the code from https://github.com/denniske/ngx-translate-multi-http-loader/blob/master/src/multi-http-loader.ts into your project instead using the library using npm to solve this issue.

AshotAleqs commented 2 years ago

Hello @mtabaj, please make sure you are using v8.0.2 version of the library, also please double check if you have imported HttpClient from @angular/common/http

so the code in your root module should be similar to this:

import { HttpClient, HttpClientModule } from '@angular/common/http';
/////// other imports 

export function HttpLoaderFactory(http: HttpClient) {
  return new MultiTranslateHttpLoader(http, [
    { prefix: TRANSLATION_PREFIX, suffix: '/common.json' },
    { prefix: TRANSLATION_PREFIX, suffix: '/shared.json' },
    { prefix: TRANSLATION_PREFIX, suffix: '/auth.json' },
    { prefix: TRANSLATION_PREFIX, suffix: '/error.json' },
  ]);
}

@NgModule({
  declarations: [],
  imports: [
    CommonModule,
    HttpClientModule,
    TranslateModule.forRoot({
      loader: {
        provide: TranslateLoader,
        useFactory: HttpLoaderFactory,
        deps: [HttpClient],         //. <------- this is important
      },
      defaultLanguage: DEFAULT_LANGUAGE,
    }),

  ]
  })
export class AppModule { }
ojacquemart commented 2 years ago

I don't know what's the problem here. But with the 8.0.2 version, I have to remove the HttpClient type from the HttpLoaderFactory.

export function HttpLoaderFactory(http) { ... } is ok.

rbalet commented 2 years ago

@mtabaj Close as fixed in the latest release https://github.com/rbalet/ngx-translate-multi-http-loader/releases/tag/v9.0.0.

Please open the issue again in case this wouldn't be the case

ojacquemart commented 2 years ago

Thanks @rbalet for all the good work! 🚀 I did the upgrade and it worked smoothly 🥇

mtabaj commented 2 years ago

Thanks @rbalet !