-
-
Notifications
You must be signed in to change notification settings - Fork 576
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sometimes DefaultLang translations are not loaded when starting the app #1347
Comments
Hi @ewolfman. I had the same problem, which came funnily from my httpInterceptor. I was using the angular Here's how I fixed it. 1. I recreated the MultiTranslateHttpLoader to be able to add the
|
@rbalet just try to use HttpBackend instead of HttpClient inside your custom translate loader. It will skip your interceptors. |
@krutkowski86 Thx! I didn't though of it, here's the new code import { HttpBackend, HttpClient } from '@angular/common/http'
import { TranslateLoader } from '@ngx-translate/core'
import * as merge from 'deepmerge'
import { forkJoin, Observable, of } from 'rxjs'
import { catchError, map } from 'rxjs/operators'
export class MegaMultiTranslateHttpLoader implements TranslateLoader {
constructor(private _handler: HttpBackend, private _resourcesPrefix: string[]) {}
public getTranslation(lang: string): Observable<any> {
const requests = this._resourcesPrefix.map((prefix) => {
const path = `${prefix}${lang}.json`
return new HttpClient(this._handler).get(path).pipe(
catchError((res) => {
console.group('MegaMultiTranslateHttpLoader')
console.error('Something went wrong for the following translation file:', path)
console.error('Content of the error: ', res)
console.groupEnd()
return of({})
}),
)
})
return forkJoin(requests).pipe(map((response) => merge.all(response)))
}
} |
@ewolfman Should be fixed on the latest version of this library https://www.npmjs.com/package/ngx-translate-multi-http-loader. Can you try this out ? |
@ocombe Feel free to close this issue since I took over the library that was causing the problem & fixed the problem there |
Current behavior
This issue may be similar to: #1162.
In my case I noticed that the app, while in production, sometimes fails to fallback to the default language on the first loaded screen (i.e. app first startup on load).
For example:
this.translate.setDefaultLang('en');
this.translate.use('es')
.Some observations:
For these reasons I suspect that the problem is with falling back to the default language when a resource is missing.
I tried various solutions to delay loading and ensure the translations are available but unfortunately could not workaround these problems. Here are some of the things I tried:
Expected behavior
The default language should be used for missing keys in the selected language, also upon application startup.
Environment
The text was updated successfully, but these errors were encountered: