You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am doing dynamic translations that come from an api. I use the setLocaleMessage() function to set the translations. For this, within the components I can use
var i18n = useI18n({}) and i18n.setLocaleMessage(lang, translations) translations coming from the api. I want to do this with a service, but useI18n cannot be used outside of a setup function.
this.i18n also does not work as it is undefined. Online examples show to have the app use ViteI18n from import VueI18n from 'vue-i18n' , but this import is not provided by vue-i18n. According to the vite i18n docs, I use const i18n = createI18n({ locale: 'en', legacy: false, globalInjection: true})
The global problem I am trying to solve is the fact that I want to have translations loaded for separate components ( as my current solution requires me to provide an array with all translation ids to the axios post request ). I wanted to have them loaded on the router.beforeach, but right now I am unable to do the translation anywhere outside of components.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I am doing dynamic translations that come from an api. I use the setLocaleMessage() function to set the translations. For this, within the components I can use
var i18n = useI18n({})
andi18n.setLocaleMessage(lang, translations)
translations coming from the api. I want to do this with a service, but useI18n cannot be used outside of a setup function.this.i18n also does not work as it is undefined. Online examples show to have the app use ViteI18n from import VueI18n from 'vue-i18n' , but this import is not provided by vue-i18n. According to the vite i18n docs, I use
const i18n = createI18n({ locale: 'en', legacy: false, globalInjection: true})
The global problem I am trying to solve is the fact that I want to have translations loaded for separate components ( as my current solution requires me to provide an array with all translation ids to the axios post request ). I wanted to have them loaded on the router.beforeach, but right now I am unable to do the translation anywhere outside of components.
Beta Was this translation helpful? Give feedback.
All reactions