In the official documentation there is a description how to configure the server for being ready for internationalization https://angular.io/guide/i18n#configuring-servers. Basically the url will be rewritten on the server-side based on the Accept-Language HTTP header.
I'm nevertheless searching for an approach for determine the locale based on a saved user preference in the backend database.
My project configuration: The angular project is included in a Single-Sign-On infrastructure. Which means the angular project itself hasn't any login page. Before coming onto the angular page, I want to go through a kind of proxy page. This page should request the backend server for the saved locale of the current user. After reading the response the user will be redirected to the locale specific url path. For example: Saved user locale on server: en -> url redirect to /app/en
index.html // the proxy page en de fr are the production build directories of the needed locales
My initial approach is the following:
<script>
const redirect = async () => {
const response = await fetch(<Webservice>);
const result = await response.json();
const locale = result?.user?.locale || 'en';
window.location.href = window.location.href.replace('/app/', '/app/' + locale + '/'));
}
redirect();
</script>
But I'm very unsure if this approach is a good one. Is it safety? Maybe there is already a standard implementation for this use case?
Thank you in advance!