0👍
✅
Maybe there are more problems but now I see two:
- Your
menudata
should becomputed
instead of justref
. Right now you are creating a JS object and setting itlabel
property to result oft()
call. When global locale changes this object is NOT created again. It still holds same value thet()
function returned the only time it was executed – whensetup()
was running
// correct
const menudata = computed<MenuItemData[]>(() => [
{
type: "root",
label: t("ファイル"),
onClick: () => {
closeAllDialog();
},
// ...
]);
This way whenever i18n.global.locale
changes, your menudata
is created again with new translation
As an alternative, set label
to key and use t(label)
inside the template. However computed
is much more effective solution…
- You don’t need to pass
messages
touseI18n()
in every component. Only to the global instance. By passing config object into auseI18n()
in a component you are creating Local scope which makes no sense if you are storing all translations in a single global place anyway
Source:stackexchange.com