core
core copied to clipboard
Translation file not found
Hello,
I am trying to use the plugin in nativescript with shared functionality of web and native code in angular 7. I have already used in previous NS projects, but I'm not able to get the proper paths for the jSON files, please help.
This is the required code. import { HttpClientModule, HttpClient } from "@angular/common/http"; mport { TranslateModule, TranslateLoader } from "@ngx-translate/core"; import { TranslateHttpLoader } from '@ngx-translate/http-loader'; .... export function createTranslateLoader(http: HttpClient) { return new TranslateHttpLoader(http, "./assets/i18n/", ".json"); }
imports: [ ... TranslateModule.forRoot({ loader: { provide: TranslateLoader, useFactory: createTranslateLoader, deps: [HttpClient] } }) ]
This is the error I am receiving...
CONSOLE ERROR file:///app/vendor.js:51832:24: ERROR { "headers": { "normalizedNames": {}, "lazyUpdate": null, "headers": {} }, "status": 0, "statusText": "Unknown Error", "url": "./assets/i18n/en.json", "ok": false, "name": "HttpErrorResponse", "message": "Http failure response for ./assets/i18n/en.json: 0 Unknown Error", "error": { "line": 84573, "column": 38, "sourceURL": "file:///app/vendor.js", "originalStack": "ZoneAwareError@file:///app/vendor.js:84573:38\nfile:///app/vendor.js:108252:37\nUIApplicationMain@[native code]\nstart@file:///app/vendor.js:103098:26\nrun@file:///app/vendor.js:103126:10\nbootstrapNativeScriptApp@file:///app/vendor.js:79967:26\nbootstrapApp@file:///app/vendor.js:79868:38\nbootstrapModule@file:///app/vendor.js:79852:26\nfile:///app/bundle.js:2014:144\n./main.ts@file:///app/bundle.js:2019:34\n__webpack_require__@file:///app/bundle.js:752:34\ncheckDeferredModules@file:///app/bundle.js:45:42\nfile:///app/bundle.js:828:38\nanonymous@file:
Been stuck in it for the last 2 hours, don't know what i'm missing here, please help.
We have a similar issue on ng version 8. The translation files cannot be found, but same configuration works on a version 7 project.
We have the same issue with V8 and Nativescript
For anyone having a similar issue, this might be your solution. Please have a look and check. It solved the problem for me: https://github.com/ngx-translate/core/issues/921
I'm getting the following error
CONSOLE ERROR file:///node_modules/@angular/core/fesm5/core.js:4002:0: ERROR {
"headers": {
"normalizedNames": {},
"lazyUpdate": null,
"headers": {}
},
"status": 404,
"statusText": "ERROR",
"url": "/var/mobile/Containers/Data/Application/07A47D7F-9A3E-4814-A9B7-DF0C72FEA1D7/Library/Application Support/LiveSync/app/assets/i18n/ko-KR.json",
"ok": false,
"name": "HttpErrorResponse",
"message": "Http failure response for /var/mobile/Containers/Data/Application/07A47D7F-9A3E-4814-A9B7-DF0C72FEA1D7/Library/Application Support/LiveSync/app/assets/i18n/ko-KR.json: 404 ERROR",
"error": "Not Found"
}
I'm having the following httpLoaderFactory()
import { HttpBackend, HttpClient } from '@angular/common/http';
import { TranslateHttpLoader } from '@ngx-translate/http-loader';
export function httpLoaderFactory(http: HttpBackend): TranslateHttpLoader {
return new TranslateHttpLoader(new HttpClient(http));
}
any news about this issue?
@DepickereSven try this code
export function createTranslateLoader(http: HttpClient) {
return new TranslateHttpLoader(http, 'assets/i18n/', '.json');
}
@NgModule({
declarations: [
AppComponent,
HomeComponent,
],
imports: [
BrowserModule,
BrowserAnimationsModule,
AppRoutingModule,
HttpClientModule,
GraphQLModule,
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useFactory: createTranslateLoader,
deps: [HttpClient]
}
})
],
providers: [
AuthService,
{provide: HTTP_INTERCEPTORS, useClass: InterceptorService, multi: true},
],
bootstrap: [AppComponent]
})
export class AppModule {
constructor(
private translate: TranslateService,
) {
this.translate.setDefaultLang('en');
translate.use('en');
}
}
the en.json is in src/assets/i18n
I have this error happens randomly in production in error logging.
Error: Http failure response for ./assets/en.json: 0 Unknown Error