1 |
- {"version":3,"file":"vuetify.mjs","names":["useProxiedModel","ref","shallowRef","watch","consoleError","consoleWarn","getObjectValueByPath","en","LANG_PREFIX","replace","str","params","match","index","String","createTranslateFunction","current","fallback","messages","key","_len","arguments","length","Array","_key","startsWith","shortKey","currentLocale","value","fallbackLocale","createNumberFunction","options","numberFormat","Intl","NumberFormat","format","useProvided","props","prop","provided","internal","v","createProvideFunction","state","name","t","n","provide","createVuetifyAdapter","locale"],"sources":["../../../src/locale/adapters/vuetify.ts"],"sourcesContent":["// Composables\nimport { useProxiedModel } from '@/composables/proxiedModel'\n\n// Utilities\nimport { ref, shallowRef, watch } from 'vue'\nimport { consoleError, consoleWarn, getObjectValueByPath } from '@/util'\n\n// Locales\nimport en from '@/locale/en'\n\n// Types\nimport type { Ref } from 'vue'\nimport type { LocaleInstance, LocaleMessages, LocaleOptions } from '@/composables/locale'\n\nconst LANG_PREFIX = '$vuetify.'\n\nconst replace = (str: string, params: unknown[]) => {\n return str.replace(/\\{(\\d+)\\}/g, (match: string, index: string) => {\n return String(params[+index])\n })\n}\n\nconst createTranslateFunction = (\n current: Ref<string>,\n fallback: Ref<string>,\n messages: Ref<LocaleMessages>,\n) => {\n return (key: string, ...params: unknown[]) => {\n if (!key.startsWith(LANG_PREFIX)) {\n return replace(key, params)\n }\n\n const shortKey = key.replace(LANG_PREFIX, '')\n const currentLocale = current.value && messages.value[current.value]\n const fallbackLocale = fallback.value && messages.value[fallback.value]\n\n let str: string = getObjectValueByPath(currentLocale, shortKey, null)\n\n if (!str) {\n consoleWarn(`Translation key \"${key}\" not found in \"${current.value}\", trying fallback locale`)\n str = getObjectValueByPath(fallbackLocale, shortKey, null)\n }\n\n if (!str) {\n consoleError(`Translation key \"${key}\" not found in fallback`)\n str = key\n }\n\n if (typeof str !== 'string') {\n consoleError(`Translation key \"${key}\" has a non-string value`)\n str = key\n }\n\n return replace(str, params)\n }\n}\n\nfunction createNumberFunction (current: Ref<string>, fallback: Ref<string>) {\n return (value: number, options?: Intl.NumberFormatOptions) => {\n const numberFormat = new Intl.NumberFormat([current.value, fallback.value], options)\n\n return numberFormat.format(value)\n }\n}\n\nfunction useProvided <T> (props: any, prop: string, provided: Ref<T>) {\n const internal = useProxiedModel(props, prop, props[prop] ?? provided.value)\n\n // TODO: Remove when defaultValue works\n internal.value = props[prop] ?? provided.value\n\n watch(provided, v => {\n if (props[prop] == null) {\n internal.value = provided.value\n }\n })\n\n return internal as Ref<T>\n}\n\nfunction createProvideFunction (state: { current: Ref<string>, fallback: Ref<string>, messages: Ref<LocaleMessages> }) {\n return (props: LocaleOptions): LocaleInstance => {\n const current = useProvided(props, 'locale', state.current)\n const fallback = useProvided(props, 'fallback', state.fallback)\n const messages = useProvided(props, 'messages', state.messages)\n\n return {\n name: 'vuetify',\n current,\n fallback,\n messages,\n t: createTranslateFunction(current, fallback, messages),\n n: createNumberFunction(current, fallback),\n provide: createProvideFunction({ current, fallback, messages }),\n }\n }\n}\n\nexport function createVuetifyAdapter (options?: LocaleOptions): LocaleInstance {\n const current = shallowRef(options?.locale ?? 'en')\n const fallback = shallowRef(options?.fallback ?? 'en')\n const messages = ref({ en, ...options?.messages })\n\n return {\n name: 'vuetify',\n current,\n fallback,\n messages,\n t: createTranslateFunction(current, fallback, messages),\n n: createNumberFunction(current, fallback),\n provide: createProvideFunction({ current, fallback, messages }),\n }\n}\n"],"mappings":"AAAA;AAAA,SACSA,eAAe,8CAExB;AACA,SAASC,GAAG,EAAEC,UAAU,EAAEC,KAAK,QAAQ,KAAK;AAAA,SACnCC,YAAY,EAAEC,WAAW,EAAEC,oBAAoB,gCAExD;AAAA,OACOC,EAAE,mBAET;AAIA,MAAMC,WAAW,GAAG,WAAW;AAE/B,MAAMC,OAAO,GAAGA,CAACC,GAAW,EAAEC,MAAiB,KAAK;EAClD,OAAOD,GAAG,CAACD,OAAO,CAAC,YAAY,EAAE,CAACG,KAAa,EAAEC,KAAa,KAAK;IACjE,OAAOC,MAAM,CAACH,MAAM,CAAC,CA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