1👍
You could use the onBeforeLanguageSwitch
callback.
From the official documentation
Called before the app’s locale is switched. Can be used to override the new locale by returning a new locale code.
So you could create a plugin that handles the logic for you. For example (as in the official documentation):
/plugins/i18n.js
:
export default function ({ app }) {
// onBeforeLanguageSwitch called right before setting a new locale
app.i18n.onBeforeLanguageSwitch = (oldLocale, newLocale, isInitialSetup, context) => {
console.log(oldLocale, newLocale, isInitialSetup)
}
// onLanguageSwitched called right after a new locale has been set
app.i18n.onLanguageSwitched = (oldLocale, newLocale) => {
console.log(oldLocale, newLocale)
}
}
Source:stackexchange.com