Skip to content

How to configure formkit to use the current locale of @nuxtjs/i18n #1839

Answered by ineshbose
devbrains-com asked this question in Q&A
Discussion options

You must be logged in to vote

FormKit is an incredible tool that I'm using for one of my Nuxt projects that also uses i18n. This is how you could keep locales for both modules in sync:

const { locale, locales, setLocale } = useI18n();
const fkConfig = inject(Symbol.for('FormKitConfig'));
fkConfig.locale = locale.value;

watch(locale, (newLocale) => fkConfig.locale = newLocale);

// or if you want to use click event of a button
const changeLocale = (code) => {
  fkConfig.locale = code;
  setLocale(code);
};

Keep in mind that this only uses @nuxtjs/i18n to switch locales and take preference over FormKit - not having separate switches.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@devbrains-com
Comment options

Answer selected by devbrains-com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
2 participants