http-loader
http-loader copied to clipboard
How to get translations files from other server (fix cors error)
When getting translations from other server like this
export function HttpLoaderFactory(http: HttpClient) {
return new TranslateHttpLoader(http, 'http://www.example.com/assets/i18n/', '/translations.json');
}
I get the following cors error:
Access to XMLHttpRequest at 'http://www.example.com/assets/i18n/en_US/translations.json' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Can anyone help with that? Thanks in advance.
+1
Having the same issue.
It's not the problem of ngx-translate. Read: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
In short, remote server which holds translations should add header in response: Access-Control-Allow-Origin: *
Well the remote server is the angular web server. I have already enabled crossOrigin flag in angular builder and updated nginx config. Still cors issue with retrieving json from resource. Im suspecting this is linked to the Interceptor issue. I have several Angular FEs running and none of them have the issue except for the one with Interceptor enabled.
Im trying this now: https://github.com/ngx-translate/core/issues/921. will report back.
circumventing the HttpIntecptor fixed the issue for me. no more cors errors.