1
0
Fork 0
mirror of https://github.com/mealie-recipes/mealie.git synced 2025-07-23 15:19:41 +02:00
mealie/frontend/composables/use-locales/use-locales.ts
Hoa (Kyle) Trinh c24d532608
feat: Migrate to Nuxt 3 framework (#5184)
Co-authored-by: Michael Genson <71845777+michael-genson@users.noreply.github.com>
Co-authored-by: Kuchenpirat <24235032+Kuchenpirat@users.noreply.github.com>
2025-06-19 17:09:12 +00:00

33 lines
744 B
TypeScript

import type { LocaleObject } from "@nuxtjs/i18n";
import { LOCALES } from "./available-locales";
export const useLocales = () => {
const i18n = useI18n();
const { isRtl } = useRtl();
const { current: vuetifyLocale } = useLocale();
const locale = computed<LocaleObject["code"]>({
get: () => i18n.locale.value,
set(value) {
i18n.setLocale(value);
},
});
// auto update vuetify locale
watch(locale, (lc) => {
vuetifyLocale.value = lc;
});
// auto update rtl
watch(vuetifyLocale, (vl) => {
const currentLocale = LOCALES.find(lc => lc.value === vl);
if (currentLocale) {
isRtl.value = currentLocale.dir === "rtl";
}
});
return {
locale,
locales: LOCALES,
i18n,
};
};