How to get the equivalent to context.app.i18n.locale inside nuxt.config.ts file in Nuxt 3 ?
I am using "@nuxtjs/i18n": "^8.0.0-rc.5" (the @nuxtjs/i18n@next one).
Thank you in advance,
How to get the equivalent to context.app.i18n.locale inside nuxt.config.ts file in Nuxt 3 ?
I am using "@nuxtjs/i18n": "^8.0.0-rc.5" (the @nuxtjs/i18n@next one).
Thank you in advance,
With Nuxt 3 I have created a Pinia store in the project and called it localeStore. This is the locale.ts file code for the store:
import { defineStore } from "pinia";
export const useLocaleStore = defineStore("locale", {
state: () => ({
}),
getters: {
currentLocale: () => {
return useNuxtApp().$i18n.locale.value;
}
},
actions: {
translate(key: string) {
return useNuxtApp().$i18n.t(key);
}
}
});
Then, inside other .ts files in composables or utils or whatever, you can import the store and use its currentLocale getter or translate function:
import { useLocaleStore } from "~~/store/locale";
const localeStore = useLocaleStore();
function t(key: string) {
return localeStore.translate(key);
}
Ii realized I couldn't, so I used a different strategy.