lephyrus / ngx-translate-messageformat-compiler

Advanced pluralization (and more) for ngx-translate, using standard ICU syntax which is compiled with the help of messageformat.js.
MIT License
93 stars 30 forks source link

When enable Ivy get runtime error: Error: Can't resolve all parameters for sp: (?). #49

Closed menelai closed 4 years ago

menelai commented 5 years ago

To reproduce: create new Ivy app:

ng new shiny-ivy-app --enable-ivy
npm install @ngx-translate/core ngx-translate-messageformat-compiler messageformat --save

Enable message compiler in app.module.ts:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import {TranslateCompiler, TranslateModule} from '@ngx-translate/core';
import {TranslateMessageFormatCompiler} from 'ngx-translate-messageformat-compiler';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    TranslateModule.forRoot({
      compiler: {
        provide: TranslateCompiler,
        useClass: TranslateMessageFormatCompiler
      }
    })
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Run ng build --prod, then open the app in browser and you will get an error in the console:

main-es2015.b641edd2cb6b4bcc70a3.js:1 Error: Can't resolve all parameters for sp: (?).
    at main-es2015.b641edd2cb6b4bcc70a3.js:1
    at Ws (main-es2015.b641edd2cb6b4bcc70a3.js:1)
    at main-es2015.b641edd2cb6b4bcc70a3.js:1
    at main-es2015.b641edd2cb6b4bcc70a3.js:1
    at Gs.processProvider (main-es2015.b641edd2cb6b4bcc70a3.js:1)
    at main-es2015.b641edd2cb6b4bcc70a3.js:1
    at main-es2015.b641edd2cb6b4bcc70a3.js:1
    at Array.forEach (<anonymous>)
    at Jt (main-es2015.b641edd2cb6b4bcc70a3.js:1)
    at Gs.processInjectorType (main-es2015.b641edd2cb6b4bcc70a3.js:1)
lephyrus commented 5 years ago

@menelai For clarification: if you use ngx-translate without the messageformat compiler (this library), everything's fine?

menelai commented 5 years ago

@menelai For clarification: if you use ngx-translate without the messageformat compiler (this library), everything's fine?

Yes, it is.

mlcit commented 5 years ago

Creating factory for TranslateMessageFormatCompiler fix issue. MessageFormatConfig can be passed as param of constructor TranslateMessageFormatCompiler in factory function.

factory function:

export function TranslateMessageFormatCompilerFactory() {
  return new TranslateMessageFormatCompiler();
}

module imports:

TranslateModule.forRoot({
      compiler: {
        provide: TranslateCompiler,
        useFactory: TranslateMessageFormatCompilerFactory,
      },
}),
menelai commented 5 years ago

@mlcit it works, thank you!