mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-07-23 15:19:41 +02:00
Co-authored-by: Michael Genson <71845777+michael-genson@users.noreply.github.com> Co-authored-by: Kuchenpirat <24235032+Kuchenpirat@users.noreply.github.com>
33 lines
744 B
TypeScript
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,
|
|
};
|
|
};
|