Currently, I am focused on internationalization (i18n) of my Aurelia components. My goal is to render the translations server-side because our CMS houses the translations and they can be updated even after deployment. To achieve this, I have successfully developed a Java WebFilter that intercepts requests made to Aurelia templates, allowing me to translate strings before serving the template.
Everything seems to be working smoothly until the user decides to switch languages. The language switching triggers a full page refresh, with the chosen language stored in the server-side session. Consequently, even though the template parser detects the language change, the issue arises from the fact that the client-side cache contains the templates with the incorrect translations.
As a temporary solution, I've disabled caching for the templates. However, ideally, I would prefer for the browser to cache the templates but trigger a new request upon a language change event. This way, the templates will always remain up-to-date with the latest translations.
One simple workaround would involve appending the language as a parameter to the template URL when making the request. By doing so, the cached template won't be served if the language has changed. And in case the user switches back to the original language, we can easily retrieve the templates from the cache once more.
I attempted to implement this approach, but couldn't find any documentation related to configuring the default loader for this purpose. Is there a way to set it up to automatically include the language as a parameter in the template URL? Alternatively, could creating a custom loader be a viable solution to achieve this desired behavior?