123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- // Utilities
- import { computed, inject, provide, ref } from 'vue';
- import { defaultRtl } from "../locale/index.mjs";
- import { createVuetifyAdapter } from "../locale/adapters/vuetify.mjs"; // Types
- export const LocaleSymbol = Symbol.for('vuetify:locale');
- function isLocaleInstance(obj) {
- return obj.name != null;
- }
- export function createLocale(options) {
- const i18n = options?.adapter && isLocaleInstance(options?.adapter) ? options?.adapter : createVuetifyAdapter(options);
- const rtl = createRtl(i18n, options);
- return {
- ...i18n,
- ...rtl
- };
- }
- export function useLocale() {
- const locale = inject(LocaleSymbol);
- if (!locale) throw new Error('[Vuetify] Could not find injected locale instance');
- return locale;
- }
- export function provideLocale(props) {
- const locale = inject(LocaleSymbol);
- if (!locale) throw new Error('[Vuetify] Could not find injected locale instance');
- const i18n = locale.provide(props);
- const rtl = provideRtl(i18n, locale.rtl, props);
- const data = {
- ...i18n,
- ...rtl
- };
- provide(LocaleSymbol, data);
- return data;
- }
- // RTL
- export const RtlSymbol = Symbol.for('vuetify:rtl');
- export function createRtl(i18n, options) {
- const rtl = ref(options?.rtl ?? defaultRtl);
- const isRtl = computed(() => rtl.value[i18n.current.value] ?? false);
- return {
- isRtl,
- rtl,
- rtlClasses: computed(() => `v-locale--is-${isRtl.value ? 'rtl' : 'ltr'}`)
- };
- }
- export function provideRtl(locale, rtl, props) {
- const isRtl = computed(() => props.rtl ?? rtl.value[locale.current.value] ?? false);
- return {
- isRtl,
- rtl,
- rtlClasses: computed(() => `v-locale--is-${isRtl.value ? 'rtl' : 'ltr'}`)
- };
- }
- export function useRtl() {
- const locale = inject(LocaleSymbol);
- if (!locale) throw new Error('[Vuetify] Could not find injected rtl instance');
- return {
- isRtl: locale.isRtl,
- rtlClasses: locale.rtlClasses
- };
- }
- //# sourceMappingURL=locale.mjs.map
|