pikax / vue-composable

Vue composition-api composable components. i18n, validation, pagination, fetch, etc. +50 different composables

Home Page:https://pikax.me/vue-composable/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

i18n: replace locale after setup

francois-pasquier opened this issue · comments

Hi, I tried setting my locale inside vuex in order to be able to change in without reloading my app but I am getting this warning: provide() can only be used inside setup().

I tried calling setI18n inside a watchEffect but I guess the composition api doesn't allow that.

Is there any method to call to update the current locale inside of i18n?

Can you provide code?

set/use functions need to be called in the setup, because they need to call provide/inject.

wrong usage:

setup(){
  watchEffect(()=> {
      setI18n({/*def*/}) 
     // equivalent to
     provide(I18N, {/* def */} // provide cannot be used here
  }
}

Depending on what you are intending to do, you have a couple choices, my recommendation is to useI18n on the setup and then addLocale or removeLocale as you please on whatchEffect

I'll be closing this, since this has been also inactive for abut a month, if you still having problems, please reply and I will reopen or help you out figuring out a solution.