@intlayer/vue-i18n 8.12.5-canary.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +330 -0
- package/dist/cjs/_virtual/_rolldown/runtime.cjs +29 -0
- package/dist/cjs/createI18n.cjs +215 -0
- package/dist/cjs/createI18n.cjs.map +1 -0
- package/dist/cjs/formats.cjs +31 -0
- package/dist/cjs/formats.cjs.map +1 -0
- package/dist/cjs/index.cjs +11 -0
- package/dist/cjs/plugin/index.cjs +55 -0
- package/dist/cjs/plugin/index.cjs.map +1 -0
- package/dist/cjs/resolveVueMessage.cjs +67 -0
- package/dist/cjs/resolveVueMessage.cjs.map +1 -0
- package/dist/cjs/useDictionary.cjs +47 -0
- package/dist/cjs/useDictionary.cjs.map +1 -0
- package/dist/cjs/useDictionaryDynamic.cjs +43 -0
- package/dist/cjs/useDictionaryDynamic.cjs.map +1 -0
- package/dist/cjs/useI18nDictionary.cjs +47 -0
- package/dist/cjs/useI18nDictionary.cjs.map +1 -0
- package/dist/cjs/useI18nDictionaryDynamic.cjs +43 -0
- package/dist/cjs/useI18nDictionaryDynamic.cjs.map +1 -0
- package/dist/esm/createI18n.mjs +209 -0
- package/dist/esm/createI18n.mjs.map +1 -0
- package/dist/esm/formats.mjs +28 -0
- package/dist/esm/formats.mjs.map +1 -0
- package/dist/esm/index.mjs +5 -0
- package/dist/esm/plugin/index.mjs +51 -0
- package/dist/esm/plugin/index.mjs.map +1 -0
- package/dist/esm/resolveVueMessage.mjs +62 -0
- package/dist/esm/resolveVueMessage.mjs.map +1 -0
- package/dist/esm/useDictionary.mjs +45 -0
- package/dist/esm/useDictionary.mjs.map +1 -0
- package/dist/esm/useDictionaryDynamic.mjs +41 -0
- package/dist/esm/useDictionaryDynamic.mjs.map +1 -0
- package/dist/esm/useI18nDictionary.mjs +45 -0
- package/dist/esm/useI18nDictionary.mjs.map +1 -0
- package/dist/esm/useI18nDictionaryDynamic.mjs +41 -0
- package/dist/esm/useI18nDictionaryDynamic.mjs.map +1 -0
- package/dist/types/createI18n.d.ts +41 -0
- package/dist/types/createI18n.d.ts.map +1 -0
- package/dist/types/formats.d.ts +17 -0
- package/dist/types/formats.d.ts.map +1 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/plugin/index.d.ts +12 -0
- package/dist/types/plugin/index.d.ts.map +1 -0
- package/dist/types/resolveVueMessage.d.ts +37 -0
- package/dist/types/resolveVueMessage.d.ts.map +1 -0
- package/dist/types/useDictionary.d.ts +22 -0
- package/dist/types/useDictionary.d.ts.map +1 -0
- package/dist/types/useDictionaryDynamic.d.ts +19 -0
- package/dist/types/useDictionaryDynamic.d.ts.map +1 -0
- package/dist/types/useI18nDictionary.d.ts +22 -0
- package/dist/types/useI18nDictionary.d.ts.map +1 -0
- package/dist/types/useI18nDictionaryDynamic.d.ts +19 -0
- package/dist/types/useI18nDictionaryDynamic.d.ts.map +1 -0
- package/package.json +114 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createI18n.cjs","names":["parseTranslateArguments","resolveVueMessage","internationalization","ANSIColors","formatDateValue","formatNumberValue"],"sources":["../../src/createI18n.ts"],"sourcesContent":["import { internationalization, log } from '@intlayer/config/built';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport { getIntlayer } from '@intlayer/core/interpreter';\nimport type { ValidDotPathsFor } from '@intlayer/core/transpiler';\nimport type {\n DictionaryKeys,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport type {\n App,\n DirectiveBinding,\n InjectionKey,\n WritableComputedRef,\n} from 'vue';\nimport { computed } from 'vue';\nimport type { createI18n as _createI18n, I18n } from 'vue-i18n';\nimport { createIntlayerClient, installIntlayer, useLocale } from 'vue-intlayer';\nimport {\n type DateTimeFormatsConfig,\n formatDateValue,\n formatNumberValue,\n type NumberFormatsConfig,\n} from './formats';\nimport {\n parseTranslateArguments,\n resolveVueMessage,\n} from './resolveVueMessage';\n\nexport const VERSION = '9.13.1';\nexport const I18nInjectionKey: InjectionKey<I18n> = Symbol('global-i18n');\n\nconst DEFAULT_NAMESPACE = 'translation';\n\nconst navigatePath = (objectValue: unknown, path: string): unknown => {\n if (!path) return objectValue;\n let current: unknown = objectValue;\n for (const part of path.split('.')) {\n if (\n current === null ||\n current === undefined ||\n typeof current !== 'object'\n ) {\n return undefined;\n }\n current = (current as Record<string, unknown>)[part];\n }\n return current;\n};\n\n/**\n * Looks up a raw value for a vue-i18n key against intlayer dictionaries.\n *\n * Resolution order:\n * 1. `ns:key` prefix → dictionary `ns`\n * 2. The default namespace dictionary with the full dot-path\n * 3. The first key segment as the dictionary key (`'home.title'` →\n * dictionary `home`, path `title`)\n */\nconst lookupRaw = (locale: string, namespace: string, key: string): unknown => {\n let targetNamespace = namespace;\n let path = key;\n\n if (key.includes(':')) {\n const separatorIndex = key.indexOf(':');\n targetNamespace = key.slice(0, separatorIndex);\n path = key.slice(separatorIndex + 1);\n }\n\n try {\n const dictionary = getIntlayer(\n targetNamespace as DictionaryKeys,\n locale as LocalesValues\n );\n const value = navigatePath(dictionary, path);\n if (value !== undefined && value !== null) return value;\n } catch {}\n\n if (path.includes('.')) {\n const separatorIndex = path.indexOf('.');\n const firstSegment = path.slice(0, separatorIndex);\n const restPath = path.slice(separatorIndex + 1);\n try {\n const dictionary = getIntlayer(\n firstSegment as DictionaryKeys,\n locale as LocalesValues\n );\n const value = navigatePath(dictionary, restPath);\n if (value !== undefined && value !== null) return value;\n } catch {}\n }\n\n return undefined;\n};\n\n/** Translates a key with vue-i18n's polymorphic argument list. */\nconst translateKey = (\n locale: string,\n namespace: string,\n key: string,\n args: unknown[]\n): string => {\n const { values, count, defaultMessage } = parseTranslateArguments(args);\n\n const rawValue = lookupRaw(locale, namespace, key);\n\n if (rawValue === undefined) {\n if (defaultMessage !== undefined) {\n return resolveVueMessage(\n defaultMessage,\n values,\n count,\n locale as LocalesValues\n );\n }\n return key;\n }\n\n return resolveVueMessage(rawValue, values, count, locale as LocalesValues);\n};\n\nconst getAvailableLocales = (): string[] =>\n internationalization?.locales?.map(String) ?? [];\n\nconst warnDeprecatedRuntimeMessages = (location: string) => {\n const appLogger = getAppLogger({ log });\n appLogger(\n `${colorize(location, ANSIColors.CYAN)} has no effect with ${colorize('@intlayer/vue-i18n', ANSIColors.MAGENTA)} — translations are managed by the compiled intlayer dictionaries.`\n );\n};\n\n/** Value accepted by the `v-t` directive. */\ntype TranslateDirectiveValue =\n | string\n | { path: string; args?: Record<string, unknown>; choice?: number };\n\nexport const createI18n = ((options: Record<string, unknown> = {}) => {\n if (options.messages !== undefined) {\n const appLogger = getAppLogger({ log });\n appLogger(\n `${colorize('createI18n', ANSIColors.CYAN)}: the ${colorize('`messages`', ANSIColors.CYAN)} option is ignored when using ${colorize('@intlayer/vue-i18n', ANSIColors.MAGENTA)} — translations are served from the compiled intlayer dictionaries instead. Remove the locale JSON imports and the ${colorize('`messages`', ANSIColors.CYAN)} option to reduce your bundle size:\\n ${colorize('Before:', ANSIColors.GREY)} createI18n({ messages: { en, fr, … } })\\n ${colorize('After: ', ANSIColors.GREY)} createI18n({})`\n );\n }\n\n const client = createIntlayerClient(options.locale as LocalesValues);\n\n const datetimeFormats = options.datetimeFormats as\n | DateTimeFormatsConfig\n | undefined;\n const numberFormats = options.numberFormats as\n | NumberFormatsConfig\n | undefined;\n\n const currentLocale = (): string => String(client.locale.value);\n\n /** Writable ref matching vue-i18n's composition-mode `global.locale`. */\n const localeRef: WritableComputedRef<string> = computed({\n get: () => currentLocale(),\n set: (newLocale: string) => {\n client.setLocale(newLocale as LocalesValues);\n },\n });\n\n const globalTranslate = (key: string, ...args: unknown[]): string =>\n translateKey(currentLocale(), DEFAULT_NAMESPACE, key, args);\n\n const globalDate = (\n value: Date | number | string,\n formatOrOptions?: string | Intl.DateTimeFormatOptions\n ): string =>\n formatDateValue(value, formatOrOptions, currentLocale(), datetimeFormats);\n\n const globalNumber = (\n value: number,\n formatOrOptions?: string | Intl.NumberFormatOptions\n ): string =>\n formatNumberValue(value, formatOrOptions, currentLocale(), numberFormats);\n\n const global = {\n locale: localeRef,\n availableLocales: getAvailableLocales(),\n fallbackLocale: (options.fallbackLocale ??\n internationalization?.defaultLocale) as string,\n t: globalTranslate,\n tc: globalTranslate,\n te: (key: string): boolean =>\n lookupRaw(currentLocale(), DEFAULT_NAMESPACE, key) !== undefined,\n tm: (key: string): unknown =>\n lookupRaw(currentLocale(), DEFAULT_NAMESPACE, key) ?? {},\n rt: (message: unknown, ...args: unknown[]): string => {\n const { values, count } = parseTranslateArguments(args);\n return resolveVueMessage(\n message,\n values,\n count,\n currentLocale() as LocalesValues\n );\n },\n d: globalDate,\n n: globalNumber,\n setLocaleMessage: (_locale: string, _messages: unknown) => {\n warnDeprecatedRuntimeMessages('setLocaleMessage');\n },\n mergeLocaleMessage: (_locale: string, _messages: unknown) => {\n warnDeprecatedRuntimeMessages('mergeLocaleMessage');\n },\n getLocaleMessage: (locale: string): unknown => {\n try {\n return getIntlayer(\n DEFAULT_NAMESPACE as DictionaryKeys,\n locale as LocalesValues\n );\n } catch {\n return {};\n }\n },\n };\n\n /** Legacy Options-API facade (`this.$i18n`) with a string `locale`. */\n const legacyI18n = {\n get locale(): string {\n return currentLocale();\n },\n set locale(newLocale: string) {\n client.setLocale(newLocale as LocalesValues);\n },\n get availableLocales(): string[] {\n return getAvailableLocales();\n },\n t: globalTranslate,\n tc: globalTranslate,\n te: global.te,\n tm: global.tm,\n rt: global.rt,\n d: globalDate,\n n: globalNumber,\n };\n\n const applyTranslateDirective = (\n element: HTMLElement,\n binding: DirectiveBinding<TranslateDirectiveValue>\n ) => {\n const bindingValue = binding.value;\n if (typeof bindingValue === 'string') {\n element.textContent = globalTranslate(bindingValue);\n } else if (bindingValue && typeof bindingValue === 'object') {\n const directiveArgs: unknown[] = [];\n if (bindingValue.args) directiveArgs.push(bindingValue.args);\n if (typeof bindingValue.choice === 'number')\n directiveArgs.push(bindingValue.choice);\n element.textContent = globalTranslate(\n bindingValue.path,\n ...directiveArgs\n );\n }\n };\n\n const i18nInstance = {\n global,\n mode: options.legacy === true ? 'legacy' : 'composition',\n install(app: App) {\n installIntlayer(app, {\n locale: options.locale as LocalesValues,\n });\n\n // Provide under I18nInjectionKey to satisfy inject(I18nInjectionKey) calls\n app.provide(I18nInjectionKey, i18nInstance as unknown as I18n);\n\n // Legacy API support ($t / $tc / $te / $tm / $rt / $d / $n / $i18n)\n app.config.globalProperties.$t = globalTranslate;\n (app.config.globalProperties as Record<string, unknown>).$tc =\n globalTranslate;\n (app.config.globalProperties as Record<string, unknown>).$te = global.te;\n (app.config.globalProperties as Record<string, unknown>).$tm = global.tm;\n (app.config.globalProperties as Record<string, unknown>).$rt = global.rt;\n (app.config.globalProperties as Record<string, unknown>).$d = globalDate;\n (app.config.globalProperties as Record<string, unknown>).$n =\n globalNumber;\n (app.config.globalProperties as Record<string, unknown>).$i18n =\n legacyI18n;\n\n // `v-t` directive support\n app.directive('t', {\n beforeMount: applyTranslateDirective,\n updated: applyTranslateDirective,\n });\n },\n };\n\n return i18nInstance as unknown as I18n;\n}) as typeof _createI18n;\n\n/**\n * Composable providing a typed `t()` function scoped to a dictionary namespace.\n * Pass `{ namespace: 'myDict' }` to restrict keys to valid dot-notation paths\n * within that intlayer dictionary (autocompleted and validated at compile time).\n *\n * Supports vue-i18n's full message syntax: named (`{name}`) and list (`{0}`)\n * interpolation, pipe choice messages (`'car | cars'` with a count argument),\n * plus `te`/`tm`/`rt` and `Intl`-backed `d()`/`n()` formatters.\n *\n * @example\n * ```ts\n * const { t } = useI18n({ namespace: 'about' });\n * t('counter.label'); // ✓ typed; compile error if key doesn't exist\n * t('apples', 5); // pipe plural choice\n * ```\n */\nexport const useI18n = <N extends DictionaryKeys = DictionaryKeys>(\n options?: Record<string, unknown> & { namespace?: N }\n): {\n locale: WritableComputedRef<string>;\n availableLocales: string[];\n t: <P extends ValidDotPathsFor<N>>(key: P, ...args: unknown[]) => string;\n tc: <P extends ValidDotPathsFor<N>>(key: P, ...args: unknown[]) => string;\n te: <P extends ValidDotPathsFor<N>>(key: P) => boolean;\n tm: <P extends ValidDotPathsFor<N>>(key: P) => unknown;\n rt: (message: unknown, ...args: unknown[]) => string;\n d: (\n value: Date | number | string,\n formatOrOptions?: string | Intl.DateTimeFormatOptions\n ) => string;\n n: (\n value: number,\n formatOrOptions?: string | Intl.NumberFormatOptions\n ) => string;\n} => {\n const { locale: currentLocale, setLocale, availableLocales } = useLocale();\n\n const namespace = ((options?.namespace as string) ?? DEFAULT_NAMESPACE) as N;\n\n const datetimeFormats = options?.datetimeFormats as\n | DateTimeFormatsConfig\n | undefined;\n const numberFormats = options?.numberFormats as\n | NumberFormatsConfig\n | undefined;\n\n const localeRef = computed({\n get: () => currentLocale.value as string,\n set: (newLocale: string) => {\n setLocale(newLocale as LocalesValues);\n },\n });\n\n const translate = <P extends ValidDotPathsFor<N>>(\n key: P,\n ...args: unknown[]\n ): string => translateKey(currentLocale.value, namespace, String(key), args);\n\n return {\n locale: localeRef,\n availableLocales: availableLocales as string[],\n t: translate,\n tc: translate,\n te: <P extends ValidDotPathsFor<N>>(key: P): boolean =>\n lookupRaw(currentLocale.value, namespace, String(key)) !== undefined,\n tm: <P extends ValidDotPathsFor<N>>(key: P): unknown =>\n lookupRaw(currentLocale.value, namespace, String(key)) ?? {},\n rt: (message: unknown, ...args: unknown[]): string => {\n const { values, count } = parseTranslateArguments(args);\n return resolveVueMessage(\n message,\n values,\n count,\n currentLocale.value as LocalesValues\n );\n },\n d: (\n value: Date | number | string,\n formatOrOptions?: string | Intl.DateTimeFormatOptions\n ): string =>\n formatDateValue(\n value,\n formatOrOptions,\n currentLocale.value,\n datetimeFormats\n ),\n n: (\n value: number,\n formatOrOptions?: string | Intl.NumberFormatOptions\n ): string =>\n formatNumberValue(\n value,\n formatOrOptions,\n currentLocale.value,\n numberFormats\n ),\n };\n};\n"],"mappings":"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"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
|
|
3
|
+
//#region src/formats.ts
|
|
4
|
+
const resolveNamedOptions = (formatOrOptions, locale, namedFormats) => {
|
|
5
|
+
if (typeof formatOrOptions === "string") return namedFormats?.[locale]?.[formatOrOptions] ?? namedFormats?.[locale.split("-")[0]]?.[formatOrOptions];
|
|
6
|
+
return formatOrOptions;
|
|
7
|
+
};
|
|
8
|
+
/** Formats a date value like vue-i18n's `d()`. */
|
|
9
|
+
const formatDateValue = (value, formatOrOptions, locale, datetimeFormats) => {
|
|
10
|
+
const dateValue = value instanceof Date ? value : new Date(value);
|
|
11
|
+
const options = resolveNamedOptions(formatOrOptions, locale, datetimeFormats);
|
|
12
|
+
try {
|
|
13
|
+
return new Intl.DateTimeFormat(locale, options).format(dateValue);
|
|
14
|
+
} catch {
|
|
15
|
+
return String(value);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
/** Formats a number value like vue-i18n's `n()`. */
|
|
19
|
+
const formatNumberValue = (value, formatOrOptions, locale, numberFormats) => {
|
|
20
|
+
const options = resolveNamedOptions(formatOrOptions, locale, numberFormats);
|
|
21
|
+
try {
|
|
22
|
+
return new Intl.NumberFormat(locale, options).format(value);
|
|
23
|
+
} catch {
|
|
24
|
+
return String(value);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
exports.formatDateValue = formatDateValue;
|
|
30
|
+
exports.formatNumberValue = formatNumberValue;
|
|
31
|
+
//# sourceMappingURL=formats.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formats.cjs","names":[],"sources":["../../src/formats.ts"],"sourcesContent":["/**\n * Locale-aware `d()` / `n()` formatting backed by the native `Intl.*` APIs,\n * honoring the `datetimeFormats` / `numberFormats` maps from `createI18n`\n * options (vue-i18n named formats).\n */\n\n/** vue-i18n `datetimeFormats` option shape: locale → format name → options. */\nexport type DateTimeFormatsConfig = Record<\n string,\n Record<string, Intl.DateTimeFormatOptions>\n>;\n\n/** vue-i18n `numberFormats` option shape: locale → format name → options. */\nexport type NumberFormatsConfig = Record<\n string,\n Record<string, Intl.NumberFormatOptions>\n>;\n\nconst resolveNamedOptions = <FormatOptions>(\n formatOrOptions: string | FormatOptions | undefined,\n locale: string,\n namedFormats: Record<string, Record<string, FormatOptions>> | undefined\n): FormatOptions | undefined => {\n if (typeof formatOrOptions === 'string') {\n return (\n namedFormats?.[locale]?.[formatOrOptions] ??\n // Fall back to the base language entry (`'en'` for `'en-GB'`)\n namedFormats?.[locale.split('-')[0]]?.[formatOrOptions]\n );\n }\n return formatOrOptions;\n};\n\n/** Formats a date value like vue-i18n's `d()`. */\nexport const formatDateValue = (\n value: Date | number | string,\n formatOrOptions: string | Intl.DateTimeFormatOptions | undefined,\n locale: string,\n datetimeFormats?: DateTimeFormatsConfig\n): string => {\n const dateValue = value instanceof Date ? value : new Date(value);\n const options = resolveNamedOptions(formatOrOptions, locale, datetimeFormats);\n\n try {\n return new Intl.DateTimeFormat(locale, options).format(dateValue);\n } catch {\n return String(value);\n }\n};\n\n/** Formats a number value like vue-i18n's `n()`. */\nexport const formatNumberValue = (\n value: number,\n formatOrOptions: string | Intl.NumberFormatOptions | undefined,\n locale: string,\n numberFormats?: NumberFormatsConfig\n): string => {\n const options = resolveNamedOptions(formatOrOptions, locale, numberFormats);\n\n try {\n return new Intl.NumberFormat(locale, options).format(value);\n } catch {\n return String(value);\n }\n};\n"],"mappings":";;;AAkBA,MAAM,uBACJ,iBACA,QACA,iBAC8B;AAC9B,KAAI,OAAO,oBAAoB,SAC7B,QACE,eAAe,UAAU,oBAEzB,eAAe,OAAO,MAAM,IAAI,CAAC,MAAM;AAG3C,QAAO;;;AAIT,MAAa,mBACX,OACA,iBACA,QACA,oBACW;CACX,MAAM,YAAY,iBAAiB,OAAO,QAAQ,IAAI,KAAK,MAAM;CACjE,MAAM,UAAU,oBAAoB,iBAAiB,QAAQ,gBAAgB;AAE7E,KAAI;AACF,SAAO,IAAI,KAAK,eAAe,QAAQ,QAAQ,CAAC,OAAO,UAAU;SAC3D;AACN,SAAO,OAAO,MAAM;;;;AAKxB,MAAa,qBACX,OACA,iBACA,QACA,kBACW;CACX,MAAM,UAAU,oBAAoB,iBAAiB,QAAQ,cAAc;AAE3E,KAAI;AACF,SAAO,IAAI,KAAK,aAAa,QAAQ,QAAQ,CAAC,OAAO,MAAM;SACrD;AACN,SAAO,OAAO,MAAM"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_createI18n = require('./createI18n.cjs');
|
|
3
|
+
const require_useDictionaryDynamic = require('./useDictionaryDynamic.cjs');
|
|
4
|
+
const require_useDictionary = require('./useDictionary.cjs');
|
|
5
|
+
|
|
6
|
+
exports.I18nInjectionKey = require_createI18n.I18nInjectionKey;
|
|
7
|
+
exports.VERSION = require_createI18n.VERSION;
|
|
8
|
+
exports.createI18n = require_createI18n.createI18n;
|
|
9
|
+
exports.useDictionary = require_useDictionary.useDictionary;
|
|
10
|
+
exports.useDictionaryDynamic = require_useDictionaryDynamic.useDictionaryDynamic;
|
|
11
|
+
exports.useI18n = require_createI18n.useI18n;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
2
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
let _intlayer_config_colors = require("@intlayer/config/colors");
|
|
4
|
+
_intlayer_config_colors = require_runtime.__toESM(_intlayer_config_colors);
|
|
5
|
+
let _intlayer_config_logger = require("@intlayer/config/logger");
|
|
6
|
+
let node_path = require("node:path");
|
|
7
|
+
let _intlayer_chokidar_utils = require("@intlayer/chokidar/utils");
|
|
8
|
+
let _intlayer_config_node = require("@intlayer/config/node");
|
|
9
|
+
let vite_intlayer = require("vite-intlayer");
|
|
10
|
+
|
|
11
|
+
//#region src/plugin/index.ts
|
|
12
|
+
/**
|
|
13
|
+
* Caller configurations for vue-i18n's `useI18n` composable.
|
|
14
|
+
*
|
|
15
|
+
* Tells the intlayer field-usage analyser how to extract the dictionary key
|
|
16
|
+
* (namespace) from `useI18n({ namespace: 'ns' })` call sites, enabling
|
|
17
|
+
* accurate dictionary pruning for projects using `@intlayer/vue-i18n`.
|
|
18
|
+
*/
|
|
19
|
+
const VUE_I18N_COMPAT_CALLERS = [{
|
|
20
|
+
callerName: "useI18n",
|
|
21
|
+
importSources: ["vue-i18n", "@intlayer/vue-i18n"],
|
|
22
|
+
namespace: {
|
|
23
|
+
from: "option",
|
|
24
|
+
argumentIndex: 0,
|
|
25
|
+
property: "namespace"
|
|
26
|
+
},
|
|
27
|
+
translationFunction: "destructured-t"
|
|
28
|
+
}];
|
|
29
|
+
/**
|
|
30
|
+
* A Vite plugin for vue-i18n compat that wraps vite-intlayer
|
|
31
|
+
* and configures resolve aliases for vue-i18n.
|
|
32
|
+
*/
|
|
33
|
+
const vueI18nVitePlugin = (options) => {
|
|
34
|
+
const intlayerConfig = (0, _intlayer_config_node.getConfiguration)();
|
|
35
|
+
const appLogger = (0, _intlayer_config_logger.getAppLogger)(intlayerConfig);
|
|
36
|
+
(0, _intlayer_chokidar_utils.runOnce)((0, node_path.join)(intlayerConfig.system.baseDir, ".intlayer", "cache", "intlayer-issues-invitation.lock"), () => {
|
|
37
|
+
appLogger([(0, _intlayer_config_logger.colorize)("Please report any issues you met on GitHub:", _intlayer_config_colors.GREY), (0, _intlayer_config_logger.colorize)("https://github.com/aymericzip/intlayer/issues", _intlayer_config_colors.GREY_LIGHT)]);
|
|
38
|
+
}, { cacheTimeoutMs: 1e3 * 60 * 60 });
|
|
39
|
+
const basePlugins = (0, vite_intlayer.intlayer)({
|
|
40
|
+
...options,
|
|
41
|
+
compatCallers: [...options?.compatCallers ?? [], ...VUE_I18N_COMPAT_CALLERS]
|
|
42
|
+
});
|
|
43
|
+
const compatPlugin = {
|
|
44
|
+
name: "vite-vue-i18n-compat-plugin",
|
|
45
|
+
config: () => {
|
|
46
|
+
return { resolve: { alias: { "vue-i18n": "@intlayer/vue-i18n" } } };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
return [...Array.isArray(basePlugins) ? basePlugins : [basePlugins], compatPlugin];
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
//#endregion
|
|
53
|
+
exports.default = vueI18nVitePlugin;
|
|
54
|
+
exports.vueI18nVitePlugin = vueI18nVitePlugin;
|
|
55
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["ANSIColors"],"sources":["../../../src/plugin/index.ts"],"sourcesContent":["import { join } from 'node:path';\nimport { runOnce } from '@intlayer/chokidar/utils';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport { getConfiguration } from '@intlayer/config/node';\nimport type { PluginOption } from 'vite';\nimport { type CompatCallerConfig, intlayer } from 'vite-intlayer';\n\n/**\n * Caller configurations for vue-i18n's `useI18n` composable.\n *\n * Tells the intlayer field-usage analyser how to extract the dictionary key\n * (namespace) from `useI18n({ namespace: 'ns' })` call sites, enabling\n * accurate dictionary pruning for projects using `@intlayer/vue-i18n`.\n */\nconst VUE_I18N_COMPAT_CALLERS: CompatCallerConfig[] = [\n {\n callerName: 'useI18n',\n importSources: ['vue-i18n', '@intlayer/vue-i18n'],\n namespace: { from: 'option', argumentIndex: 0, property: 'namespace' },\n translationFunction: 'destructured-t',\n },\n];\n\n/**\n * A Vite plugin for vue-i18n compat that wraps vite-intlayer\n * and configures resolve aliases for vue-i18n.\n */\nexport const vueI18nVitePlugin = (\n options?: Parameters<typeof intlayer>[0]\n): PluginOption[] => {\n const intlayerConfig = getConfiguration();\n const appLogger = getAppLogger(intlayerConfig);\n\n runOnce(\n join(\n intlayerConfig.system.baseDir,\n '.intlayer',\n 'cache',\n 'intlayer-issues-invitation.lock'\n ),\n () => {\n appLogger([\n colorize(\n 'Please report any issues you met on GitHub:',\n ANSIColors.GREY\n ),\n colorize(\n 'https://github.com/aymericzip/intlayer/issues',\n ANSIColors.GREY_LIGHT\n ),\n ]);\n },\n {\n cacheTimeoutMs: 1000 * 60 * 60, // 1 hour\n }\n );\n\n const basePlugins = intlayer({\n ...options,\n compatCallers: [\n ...(options?.compatCallers ?? []),\n ...VUE_I18N_COMPAT_CALLERS,\n ],\n });\n\n const compatPlugin: PluginOption = {\n name: 'vite-vue-i18n-compat-plugin',\n config: () => {\n return {\n resolve: {\n alias: {\n 'vue-i18n': '@intlayer/vue-i18n',\n },\n },\n };\n },\n };\n\n return [\n ...(Array.isArray(basePlugins) ? basePlugins : [basePlugins]),\n compatPlugin,\n ];\n};\n\nexport default vueI18nVitePlugin;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAeA,MAAM,0BAAgD,CACpD;CACE,YAAY;CACZ,eAAe,CAAC,YAAY,qBAAqB;CACjD,WAAW;EAAE,MAAM;EAAU,eAAe;EAAG,UAAU;EAAa;CACtE,qBAAqB;CACtB,CACF;;;;;AAMD,MAAa,qBACX,YACmB;CACnB,MAAM,8DAAmC;CACzC,MAAM,sDAAyB,eAAe;AAE9C,2DAEI,eAAe,OAAO,SACtB,aACA,SACA,kCACD,QACK;AACJ,YAAU,uCAEN,+CACAA,wBAAW,KACZ,wCAEC,iDACAA,wBAAW,WACZ,CACF,CAAC;IAEJ,EACE,gBAAgB,MAAO,KAAK,IAC7B,CACF;CAED,MAAM,0CAAuB;EAC3B,GAAG;EACH,eAAe,CACb,GAAI,SAAS,iBAAiB,EAAE,EAChC,GAAG,wBACJ;EACF,CAAC;CAEF,MAAM,eAA6B;EACjC,MAAM;EACN,cAAc;AACZ,UAAO,EACL,SAAS,EACP,OAAO,EACL,YAAY,sBACb,EACF,EACF;;EAEJ;AAED,QAAO,CACL,GAAI,MAAM,QAAQ,YAAY,GAAG,cAAc,CAAC,YAAY,EAC5D,aACD"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
let _intlayer_core_messageFormat = require("@intlayer/core/messageFormat");
|
|
4
|
+
|
|
5
|
+
//#region src/resolveVueMessage.ts
|
|
6
|
+
/**
|
|
7
|
+
* Splits a vue-i18n choice message (`'no car | one car | {count} cars'`)
|
|
8
|
+
* into its parts, honoring escaped pipes (`\|`).
|
|
9
|
+
*/
|
|
10
|
+
const splitChoices = (message) => message.split(/(?<!\\)\|/).map((part) => part.replace(/\\\|/g, "|").trim());
|
|
11
|
+
/**
|
|
12
|
+
* vue-i18n's default choice rule:
|
|
13
|
+
* - 2 choices: `1 | other` — 0 picks `other`, 1 picks the first part
|
|
14
|
+
* - 3+ choices: `0 | 1 | other`
|
|
15
|
+
*/
|
|
16
|
+
const getChoiceIndex = (choice, choicesLength) => {
|
|
17
|
+
const absoluteChoice = Math.abs(choice);
|
|
18
|
+
if (choicesLength === 2) return absoluteChoice ? absoluteChoice > 1 ? 1 : 0 : 1;
|
|
19
|
+
return absoluteChoice ? Math.min(absoluteChoice, 2) : 0;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Parses vue-i18n's polymorphic `t()` arguments:
|
|
23
|
+
* `t(key)`, `t(key, count)`, `t(key, defaultMsg)`, `t(key, list)`,
|
|
24
|
+
* `t(key, named)`, `t(key, named, count)`, `t(key, list, count)`, …
|
|
25
|
+
*/
|
|
26
|
+
const parseTranslateArguments = (args) => {
|
|
27
|
+
const parsed = { values: {} };
|
|
28
|
+
for (const arg of args) if (typeof arg === "number") parsed.count = arg;
|
|
29
|
+
else if (typeof arg === "string") parsed.defaultMessage = arg;
|
|
30
|
+
else if (Array.isArray(arg)) parsed.values = { ...arg.map(String) };
|
|
31
|
+
else if (typeof arg === "object" && arg !== null) {
|
|
32
|
+
const objectArg = arg;
|
|
33
|
+
parsed.values = objectArg;
|
|
34
|
+
if (typeof objectArg.plural === "number") parsed.count = objectArg.plural;
|
|
35
|
+
}
|
|
36
|
+
return parsed;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Resolves a raw dictionary value the vue-i18n way: pipe-separated choice
|
|
40
|
+
* messages (positional rule, not CLDR), named `{name}` and list `{0}`
|
|
41
|
+
* interpolation, and intlayer nodes (`insert`, `plural`, `enu`) produced by
|
|
42
|
+
* dictionaries built with `format: 'vue-i18n'`.
|
|
43
|
+
*/
|
|
44
|
+
const resolveVueMessage = (value, values, count, locale) => {
|
|
45
|
+
const interpolationValues = { ...values };
|
|
46
|
+
if (count !== void 0) {
|
|
47
|
+
interpolationValues.count ??= count;
|
|
48
|
+
interpolationValues.n ??= count;
|
|
49
|
+
}
|
|
50
|
+
if (typeof value === "string") {
|
|
51
|
+
let message = value;
|
|
52
|
+
if (/(?<!\\)\|/.test(message)) {
|
|
53
|
+
const parts = splitChoices(message);
|
|
54
|
+
message = parts[getChoiceIndex(count ?? 1, parts.length)] ?? message;
|
|
55
|
+
}
|
|
56
|
+
return (0, _intlayer_core_messageFormat.interpolateMessage)(message, interpolationValues, locale);
|
|
57
|
+
}
|
|
58
|
+
const resolved = (0, _intlayer_core_messageFormat.resolveMessageNode)(value, interpolationValues, locale);
|
|
59
|
+
return typeof resolved === "string" ? resolved : String(resolved ?? "");
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
//#endregion
|
|
63
|
+
exports.getChoiceIndex = getChoiceIndex;
|
|
64
|
+
exports.parseTranslateArguments = parseTranslateArguments;
|
|
65
|
+
exports.resolveVueMessage = resolveVueMessage;
|
|
66
|
+
exports.splitChoices = splitChoices;
|
|
67
|
+
//# sourceMappingURL=resolveVueMessage.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveVueMessage.cjs","names":[],"sources":["../../src/resolveVueMessage.ts"],"sourcesContent":["import {\n interpolateMessage,\n type MessageValues,\n resolveMessageNode,\n} from '@intlayer/core/messageFormat';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\n\n/**\n * Splits a vue-i18n choice message (`'no car | one car | {count} cars'`)\n * into its parts, honoring escaped pipes (`\\|`).\n */\nexport const splitChoices = (message: string): string[] =>\n message.split(/(?<!\\\\)\\|/).map((part) => part.replace(/\\\\\\|/g, '|').trim());\n\n/**\n * vue-i18n's default choice rule:\n * - 2 choices: `1 | other` — 0 picks `other`, 1 picks the first part\n * - 3+ choices: `0 | 1 | other`\n */\nexport const getChoiceIndex = (\n choice: number,\n choicesLength: number\n): number => {\n const absoluteChoice = Math.abs(choice);\n\n if (choicesLength === 2) {\n return absoluteChoice ? (absoluteChoice > 1 ? 1 : 0) : 1;\n }\n\n return absoluteChoice ? Math.min(absoluteChoice, 2) : 0;\n};\n\n/** Arguments parsed from vue-i18n's polymorphic `t()` signatures. */\nexport type ParsedTranslateArguments = {\n /** Named (`{name}`) or list (`{0}`) interpolation values. */\n values: MessageValues;\n /** Plural choice count, when a number argument was provided. */\n count?: number;\n /** Default message, when a string argument was provided. */\n defaultMessage?: string;\n};\n\n/**\n * Parses vue-i18n's polymorphic `t()` arguments:\n * `t(key)`, `t(key, count)`, `t(key, defaultMsg)`, `t(key, list)`,\n * `t(key, named)`, `t(key, named, count)`, `t(key, list, count)`, …\n */\nexport const parseTranslateArguments = (\n args: unknown[]\n): ParsedTranslateArguments => {\n const parsed: ParsedTranslateArguments = { values: {} };\n\n for (const arg of args) {\n if (typeof arg === 'number') {\n parsed.count = arg;\n } else if (typeof arg === 'string') {\n parsed.defaultMessage = arg;\n } else if (Array.isArray(arg)) {\n // List interpolation: ['a', 'b'] → { 0: 'a', 1: 'b' }\n parsed.values = { ...arg.map(String) } as unknown as MessageValues;\n } else if (typeof arg === 'object' && arg !== null) {\n const objectArg = arg as MessageValues & { plural?: number };\n parsed.values = objectArg;\n if (typeof objectArg.plural === 'number') {\n parsed.count = objectArg.plural;\n }\n }\n }\n\n return parsed;\n};\n\n/**\n * Resolves a raw dictionary value the vue-i18n way: pipe-separated choice\n * messages (positional rule, not CLDR), named `{name}` and list `{0}`\n * interpolation, and intlayer nodes (`insert`, `plural`, `enu`) produced by\n * dictionaries built with `format: 'vue-i18n'`.\n */\nexport const resolveVueMessage = (\n value: unknown,\n values: MessageValues,\n count: number | undefined,\n locale: LocalesValues\n): string => {\n const interpolationValues: MessageValues = { ...values };\n if (count !== undefined) {\n interpolationValues.count ??= count;\n interpolationValues.n ??= count;\n }\n\n if (typeof value === 'string') {\n let message = value;\n\n if (/(?<!\\\\)\\|/.test(message)) {\n const parts = splitChoices(message);\n message = parts[getChoiceIndex(count ?? 1, parts.length)] ?? message;\n }\n\n return interpolateMessage(message, interpolationValues, locale);\n }\n\n const resolved = resolveMessageNode(value, interpolationValues, locale);\n\n return typeof resolved === 'string' ? resolved : String(resolved ?? '');\n};\n"],"mappings":";;;;;;;;;AAWA,MAAa,gBAAgB,YAC3B,QAAQ,MAAM,YAAY,CAAC,KAAK,SAAS,KAAK,QAAQ,SAAS,IAAI,CAAC,MAAM,CAAC;;;;;;AAO7E,MAAa,kBACX,QACA,kBACW;CACX,MAAM,iBAAiB,KAAK,IAAI,OAAO;AAEvC,KAAI,kBAAkB,EACpB,QAAO,iBAAkB,iBAAiB,IAAI,IAAI,IAAK;AAGzD,QAAO,iBAAiB,KAAK,IAAI,gBAAgB,EAAE,GAAG;;;;;;;AAkBxD,MAAa,2BACX,SAC6B;CAC7B,MAAM,SAAmC,EAAE,QAAQ,EAAE,EAAE;AAEvD,MAAK,MAAM,OAAO,KAChB,KAAI,OAAO,QAAQ,SACjB,QAAO,QAAQ;UACN,OAAO,QAAQ,SACxB,QAAO,iBAAiB;UACf,MAAM,QAAQ,IAAI,CAE3B,QAAO,SAAS,EAAE,GAAG,IAAI,IAAI,OAAO,EAAE;UAC7B,OAAO,QAAQ,YAAY,QAAQ,MAAM;EAClD,MAAM,YAAY;AAClB,SAAO,SAAS;AAChB,MAAI,OAAO,UAAU,WAAW,SAC9B,QAAO,QAAQ,UAAU;;AAK/B,QAAO;;;;;;;;AAST,MAAa,qBACX,OACA,QACA,OACA,WACW;CACX,MAAM,sBAAqC,EAAE,GAAG,QAAQ;AACxD,KAAI,UAAU,QAAW;AACvB,sBAAoB,UAAU;AAC9B,sBAAoB,MAAM;;AAG5B,KAAI,OAAO,UAAU,UAAU;EAC7B,IAAI,UAAU;AAEd,MAAI,YAAY,KAAK,QAAQ,EAAE;GAC7B,MAAM,QAAQ,aAAa,QAAQ;AACnC,aAAU,MAAM,eAAe,SAAS,GAAG,MAAM,OAAO,KAAK;;AAG/D,8DAA0B,SAAS,qBAAqB,OAAO;;CAGjE,MAAM,gEAA8B,OAAO,qBAAqB,OAAO;AAEvE,QAAO,OAAO,aAAa,WAAW,WAAW,OAAO,YAAY,GAAG"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
let vue = require("vue");
|
|
4
|
+
let vue_intlayer = require("vue-intlayer");
|
|
5
|
+
|
|
6
|
+
//#region src/useDictionary.ts
|
|
7
|
+
/**
|
|
8
|
+
* Dictionary-accepting variant of `useI18n`.
|
|
9
|
+
*
|
|
10
|
+
* Used internally by the SWC optimization: instead of looking up the dictionary
|
|
11
|
+
* at runtime by key, the SWC plugin pre-imports the dictionary JSON at build time
|
|
12
|
+
* and passes it directly here. This enables tree-shaking of unused locale content.
|
|
13
|
+
*/
|
|
14
|
+
const useDictionary = (dictionary, namespacePrefix) => {
|
|
15
|
+
const content = (0, vue_intlayer.useDictionary)(dictionary);
|
|
16
|
+
const { locale: currentLocale, setLocale, availableLocales } = (0, vue_intlayer.useLocale)();
|
|
17
|
+
const localeRef = (0, vue.computed)({
|
|
18
|
+
get: () => currentLocale.value,
|
|
19
|
+
set: (newVal) => {
|
|
20
|
+
setLocale(newVal);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
const t = (lookup, ...args) => {
|
|
24
|
+
const params = typeof args[0] === "object" && args[0] !== null ? args[0] : void 0;
|
|
25
|
+
const lookupKey = namespacePrefix ? `${namespacePrefix}.${String(lookup)}` : String(lookup);
|
|
26
|
+
const parts = lookupKey.split(".");
|
|
27
|
+
let current = content.value;
|
|
28
|
+
for (const part of parts) {
|
|
29
|
+
if (current == null) break;
|
|
30
|
+
current = current[part];
|
|
31
|
+
}
|
|
32
|
+
const str = String(current ?? lookupKey);
|
|
33
|
+
if (!params) return str;
|
|
34
|
+
return str.replace(/\{(\w+)\}/g, (_, k) => params[k] != null ? String(params[k]) : `{${k}}`);
|
|
35
|
+
};
|
|
36
|
+
return {
|
|
37
|
+
locale: localeRef,
|
|
38
|
+
availableLocales,
|
|
39
|
+
t,
|
|
40
|
+
n: (val) => String(val),
|
|
41
|
+
d: (val) => String(val)
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
//#endregion
|
|
46
|
+
exports.useDictionary = useDictionary;
|
|
47
|
+
//# sourceMappingURL=useDictionary.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDictionary.cjs","names":[],"sources":["../../src/useDictionary.ts"],"sourcesContent":["import type { ValidDotPathsFor } from '@intlayer/core/transpiler';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { computed, type WritableComputedRef } from 'vue';\nimport { useDictionary as useDictionaryBase, useLocale } from 'vue-intlayer';\n\n/**\n * Dictionary-accepting variant of `useI18n`.\n *\n * Used internally by the SWC optimization: instead of looking up the dictionary\n * at runtime by key, the SWC plugin pre-imports the dictionary JSON at build time\n * and passes it directly here. This enables tree-shaking of unused locale content.\n */\nexport const useDictionary = <T extends Dictionary>(\n dictionary: T,\n namespacePrefix?: string\n): {\n locale: WritableComputedRef<string>;\n availableLocales: string[];\n t: <P extends ValidDotPathsFor<any>>(key: P, ...args: unknown[]) => string;\n n: (val: unknown) => string;\n d: (val: unknown) => string;\n} => {\n const content = useDictionaryBase(dictionary);\n const { locale: currentLocale, setLocale, availableLocales } = useLocale();\n\n const localeRef = computed({\n get: () => currentLocale.value as string,\n set: (newVal: string) => {\n setLocale(newVal as LocalesValues);\n },\n });\n\n const t = <P extends ValidDotPathsFor<any>>(\n lookup: P,\n ...args: unknown[]\n ): string => {\n const params =\n typeof args[0] === 'object' && args[0] !== null\n ? (args[0] as Record<string, unknown>)\n : undefined;\n\n const lookupKey = namespacePrefix\n ? `${namespacePrefix}.${String(lookup)}`\n : String(lookup);\n const parts = lookupKey.split('.');\n let current: any = content.value;\n for (const part of parts) {\n if (current == null) break;\n current = current[part];\n }\n const str = String(current ?? lookupKey);\n if (!params) return str;\n return str.replace(/\\{(\\w+)\\}/g, (_, k) =>\n params[k] != null ? String(params[k]) : `{${k}}`\n );\n };\n\n return {\n locale: localeRef,\n availableLocales: availableLocales as string[],\n t,\n n: (val: unknown) => String(val),\n d: (val: unknown) => String(val),\n };\n};\n"],"mappings":";;;;;;;;;;;;;AAaA,MAAa,iBACX,YACA,oBAOG;CACH,MAAM,0CAA4B,WAAW;CAC7C,MAAM,EAAE,QAAQ,eAAe,WAAW,kDAAgC;CAE1E,MAAM,8BAAqB;EACzB,WAAW,cAAc;EACzB,MAAM,WAAmB;AACvB,aAAU,OAAwB;;EAErC,CAAC;CAEF,MAAM,KACJ,QACA,GAAG,SACQ;EACX,MAAM,SACJ,OAAO,KAAK,OAAO,YAAY,KAAK,OAAO,OACtC,KAAK,KACN;EAEN,MAAM,YAAY,kBACd,GAAG,gBAAgB,GAAG,OAAO,OAAO,KACpC,OAAO,OAAO;EAClB,MAAM,QAAQ,UAAU,MAAM,IAAI;EAClC,IAAI,UAAe,QAAQ;AAC3B,OAAK,MAAM,QAAQ,OAAO;AACxB,OAAI,WAAW,KAAM;AACrB,aAAU,QAAQ;;EAEpB,MAAM,MAAM,OAAO,WAAW,UAAU;AACxC,MAAI,CAAC,OAAQ,QAAO;AACpB,SAAO,IAAI,QAAQ,eAAe,GAAG,MACnC,OAAO,MAAM,OAAO,OAAO,OAAO,GAAG,GAAG,IAAI,EAAE,GAC/C;;AAGH,QAAO;EACL,QAAQ;EACU;EAClB;EACA,IAAI,QAAiB,OAAO,IAAI;EAChC,IAAI,QAAiB,OAAO,IAAI;EACjC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
let vue = require("vue");
|
|
4
|
+
let vue_intlayer = require("vue-intlayer");
|
|
5
|
+
|
|
6
|
+
//#region src/useDictionaryDynamic.ts
|
|
7
|
+
/**
|
|
8
|
+
* Dynamic dictionary-accepting variant of `useI18n`.
|
|
9
|
+
*/
|
|
10
|
+
const useDictionaryDynamic = async (dictionaryPromise, key, namespacePrefix) => {
|
|
11
|
+
const content = await (0, vue_intlayer.useDictionaryDynamic)(dictionaryPromise, key);
|
|
12
|
+
const { locale: currentLocale, setLocale, availableLocales } = (0, vue_intlayer.useLocale)();
|
|
13
|
+
const localeRef = (0, vue.computed)({
|
|
14
|
+
get: () => currentLocale.value,
|
|
15
|
+
set: (newVal) => {
|
|
16
|
+
setLocale(newVal);
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
const t = (lookup, ...args) => {
|
|
20
|
+
const params = typeof args[0] === "object" && args[0] !== null ? args[0] : void 0;
|
|
21
|
+
const lookupKey = namespacePrefix ? `${namespacePrefix}.${String(lookup)}` : String(lookup);
|
|
22
|
+
const parts = lookupKey.split(".");
|
|
23
|
+
let current = content.value;
|
|
24
|
+
for (const part of parts) {
|
|
25
|
+
if (current == null) break;
|
|
26
|
+
current = current[part];
|
|
27
|
+
}
|
|
28
|
+
const str = String(current ?? lookupKey);
|
|
29
|
+
if (!params) return str;
|
|
30
|
+
return str.replace(/\{(\w+)\}/g, (_, key) => params[key] != null ? String(params[key]) : `{${key}}`);
|
|
31
|
+
};
|
|
32
|
+
return {
|
|
33
|
+
locale: localeRef,
|
|
34
|
+
availableLocales,
|
|
35
|
+
t,
|
|
36
|
+
n: (val) => String(val),
|
|
37
|
+
d: (val) => String(val)
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
//#endregion
|
|
42
|
+
exports.useDictionaryDynamic = useDictionaryDynamic;
|
|
43
|
+
//# sourceMappingURL=useDictionaryDynamic.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDictionaryDynamic.cjs","names":[],"sources":["../../src/useDictionaryDynamic.ts"],"sourcesContent":["import type { ValidDotPathsFor } from '@intlayer/core/transpiler';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { computed, type WritableComputedRef } from 'vue';\nimport {\n useDictionaryDynamic as useDictionaryDynamicBase,\n useLocale,\n} from 'vue-intlayer';\n\n/**\n * Dynamic dictionary-accepting variant of `useI18n`.\n */\nexport const useDictionaryDynamic = async <\n const T extends Dictionary,\n const K extends string,\n>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n key: K,\n namespacePrefix?: string\n): Promise<{\n locale: WritableComputedRef<string>;\n availableLocales: string[];\n t: <P extends ValidDotPathsFor<any>>(key: P, ...args: unknown[]) => string;\n n: (val: unknown) => string;\n d: (val: unknown) => string;\n}> => {\n const content = await useDictionaryDynamicBase<T, any>(\n dictionaryPromise,\n key as any\n );\n\n const { locale: currentLocale, setLocale, availableLocales } = useLocale();\n\n const localeRef = computed({\n get: () => currentLocale.value as string,\n set: (newVal: string) => {\n setLocale(newVal as LocalesValues);\n },\n });\n\n const t = <P extends ValidDotPathsFor<any>>(\n lookup: P,\n ...args: unknown[]\n ): string => {\n const params =\n typeof args[0] === 'object' && args[0] !== null\n ? (args[0] as Record<string, unknown>)\n : undefined;\n\n const lookupKey = namespacePrefix\n ? `${namespacePrefix}.${String(lookup)}`\n : String(lookup);\n const parts = lookupKey.split('.');\n let current: any = content.value;\n for (const part of parts) {\n if (current == null) break;\n current = current[part];\n }\n const str = String(current ?? lookupKey);\n\n if (!params) return str;\n return str.replace(/\\{(\\w+)\\}/g, (_, key) =>\n params[key] != null ? String(params[key]) : `{${key}}`\n );\n };\n\n return {\n locale: localeRef,\n availableLocales: availableLocales as string[],\n t,\n n: (val: unknown) => String(val),\n d: (val: unknown) => String(val),\n };\n};\n"],"mappings":";;;;;;;;;AAeA,MAAa,uBAAuB,OAIlC,mBACA,KACA,oBAOI;CACJ,MAAM,UAAU,6CACd,mBACA,IACD;CAED,MAAM,EAAE,QAAQ,eAAe,WAAW,kDAAgC;CAE1E,MAAM,8BAAqB;EACzB,WAAW,cAAc;EACzB,MAAM,WAAmB;AACvB,aAAU,OAAwB;;EAErC,CAAC;CAEF,MAAM,KACJ,QACA,GAAG,SACQ;EACX,MAAM,SACJ,OAAO,KAAK,OAAO,YAAY,KAAK,OAAO,OACtC,KAAK,KACN;EAEN,MAAM,YAAY,kBACd,GAAG,gBAAgB,GAAG,OAAO,OAAO,KACpC,OAAO,OAAO;EAClB,MAAM,QAAQ,UAAU,MAAM,IAAI;EAClC,IAAI,UAAe,QAAQ;AAC3B,OAAK,MAAM,QAAQ,OAAO;AACxB,OAAI,WAAW,KAAM;AACrB,aAAU,QAAQ;;EAEpB,MAAM,MAAM,OAAO,WAAW,UAAU;AAExC,MAAI,CAAC,OAAQ,QAAO;AACpB,SAAO,IAAI,QAAQ,eAAe,GAAG,QACnC,OAAO,QAAQ,OAAO,OAAO,OAAO,KAAK,GAAG,IAAI,IAAI,GACrD;;AAGH,QAAO;EACL,QAAQ;EACU;EAClB;EACA,IAAI,QAAiB,OAAO,IAAI;EAChC,IAAI,QAAiB,OAAO,IAAI;EACjC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
let vue = require("vue");
|
|
4
|
+
let vue_intlayer = require("vue-intlayer");
|
|
5
|
+
|
|
6
|
+
//#region src/useI18nDictionary.ts
|
|
7
|
+
/**
|
|
8
|
+
* Dictionary-accepting variant of `useI18n`.
|
|
9
|
+
*
|
|
10
|
+
* Used internally by the SWC optimization: instead of looking up the dictionary
|
|
11
|
+
* at runtime by key, the SWC plugin pre-imports the dictionary JSON at build time
|
|
12
|
+
* and passes it directly here. This enables tree-shaking of unused locale content.
|
|
13
|
+
*/
|
|
14
|
+
const useI18nDictionary = (dictionary, namespacePrefix) => {
|
|
15
|
+
const content = (0, vue_intlayer.useDictionary)(dictionary);
|
|
16
|
+
const { locale: currentLocale, setLocale, availableLocales } = (0, vue_intlayer.useLocale)();
|
|
17
|
+
const localeRef = (0, vue.computed)({
|
|
18
|
+
get: () => currentLocale.value,
|
|
19
|
+
set: (newVal) => {
|
|
20
|
+
setLocale(newVal);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
const t = (lookup, ...args) => {
|
|
24
|
+
const params = typeof args[0] === "object" && args[0] !== null ? args[0] : void 0;
|
|
25
|
+
const lookupKey = namespacePrefix ? `${namespacePrefix}.${String(lookup)}` : String(lookup);
|
|
26
|
+
const parts = lookupKey.split(".");
|
|
27
|
+
let current = content.value;
|
|
28
|
+
for (const part of parts) {
|
|
29
|
+
if (current == null) break;
|
|
30
|
+
current = current[part];
|
|
31
|
+
}
|
|
32
|
+
const str = String(current ?? lookupKey);
|
|
33
|
+
if (!params) return str;
|
|
34
|
+
return str.replace(/\{(\w+)\}/g, (_, k) => params[k] != null ? String(params[k]) : `{${k}}`);
|
|
35
|
+
};
|
|
36
|
+
return {
|
|
37
|
+
locale: localeRef,
|
|
38
|
+
availableLocales,
|
|
39
|
+
t,
|
|
40
|
+
n: (val) => String(val),
|
|
41
|
+
d: (val) => String(val)
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
//#endregion
|
|
46
|
+
exports.useI18nDictionary = useI18nDictionary;
|
|
47
|
+
//# sourceMappingURL=useI18nDictionary.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useI18nDictionary.cjs","names":[],"sources":["../../src/useI18nDictionary.ts"],"sourcesContent":["import type { ValidDotPathsFor } from '@intlayer/core/transpiler';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type { LocalesValues } from '@intlayer/types/locales';\nimport { useDictionary, useLocale } from 'vue-intlayer';\nimport { computed, type WritableComputedRef } from 'vue';\n\n/**\n * Dictionary-accepting variant of `useI18n`.\n *\n * Used internally by the SWC optimization: instead of looking up the dictionary\n * at runtime by key, the SWC plugin pre-imports the dictionary JSON at build time\n * and passes it directly here. This enables tree-shaking of unused locale content.\n */\nexport const useI18nDictionary = <T extends Dictionary>(\n dictionary: T,\n namespacePrefix?: string\n): {\n locale: WritableComputedRef<string>;\n availableLocales: string[];\n t: <P extends ValidDotPathsFor<any>>(key: P, ...args: unknown[]) => string;\n n: (val: unknown) => string;\n d: (val: unknown) => string;\n} => {\n const content = useDictionary(dictionary);\n const { locale: currentLocale, setLocale, availableLocales } = useLocale();\n\n const localeRef = computed({\n get: () => currentLocale.value as string,\n set: (newVal: string) => {\n setLocale(newVal as LocalesValues);\n },\n });\n\n const t = <P extends ValidDotPathsFor<any>>(\n lookup: P,\n ...args: unknown[]\n ): string => {\n const params =\n typeof args[0] === 'object' && args[0] !== null\n ? (args[0] as Record<string, unknown>)\n : undefined;\n\n const lookupKey = namespacePrefix\n ? `${namespacePrefix}.${String(lookup)}`\n : String(lookup);\n const parts = lookupKey.split('.');\n let current: any = content.value;\n for (const part of parts) {\n if (current == null) break;\n current = current[part];\n }\n const str = String(current ?? lookupKey);\n if (!params) return str;\n return str.replace(/\\{(\\w+)\\}/g, (_, k) =>\n params[k] != null ? String(params[k]) : `{${k}}`\n );\n };\n\n return {\n locale: localeRef,\n availableLocales: availableLocales as string[],\n t,\n n: (val: unknown) => String(val),\n d: (val: unknown) => String(val),\n };\n};\n"],"mappings":";;;;;;;;;;;;;AAaA,MAAa,qBACX,YACA,oBAOG;CACH,MAAM,0CAAwB,WAAW;CACzC,MAAM,EAAE,QAAQ,eAAe,WAAW,kDAAgC;CAE1E,MAAM,8BAAqB;EACzB,WAAW,cAAc;EACzB,MAAM,WAAmB;AACvB,aAAU,OAAwB;;EAErC,CAAC;CAEF,MAAM,KACJ,QACA,GAAG,SACQ;EACX,MAAM,SACJ,OAAO,KAAK,OAAO,YAAY,KAAK,OAAO,OACtC,KAAK,KACN;EAEN,MAAM,YAAY,kBACd,GAAG,gBAAgB,GAAG,OAAO,OAAO,KACpC,OAAO,OAAO;EAClB,MAAM,QAAQ,UAAU,MAAM,IAAI;EAClC,IAAI,UAAe,QAAQ;AAC3B,OAAK,MAAM,QAAQ,OAAO;AACxB,OAAI,WAAW,KAAM;AACrB,aAAU,QAAQ;;EAEpB,MAAM,MAAM,OAAO,WAAW,UAAU;AACxC,MAAI,CAAC,OAAQ,QAAO;AACpB,SAAO,IAAI,QAAQ,eAAe,GAAG,MACnC,OAAO,MAAM,OAAO,OAAO,OAAO,GAAG,GAAG,IAAI,EAAE,GAC/C;;AAGH,QAAO;EACL,QAAQ;EACU;EAClB;EACA,IAAI,QAAiB,OAAO,IAAI;EAChC,IAAI,QAAiB,OAAO,IAAI;EACjC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
let vue = require("vue");
|
|
4
|
+
let vue_intlayer = require("vue-intlayer");
|
|
5
|
+
|
|
6
|
+
//#region src/useI18nDictionaryDynamic.ts
|
|
7
|
+
/**
|
|
8
|
+
* Dynamic dictionary-accepting variant of `useI18n`.
|
|
9
|
+
*/
|
|
10
|
+
const useI18nDictionaryDynamic = (dictionaryPromise, key, namespacePrefix) => {
|
|
11
|
+
const content = (0, vue_intlayer.useDictionaryDynamic)(dictionaryPromise, key);
|
|
12
|
+
const { locale: currentLocale, setLocale, availableLocales } = (0, vue_intlayer.useLocale)();
|
|
13
|
+
const localeRef = (0, vue.computed)({
|
|
14
|
+
get: () => currentLocale.value,
|
|
15
|
+
set: (newVal) => {
|
|
16
|
+
setLocale(newVal);
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
const t = (lookup, ...args) => {
|
|
20
|
+
const params = typeof args[0] === "object" && args[0] !== null ? args[0] : void 0;
|
|
21
|
+
const lookupKey = namespacePrefix ? `${namespacePrefix}.${String(lookup)}` : String(lookup);
|
|
22
|
+
const parts = lookupKey.split(".");
|
|
23
|
+
let current = content.value;
|
|
24
|
+
for (const part of parts) {
|
|
25
|
+
if (current == null) break;
|
|
26
|
+
current = current[part];
|
|
27
|
+
}
|
|
28
|
+
const str = String(current ?? lookupKey);
|
|
29
|
+
if (!params) return str;
|
|
30
|
+
return str.replace(/\{(\w+)\}/g, (_, k) => params[k] != null ? String(params[k]) : `{${k}}`);
|
|
31
|
+
};
|
|
32
|
+
return {
|
|
33
|
+
locale: localeRef,
|
|
34
|
+
availableLocales,
|
|
35
|
+
t,
|
|
36
|
+
n: (val) => String(val),
|
|
37
|
+
d: (val) => String(val)
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
//#endregion
|
|
42
|
+
exports.useI18nDictionaryDynamic = useI18nDictionaryDynamic;
|
|
43
|
+
//# sourceMappingURL=useI18nDictionaryDynamic.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useI18nDictionaryDynamic.cjs","names":[],"sources":["../../src/useI18nDictionaryDynamic.ts"],"sourcesContent":["import type { ValidDotPathsFor } from '@intlayer/core/transpiler';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type { LocalesValues } from '@intlayer/types/locales';\nimport type { StrictModeLocaleMap } from '@intlayer/types/module_augmentation';\nimport { useDictionaryDynamic, useLocale } from 'vue-intlayer';\nimport { computed, type WritableComputedRef } from 'vue';\n\n/**\n * Dynamic dictionary-accepting variant of `useI18n`.\n */\nexport const useI18nDictionaryDynamic = <\n const T extends Dictionary,\n const K extends string,\n>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n key: K,\n namespacePrefix?: string\n): {\n locale: WritableComputedRef<string>;\n availableLocales: string[];\n t: <P extends ValidDotPathsFor<any>>(key: P, ...args: unknown[]) => string;\n n: (val: unknown) => string;\n d: (val: unknown) => string;\n} => {\n const content = useDictionaryDynamic<T, any>(dictionaryPromise, key as any);\n const { locale: currentLocale, setLocale, availableLocales } = useLocale();\n\n const localeRef = computed({\n get: () => currentLocale.value as string,\n set: (newVal: string) => {\n setLocale(newVal as LocalesValues);\n },\n });\n\n const t = <P extends ValidDotPathsFor<any>>(\n lookup: P,\n ...args: unknown[]\n ): string => {\n const params =\n typeof args[0] === 'object' && args[0] !== null\n ? (args[0] as Record<string, unknown>)\n : undefined;\n\n const lookupKey = namespacePrefix\n ? `${namespacePrefix}.${String(lookup)}`\n : String(lookup);\n const parts = lookupKey.split('.');\n let current: any = content.value;\n for (const part of parts) {\n if (current == null) break;\n current = current[part];\n }\n const str = String(current ?? lookupKey);\n if (!params) return str;\n return str.replace(/\\{(\\w+)\\}/g, (_, k) =>\n params[k] != null ? String(params[k]) : `{${k}}`\n );\n };\n\n return {\n locale: localeRef,\n availableLocales: availableLocales as string[],\n t,\n n: (val: unknown) => String(val),\n d: (val: unknown) => String(val),\n };\n};\n"],"mappings":";;;;;;;;;AAUA,MAAa,4BAIX,mBACA,KACA,oBAOG;CACH,MAAM,iDAAuC,mBAAmB,IAAW;CAC3E,MAAM,EAAE,QAAQ,eAAe,WAAW,kDAAgC;CAE1E,MAAM,8BAAqB;EACzB,WAAW,cAAc;EACzB,MAAM,WAAmB;AACvB,aAAU,OAAwB;;EAErC,CAAC;CAEF,MAAM,KACJ,QACA,GAAG,SACQ;EACX,MAAM,SACJ,OAAO,KAAK,OAAO,YAAY,KAAK,OAAO,OACtC,KAAK,KACN;EAEN,MAAM,YAAY,kBACd,GAAG,gBAAgB,GAAG,OAAO,OAAO,KACpC,OAAO,OAAO;EAClB,MAAM,QAAQ,UAAU,MAAM,IAAI;EAClC,IAAI,UAAe,QAAQ;AAC3B,OAAK,MAAM,QAAQ,OAAO;AACxB,OAAI,WAAW,KAAM;AACrB,aAAU,QAAQ;;EAEpB,MAAM,MAAM,OAAO,WAAW,UAAU;AACxC,MAAI,CAAC,OAAQ,QAAO;AACpB,SAAO,IAAI,QAAQ,eAAe,GAAG,MACnC,OAAO,MAAM,OAAO,OAAO,OAAO,GAAG,GAAG,IAAI,EAAE,GAC/C;;AAGH,QAAO;EACL,QAAQ;EACU;EAClB;EACA,IAAI,QAAiB,OAAO,IAAI;EAChC,IAAI,QAAiB,OAAO,IAAI;EACjC"}
|