how to preserve programmatically added translations on the client?
See original GitHub issueI am using localization translations from the legacy application backend (under the hood, it converts Java .properties
files into JSON format understood by VueI18n).
The logic works as follows:
async fetch ({ $axios, store, route, app }: Context) {
const [page, lang] = route.name?.split('___') ?? []
const res = await $axios.get(`http://localhost:8080/apiroot/${lang}/${page}:renderData`)
const renderData = res.data as TapestryRenderData
for (const componentKey in renderData.components) {
store.commit(`${componentKey}/setup`, renderData.components[componentKey])
}
app.i18n.setLocaleMessage('en', renderData.messages)
app.i18n.setLocale('en')
},
I observe the following effect:
- everything loads correctly and localizations are present during the first fraction of second when the pre-rendered page is displayed
- then, client-side hydration happens and all localizations are lost
Is there is a way to either (a) avoid updating localizations during the client-side hydration or (b) somehow pass localizations from the SSR phase to client-side hydration phase (so I could programmatically set messages again in beforeMount
hook, for example)?
Issue Analytics
- State:
- Created 3 years ago
- Comments:14
Top Results From Across the Web
how to preserve programmatically added translations on the ...
I am using localization translations from the legacy application backend (under the hood, it converts Java .properties files into JSON format ...
Read more >Are there any APIs for programmatically translating text on the ...
3 Answers 3 ... There is nothing limiting the Google Translate API to client side code. There is a RESTful Google Translate interface...
Read more >How to Programmatically Translate Your App or Website with ...
We'll show you how to get started with Google API tools so you can add language auto-translation capabilities to apps and websites.
Read more >How to publish latest revision langcode programmatically in ...
I try the following code on drush eval, but "de" translations are changed as first revision in paragaraph field. $langcode = "fr"; $nid...
Read more >Add or Load Translations - i18next documentation
There are a few options to load translations to your application instrumented by i18next. The most common approach to this adding a so...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@rchl I have eventually managed to fix this. If you’re curious, here’s how:
asyncData
(where I actually retrieve server-side localizations): callapp.i18n.mergeLocaleMessage(lang, renderData.messages)
before updating the storecreated
component hook (in fact I use a mixin for this): retrieve current page messages from the Vuex store (they were saved there duringasyncData
call), callthis.$i18n.mergeLocaleMessage(storedLocale, this.$store.getters['t5/i18n/getMessages'])
Item (a) fixes flickering and warnings during the SPA navigation. Item (b) fixes warnings when it’s going through SSR.
Downside: since I’m using
mergeLocaleMessage
, it’ll end up with all my server-side localizations in the browser memory (I’m not sure it’s a bad thing, but there’s certainly some room for optimizations).Thanks a lot for your help!
What I do now is:
It is unfortunate that the step at
created
is necessary. I haven’t experienced any flickers with this solution method.SEO: nuxt async i18n