We’ve created a custom JS method for some custom locale work that loads the browser side I18n object with a custom attribute.
I want to trigger a re-evaluation of this JsLocaleHelper method on each of the dependent clients.
I’m trying to find a way to trigger this from server side.
This used to work but seems to have changed recently.
The data is correct when I delete the local client cache from the browser, but obviously this is not tenable for production use. It proves the issue is the local caching though.
Things I’ve tried include:
Discourse.request_refresh!
or the more targetted:
Discourse.request_refresh!(user_ids: user_ids)
which appears to force refresh on navigate. However suspect the script is being cached so this is not a solution.
I just tested Discourse.request_refresh! and it does seem to be reloading all javascript assets on the next navigation. It might not be triggering a JsLocaleHelper refresh, I am not sufficiently informed on how that works.
Did you try to call ExtraLocalesController.clear_cache! after you make changes to extra-locales? It should recalculate the version during the next request.
Thanks. Yes I have. I believe that’s just server side and does not change the version number on the provided JS file set up during bootstrap. Server side there is no issue.
I’m considering moving this data to the site object and serializer so see if I can have more control.
Well, I guess, I do not understand what you are trying to accomplish.
I assumed you wanted client to simply pick up data you added on the server on next reload. If you want to do everything on the client, why not update I18n.extras directly on the client.
If I run that command from the rails console, how does it invalidate the scripts on the client?
(FYI tags are special case as are used in slugs, so I have to add a special object to include translations, I can’t serialize a tag translation everywhere as routes would not work).
Next time the client reloads the page it will see a different hash in the HTML and load the new script. That’s how the “Customize Text” feature (it uses the “overrides” bundle) works.