ngx-translate / core

The internationalization (i18n) library for Angular
MIT License
4.5k stars 574 forks source link

ng2 translate does not work with webpack #608

Open Shifs opened 7 years ago

Shifs commented 7 years ago

For reducing the start time of the application, I have configured webpack in my application . But after that ng2 translate is not working and I am getting the error ERROR Error: Uncaught (in promise): Response with status: 200 for URL: null

"ng2-translate": "^5.0.0",

app.module.ts

export function createTranslateLoader(http: Http) {
    return new TranslateHttpLoader(http, './assets/i18n', '.json');
}
@NgModule({
  declarations: [AppComponent],
  bootstrap: [AppComponent],
imports: [
    NativeScriptModule,
    NativeScriptHttpModule,
    NativeScriptUIListViewModule,
    NativeScriptFormsModule,
    NativeScriptUISideDrawerModule,
    NativeScriptRouterModule,
    NativeScriptRouterModule.forRoot(routes),
    TranslateModule.forRoot({
            provide: TranslateLoader,
            useFactory: (createTranslateLoader),
            deps: [Http]
        })
  ],

In webpack.config.js I have added

new CopyWebpackPlugin([
            {from: mainSheet},
            {from: "css/**"},
            {from: "fonts/**"},
            {from: "**/*.jpg"},
            {from: "**/*.png"},
            {from: "**/*.xml"},
            **{from: "i18n/*.json"},**
            {from: "**/*.json"},
        ], {ignore: ["App_Resources/**"]}),
Shifs commented 7 years ago

I have updated ng2 translate and now using ng-x- translate but still getting the same issue "@ngx-translate/core": "^7.0.0", "@ngx-translate/http-loader": "^0.1.0",

Cayan commented 7 years ago

I had a similar issue a few hours ago, if your translation json is inside the folder app/assets/i18n add the next line to your CopyWebpackPlugin { from: "assets/i18n/*.json" }

Shifs commented 7 years ago

@Cayan : Tried that too .. still the error is same. Can you please share your app.module.ts

Cayan commented 7 years ago

@Shifs the related code from app.module.ts is listed below:

... import { TranslateModule, TranslateLoader } from '@ngx-translate/core'; import { TranslateHttpLoader } from '@ngx-translate/http-loader'; ... export function createTranslateLoader(http: Http) { return new TranslateHttpLoader(http); }

@NgModule({ schemas: [NO_ERRORS_SCHEMA], imports: [ TranslateModule.forRoot({ loader: { provide: TranslateLoader, useFactory: (createTranslateLoader), deps: [Http] } }), ...

mozi22 commented 6 years ago

@Shifs did you solve this issue ?