@intlayer/vue-i18n 9.5.2 → 9.5.4-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 CHANGED
@@ -1,6 +1,6 @@
1
1
  <p align="center">
2
2
  <a href="https://intlayer.org" rel="">
3
- <img src="https://raw.githubusercontent.com/aymericzip/intlayer/main/docs/assets/cover.png" width="60%" alt="Intlayer Logo" />
3
+ <img src="https://raw.githubusercontent.com/aymericzip/intlayer/main/docs/assets/cover.webp" width="60%" alt="Intlayer Logo" />
4
4
  </a>
5
5
  </p>
6
6
 
@@ -49,10 +49,10 @@ With **per-locale content files**, **TypeScript autocompletion**, **tree-shakabl
49
49
 
50
50
  | Feature | Description |
51
51
  | --------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
52
- | <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/frameworks.png?raw=true" alt="Feature" width="700"> | **Cross-Frameworks Support**<br><br>Intlayer is compatible with all major frameworks and libraries, including Next.js, React, Vite, Vue.js, Nuxt, Preact, Express, and more. |
52
+ | <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/frameworks.webp?raw=true" alt="Feature" width="700"> | **Cross-Frameworks Support**<br><br>Intlayer is compatible with all major frameworks and libraries, including Next.js, React, Vite, Vue.js, Nuxt, Preact, Express, and more. |
53
53
  | <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/javascript_content_management.jpg?raw=true" alt="Feature" width="700"> | **JavaScript-Powered Content Management**<br><br>Harness the flexibility of JavaScript to define and manage your content efficiently. <br><br> - [Content declaration](https://intlayer.org/doc/concept/content) |
54
54
  | <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/per_locale_content_declaration_file.png?raw=true" alt="Feature" width="700"> | **Per-Locale Content Declaration File**<br><br>Speed up your development by declaring your content once, before auto generation.<br><br> - [Per-Locale Content Declaration File](https://intlayer.org/doc/concept/per-locale-file) |
55
- | <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/compiler.jpg?raw=true" alt="Feature" width="700"> | **Compiler**<br><br>The Intlayer Compiler extract automatically the content from the components and generate the dictionary files.<br><br> - [Compiler](https://intlayer.org/doc/compiler) |
55
+ | <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/compiler.webp?raw=true" alt="Feature" width="700"> | **Compiler**<br><br>The Intlayer Compiler extract automatically the content from the components and generate the dictionary files.<br><br> - [Compiler](https://intlayer.org/doc/compiler) |
56
56
  | <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/autocompletion.png?raw=true" alt="Feature" width="700"> | **Type-Safe Environment**<br><br>Leverage TypeScript to ensure your content definitions and code are error-free, while also benefiting from IDE autocompletion.<br><br> - [TypeScript configuration](https://intlayer.org/doc/environment/vite-and-react#configure-typescript) |
57
57
  | <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/config_file.png?raw=true" alt="Feature" width="700"> | **Simplified Setup**<br><br>Get up and running quickly with minimal configuration. Adjust settings for internationalization, routing, AI, build, and content handling with ease. <br><br> - [Explore Next.js integration](https://intlayer.org/doc/environment/nextjs) |
58
58
  | <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/content_retrieval.png?raw=true" alt="Feature" width="700"> | **Simplified Content Retrieval**<br><br>No need to call your `t` function for each piece of content. Retrieve all your content directly using a single hook.<br><br> - [React integration](https://intlayer.org/doc/environment/create-react-app) |
@@ -60,12 +60,12 @@ With **per-locale content files**, **TypeScript autocompletion**, **tree-shakabl
60
60
  | <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/file_tree.png?raw=true" alt="Feature" width="700"> | **Organized Codebase**<br><br>Keep your codebase more organized: 1 component = 1 dictionary in the same folder. Translations close to their respective components, enhance maintainability and clarity. <br><br> - [How Intlayer works](https://intlayer.org/doc/concept/how-works-intlayer) |
61
61
  | <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/url_routing.png?raw=true" alt="Feature" width="700"> | **Enhanced Routing**<br><br>Full support of app routing, adapting seamlessly to complex application structures, for Next.js, React, Vite, Vue.js, etc.<br><br> - [Explore Next.js integration](https://intlayer.org/doc/environment/nextjs) |
62
62
  | <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/markdown.png?raw=true" alt="Feature" width="700"> | **Markdown Support**<br><br>Import and interpret, locale files and remote Markdown for multilingual content like privacy policies, documentation, etc. Interpret and make Markdown metadata accessible in your code.<br><br> - [Content files](https://intlayer.org/doc/concept/content/file) |
63
- | <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/visual_editor.png?raw=true" alt="Feature" width="700"> | **Free Visual Editor & CMS**<br><br>A free visual editor and CMS are available for content writers, removing the need for a localization platform. Keep your content synchronized using Git, or externalize it totally or partially with the CMS.<br><br> - [Intlayer Editor](https://intlayer.org/doc/concept/editor) <br> - [Intlayer CMS](https://intlayer.org/doc/concept/cms) |
64
- | <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/bundle.png?raw=true" alt="Feature" width="700"> | **Tree-shakable Content**<br><br>Tree-shakable content, reducing the size of the final bundle. Loads content per component, excluding any unused content from your bundle. Supports lazy loading to enhance app loading efficiency. <br><br> - [App build optimization](https://intlayer.org/doc/concept/how-works-intlayer#app-build-optimization) |
65
- | <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/static_rendering.png?raw=true" alt="Feature" width="700"> | **Static Rendering**<br><br>Doesn't block Static Rendering. <br><br> - [Next.js integration](https://intlayer.org/doc/environment/nextjs) |
63
+ | <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/visual_editor.webp?raw=true" alt="Feature" width="700"> | **Free Visual Editor & CMS**<br><br>A free visual editor and CMS are available for content writers, removing the need for a localization platform. Keep your content synchronized using Git, or externalize it totally or partially with the CMS.<br><br> - [Intlayer Editor](https://intlayer.org/doc/concept/editor) <br> - [Intlayer CMS](https://intlayer.org/doc/concept/cms) |
64
+ | <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/bundle.webp?raw=true" alt="Feature" width="700"> | **Tree-shakable Content**<br><br>Tree-shakable content, reducing the size of the final bundle. Loads content per component, excluding any unused content from your bundle. Supports lazy loading to enhance app loading efficiency. <br><br> - [App build optimization](https://intlayer.org/doc/concept/how-works-intlayer#app-build-optimization) |
65
+ | <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/static_rendering.webp?raw=true" alt="Feature" width="700"> | **Static Rendering**<br><br>Doesn't block Static Rendering. <br><br> - [Next.js integration](https://intlayer.org/doc/environment/nextjs) |
66
66
  | <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/AI_translation.png?raw=true" alt="Feature" width="700"> | **AI-Powered Translation**<br><br>Transform your website into 231 languages with just one click using Intlayer's advanced AI-powered translation tools using your own AI provider / API key. <br><br> - [CI/CD integration](https://intlayer.org/doc/concept/ci-cd) <br> - [Intlayer CLI](https://intlayer.org/doc/concept/cli) <br> - [Auto fill](https://intlayer.org/doc/concept/auto-fill) |
67
67
  | <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/mcp.png?raw=true" alt="Feature" width="700"> | **MCP Server Integration**<br><br>Provides an MCP (Model Context Protocol) server for IDE automation, enabling seamless content management and i18n workflows directly within your development environment. <br><br> - [MCP Server](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/mcp_server.md) |
68
- | <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/vscode_extension.png?raw=true" alt="Feature" width="700"> | **VSCode Extension**<br><br>Intlayer provides a VSCode extension to help you manage your content and translations, building your dictionaries, translating your content, and more. <br><br> - [VSCode Extension](https://intlayer.org/doc/vs-code-extension) |
68
+ | <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/vscode_extension.webp?raw=true" alt="Feature" width="700"> | **VSCode Extension**<br><br>Intlayer provides a VSCode extension to help you manage your content and translations, building your dictionaries, translating your content, and more. <br><br> - [VSCode Extension](https://intlayer.org/doc/vs-code-extension) |
69
69
  | <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/interoperability.png?raw=true" alt="Feature" width="700"> | **Interoperability**<br><br>Allow interoperability with react-i18next, next-i18next, next-intl, react-intl, vue-i18n. <br><br> - [Intlayer and react-intl](https://intlayer.org/blog/intlayer-with-react-intl) <br> - [Intlayer and next-intl](https://intlayer.org/blog/intlayer-with-next-intl) <br> - [Intlayer and next-i18next](https://intlayer.org/blog/intlayer-with-next-i18next) <br> - [Intlayer and vue-i18n](https://intlayer.org/blog/intlayer-with-vue-i18n) <br> - [Intlayer compat adapters](https://intlayer.org/doc/compatibility) |
70
70
  | <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/benchmark.png?raw=true" alt="Feature" width="700"> | **Performances & Benchmark**<br><br>Uses advanced tree-shaking and dynamic loading to boost performances and keep the solution as light as possible. <br><br> - [Performances & Benchmark](https://intlayer.org/doc/benchmark) |
71
71
 
@@ -262,7 +262,7 @@ Intlayer connects **developers**, **copywriters**, and **AI agents** in one work
262
262
  - Feature flags
263
263
  - Headless CMSs (e.g. Contentful, Strapi, Sanity)
264
264
 
265
- ![CMS Preview](https://github.com/aymericzip/intlayer/blob/main/docs/assets/CMS.png?raw=true)
265
+ ![CMS Preview](https://github.com/aymericzip/intlayer/blob/main/docs/assets/CMS.webp?raw=true)
266
266
 
267
267
  ## 🌐 Readme in other languages
268
268
 
@@ -328,4 +328,4 @@ Contribute on [GitHub](https://github.com/aymericzip/intlayer), [GitLab](https:/
328
328
 
329
329
  If you like Intlayer, give us a ⭐ on GitHub. It helps others discover the project! [See why GitHub Stars matter](https://github.com/aymericzip/intlayer/blob/main/CONTRIBUTING.md#why-github-stars-matter-).
330
330
 
331
- [![Star History Chart](https://api.star-history.com/svg?repos=aymericzip/intlayer&type=Date)](https://api.star-history.com/#aymericzip/intlayer&Date)
331
+ [![Star History Chart](https://api.star-history.com/svg?repos=aymericzip/intlayer&type=Date)](https://star-history.com/#aymericzip/intlayer&Date)
@@ -1,5 +1,5 @@
1
1
  import { I18nInjectionKey, VERSION, createI18n, useI18n } from "./createI18n.mjs";
2
- import { useDictionaryDynamic } from "./useDictionaryDynamic.mjs";
3
2
  import { useDictionary } from "./useDictionary.mjs";
3
+ import { useDictionaryDynamic } from "./useDictionaryDynamic.mjs";
4
4
 
5
5
  export { I18nInjectionKey, VERSION, createI18n, useDictionary, useDictionaryDynamic, useI18n };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intlayer/vue-i18n",
3
- "version": "9.5.2",
3
+ "version": "9.5.4-canary.0",
4
4
  "private": false,
5
5
  "description": "vue-i18n API adapter for intlayer — useI18n, createI18n, and installIntlayer backed by vue-intlayer",
6
6
  "keywords": [
@@ -69,19 +69,20 @@
69
69
  "prepublish": "cp -f ../../README.md ./README.md",
70
70
  "publish": "bun publish || true",
71
71
  "publish:canary": "bun publish --access public --tag canary || true",
72
+ "publish:ci": "bun ../../scripts/publish-package.mjs",
72
73
  "publish:latest": "bun publish --access public --tag latest || true",
73
74
  "test": "bun --bun vitest run",
74
75
  "test:watch": "bun --bun vitest",
75
76
  "typecheck": "tsc --noEmit --project tsconfig.types.json"
76
77
  },
77
78
  "dependencies": {
78
- "@intlayer/config": "9.5.2",
79
- "@intlayer/core": "9.5.2",
80
- "@intlayer/dictionaries-entry": "9.5.2",
81
- "@intlayer/engine": "9.5.2",
82
- "@intlayer/types": "9.5.2",
83
- "vite-intlayer": "9.5.2",
84
- "vue-intlayer": "9.5.2"
79
+ "@intlayer/config": "9.5.4-canary.0",
80
+ "@intlayer/core": "9.5.4-canary.0",
81
+ "@intlayer/dictionaries-entry": "9.5.4-canary.0",
82
+ "@intlayer/engine": "9.5.4-canary.0",
83
+ "@intlayer/types": "9.5.4-canary.0",
84
+ "vite-intlayer": "9.5.4-canary.0",
85
+ "vue-intlayer": "9.5.4-canary.0"
85
86
  },
86
87
  "devDependencies": {
87
88
  "@types/node": "^22",
@@ -92,9 +93,9 @@
92
93
  "tsdown": "0.23.0",
93
94
  "typescript": "7.0.2",
94
95
  "vite": "8.3.0",
95
- "vitest": "5.0.0",
96
- "vue": "3.5.42",
97
- "vue-i18n": "11.4.10"
96
+ "vitest": "5.0.1",
97
+ "vue": "3.5.43",
98
+ "vue-i18n": "11.4.12"
98
99
  },
99
100
  "peerDependencies": {
100
101
  "vite": ">=4.0.0",
@@ -1,29 +0,0 @@
1
- //#region \0rolldown/runtime.js
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __copyProps = (to, from, except, desc) => {
9
- if (from && typeof from === "object" || typeof from === "function") {
10
- for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
- key = keys[i];
12
- if (!__hasOwnProp.call(to, key) && key !== except) {
13
- __defProp(to, key, {
14
- get: ((k) => from[k]).bind(null, key),
15
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
- });
17
- }
18
- }
19
- }
20
- return to;
21
- };
22
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
23
- value: mod,
24
- enumerable: true
25
- }) : target, mod));
26
-
27
- //#endregion
28
-
29
- exports.__toESM = __toESM;
@@ -1,203 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
3
- const require_formats = require('./formats.cjs');
4
- const require_resolveVueMessage = require('./resolveVueMessage.cjs');
5
- let _intlayer_config_built = require("@intlayer/config/built");
6
- let _intlayer_config_colors = require("@intlayer/config/colors");
7
- _intlayer_config_colors = require_runtime.__toESM(_intlayer_config_colors);
8
- let _intlayer_config_logger = require("@intlayer/config/logger");
9
- let vue = require("vue");
10
- let vue_intlayer = require("vue-intlayer");
11
-
12
- //#region src/createI18n.ts
13
- const VERSION = "9.13.1";
14
- const I18nInjectionKey = Symbol("global-i18n");
15
- const navigatePath = (objectValue, path) => {
16
- if (!path) return objectValue;
17
- let current = objectValue;
18
- for (const part of path.split(".")) {
19
- if (current === null || current === void 0 || typeof current !== "object") return;
20
- current = current[part];
21
- }
22
- return current;
23
- };
24
- /**
25
- * Looks up a raw value for a vue-i18n key against intlayer dictionaries.
26
- *
27
- * Resolution order:
28
- * 1. `ns:key` prefix → dictionary `ns`
29
- * 2. The default namespace dictionary with the full dot-path
30
- * 3. The first key segment as the dictionary key (`'home.title'` →
31
- * dictionary `home`, path `title`)
32
- */
33
- const lookupRaw = (namespace, key) => {
34
- if (key.includes(":")) {
35
- const separatorIndex = key.indexOf(":");
36
- key.slice(0, separatorIndex);
37
- key.slice(separatorIndex + 1);
38
- }
39
- };
40
- /** Translates a key with vue-i18n's polymorphic argument list. */
41
- const translateKey = (locale, namespace, key, args, fallbackMessages) => {
42
- const { values, count, defaultMessage } = require_resolveVueMessage.parseTranslateArguments(args);
43
- const rawValue = lookupRaw(namespace, key);
44
- if (rawValue === void 0) {
45
- if (fallbackMessages?.[locale]) {
46
- const targetPath = namespace ? `${namespace}.${key}` : key;
47
- const fallbackValue = navigatePath(fallbackMessages[locale], targetPath);
48
- if (fallbackValue !== void 0) return require_resolveVueMessage.resolveVueMessage(fallbackValue, values, count, locale);
49
- }
50
- if (defaultMessage !== void 0) return require_resolveVueMessage.resolveVueMessage(defaultMessage, values, count, locale);
51
- return key;
52
- }
53
- return require_resolveVueMessage.resolveVueMessage(rawValue, values, count, locale);
54
- };
55
- const getAvailableLocales = () => _intlayer_config_built.internationalization?.locales?.map(String) ?? [];
56
- const warnDeprecatedRuntimeMessages = (location) => {
57
- (0, _intlayer_config_logger.getAppLogger)({ log: _intlayer_config_built.log })(`${(0, _intlayer_config_logger.colorize)(location, _intlayer_config_colors.CYAN)} has no effect with ${(0, _intlayer_config_logger.colorize)("@intlayer/vue-i18n", _intlayer_config_colors.MAGENTA)} — translations are managed by the compiled intlayer dictionaries.`);
58
- };
59
- const createI18n = ((options = {}) => {
60
- const fallbackMessages = options.messages;
61
- if (options.messages !== void 0 && process.env.NODE_ENV === "development") (0, _intlayer_config_logger.getAppLogger)({ log: _intlayer_config_built.log })(`${(0, _intlayer_config_logger.colorize)("createI18n", _intlayer_config_colors.CYAN)}: the ${(0, _intlayer_config_logger.colorize)("`messages`", _intlayer_config_colors.CYAN)} option is used as a fallback. For optimal bundle size, remove the locale JSON imports and use ${(0, _intlayer_config_logger.colorize)("useDictionary", _intlayer_config_colors.CYAN)} or compile your intlayer dictionaries instead:\n ${(0, _intlayer_config_logger.colorize)("Before:", _intlayer_config_colors.GREY)} createI18n({ messages: { en, fr, … } })\n ${(0, _intlayer_config_logger.colorize)("After: ", _intlayer_config_colors.GREY)} createI18n({})`);
62
- const client = (0, vue_intlayer.createIntlayerClient)(options.locale);
63
- const datetimeFormats = options.datetimeFormats;
64
- const numberFormats = options.numberFormats;
65
- const currentLocale = () => String(client.locale.value);
66
- /** Writable ref matching vue-i18n's composition-mode `global.locale`. */
67
- const localeRef = (0, vue.computed)({
68
- get: () => currentLocale(),
69
- set: (newLocale) => {
70
- client.setLocale(newLocale);
71
- }
72
- });
73
- const globalTranslate = (key, ...args) => translateKey(currentLocale(), void 0, key, args, fallbackMessages);
74
- const globalDate = (value, formatOrOptions) => require_formats.formatDateValue(value, formatOrOptions, currentLocale(), datetimeFormats);
75
- const globalNumber = (value, formatOrOptions) => require_formats.formatNumberValue(value, formatOrOptions, currentLocale(), numberFormats);
76
- const global = {
77
- locale: localeRef,
78
- availableLocales: getAvailableLocales(),
79
- fallbackLocale: options.fallbackLocale ?? _intlayer_config_built.internationalization?.defaultLocale,
80
- t: globalTranslate,
81
- tc: globalTranslate,
82
- te: (key) => lookupRaw(void 0, key) !== void 0,
83
- tm: (key) => lookupRaw(void 0, key) ?? {},
84
- rt: (message, ...args) => {
85
- const { values, count } = require_resolveVueMessage.parseTranslateArguments(args);
86
- return require_resolveVueMessage.resolveVueMessage(message, values, count, currentLocale());
87
- },
88
- d: globalDate,
89
- n: globalNumber,
90
- setLocaleMessage: (_locale, _messages) => {
91
- warnDeprecatedRuntimeMessages("setLocaleMessage");
92
- },
93
- mergeLocaleMessage: (_locale, _messages) => {
94
- warnDeprecatedRuntimeMessages("mergeLocaleMessage");
95
- },
96
- getLocaleMessage: (_locale) => {
97
- warnDeprecatedRuntimeMessages("getLocaleMessage");
98
- return {};
99
- }
100
- };
101
- /** Legacy Options-API facade (`this.$i18n`) with a string `locale`. */
102
- const legacyI18n = {
103
- get locale() {
104
- return currentLocale();
105
- },
106
- set locale(newLocale) {
107
- client.setLocale(newLocale);
108
- },
109
- get availableLocales() {
110
- return getAvailableLocales();
111
- },
112
- t: globalTranslate,
113
- tc: globalTranslate,
114
- te: global.te,
115
- tm: global.tm,
116
- rt: global.rt,
117
- d: globalDate,
118
- n: globalNumber
119
- };
120
- const applyTranslateDirective = (element, binding) => {
121
- const bindingValue = binding.value;
122
- if (typeof bindingValue === "string") element.textContent = globalTranslate(bindingValue);
123
- else if (bindingValue && typeof bindingValue === "object") {
124
- const directiveArgs = [];
125
- if (bindingValue.args) directiveArgs.push(bindingValue.args);
126
- if (typeof bindingValue.choice === "number") directiveArgs.push(bindingValue.choice);
127
- element.textContent = globalTranslate(bindingValue.path, ...directiveArgs);
128
- }
129
- };
130
- const i18nInstance = {
131
- global,
132
- mode: options.legacy === true ? "legacy" : "composition",
133
- __optionsMessages: fallbackMessages,
134
- install(app) {
135
- (0, vue_intlayer.installIntlayer)(app, { locale: options.locale });
136
- app.provide(I18nInjectionKey, i18nInstance);
137
- app.config.globalProperties.$t = globalTranslate;
138
- app.config.globalProperties.$tc = globalTranslate;
139
- app.config.globalProperties.$te = global.te;
140
- app.config.globalProperties.$tm = global.tm;
141
- app.config.globalProperties.$rt = global.rt;
142
- app.config.globalProperties.$d = globalDate;
143
- app.config.globalProperties.$n = globalNumber;
144
- app.config.globalProperties.$i18n = legacyI18n;
145
- app.directive("t", {
146
- beforeMount: applyTranslateDirective,
147
- updated: applyTranslateDirective
148
- });
149
- }
150
- };
151
- return i18nInstance;
152
- });
153
- /**
154
- * Composable providing a typed `t()` function scoped to a dictionary namespace.
155
- * Pass `{ namespace: 'myDict' }` to restrict keys to valid dot-notation paths
156
- * within that intlayer dictionary (autocompleted and validated at compile time).
157
- *
158
- * Supports vue-i18n's full message syntax: named (`{name}`) and list (`{0}`)
159
- * interpolation, pipe choice messages (`'car | cars'` with a count argument),
160
- * plus `te`/`tm`/`rt` and `Intl`-backed `d()`/`n()` formatters.
161
- *
162
- * @example
163
- * ```ts
164
- * const { t } = useI18n({ namespace: 'about' });
165
- * t('counter.label'); // ✓ typed; compile error if key doesn't exist
166
- * t('apples', 5); // pipe plural choice
167
- * ```
168
- */
169
- const useI18n = (options) => {
170
- const { locale: currentLocale, setLocale, availableLocales } = (0, vue_intlayer.useLocale)();
171
- const fallbackMessages = (0, vue.inject)(I18nInjectionKey)?.__optionsMessages;
172
- const namespace = options?.namespace;
173
- const datetimeFormats = options?.datetimeFormats;
174
- const numberFormats = options?.numberFormats;
175
- const localeRef = (0, vue.computed)({
176
- get: () => currentLocale.value,
177
- set: (newLocale) => {
178
- setLocale(newLocale);
179
- }
180
- });
181
- const translate = (key, ...args) => translateKey(currentLocale.value, namespace, String(key), args, fallbackMessages);
182
- return {
183
- locale: localeRef,
184
- availableLocales,
185
- t: translate,
186
- tc: translate,
187
- te: (key) => lookupRaw(namespace, String(key)) !== void 0,
188
- tm: (key) => lookupRaw(namespace, String(key)) ?? {},
189
- rt: (message, ...args) => {
190
- const { values, count } = require_resolveVueMessage.parseTranslateArguments(args);
191
- return require_resolveVueMessage.resolveVueMessage(message, values, count, currentLocale.value);
192
- },
193
- d: (value, formatOrOptions) => require_formats.formatDateValue(value, formatOrOptions, currentLocale.value, datetimeFormats),
194
- n: (value, formatOrOptions) => require_formats.formatNumberValue(value, formatOrOptions, currentLocale.value, numberFormats)
195
- };
196
- };
197
-
198
- //#endregion
199
- exports.I18nInjectionKey = I18nInjectionKey;
200
- exports.VERSION = VERSION;
201
- exports.createI18n = createI18n;
202
- exports.useI18n = useI18n;
203
- //# sourceMappingURL=createI18n.cjs.map
@@ -1 +0,0 @@
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 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, inject } 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 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 = (namespace: string | undefined, 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 // Without getDictionaries, global translation fallback to intlayer dictionaries\n // is disabled for bundle optimization purposes.\n // We only lookup if the namespace exists globally, but since we don't have getDictionaries\n // we rely strictly on what vue-i18n already has in its messages.\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 | undefined,\n key: string,\n args: unknown[],\n fallbackMessages?: Record<string, unknown>\n): string => {\n const { values, count, defaultMessage } = parseTranslateArguments(args);\n\n const rawValue = lookupRaw(namespace, key);\n\n if (rawValue === undefined) {\n if (fallbackMessages?.[locale]) {\n // Defer to the user's provided messages if not found in dictionaries\n const targetPath = namespace ? `${namespace}.${key}` : key;\n const fallbackValue = navigatePath(fallbackMessages[locale], targetPath);\n if (fallbackValue !== undefined) {\n return resolveVueMessage(\n fallbackValue,\n values,\n count,\n locale as LocalesValues\n );\n }\n }\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: typeof _createI18n = ((\n options: Record<string, unknown> = {}\n) => {\n const fallbackMessages = options.messages as\n | Record<string, unknown>\n | undefined;\n\n if (\n options.messages !== undefined &&\n process.env.NODE_ENV === 'development'\n ) {\n const appLogger = getAppLogger({ log });\n appLogger(\n `${colorize('createI18n', ANSIColors.CYAN)}: the ${colorize('`messages`', ANSIColors.CYAN)} option is used as a fallback. For optimal bundle size, remove the locale JSON imports and use ${colorize('useDictionary', ANSIColors.CYAN)} or compile your intlayer dictionaries instead:\\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(), undefined, key, args, fallbackMessages);\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 => lookupRaw(undefined, key) !== undefined,\n tm: (key: string): unknown => lookupRaw(undefined, 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): Record<string, unknown> => {\n warnDeprecatedRuntimeMessages('getLocaleMessage');\n // We do not load global dictionaries anymore for bundle optimization.\n // The user should use useDictionary or rely on manually provided messages.\n return {};\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 __optionsMessages: fallbackMessages,\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 const instance = inject(I18nInjectionKey) as\n | Record<string, unknown>\n | undefined;\n const fallbackMessages = instance?.__optionsMessages as\n | Record<string, unknown>\n | undefined;\n\n const namespace = options?.namespace as string | undefined as N | undefined;\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 =>\n translateKey(\n currentLocale.value,\n namespace,\n String(key),\n args,\n fallbackMessages\n );\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(namespace, String(key)) !== undefined,\n tm: <P extends ValidDotPathsFor<N>>(key: P): unknown =>\n lookupRaw(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":";;;;;;;;;;;;AA4BA,MAAa,UAAU;AACvB,MAAa,mBAAuC,OAAO,cAAc;AAEzE,MAAM,gBAAgB,aAAsB,SAA0B;AACpE,KAAI,CAAC,KAAM,QAAO;CAClB,IAAI,UAAmB;AACvB,MAAK,MAAM,QAAQ,KAAK,MAAM,IAAI,EAAE;AAClC,MACE,YAAY,QACZ,YAAY,UACZ,OAAO,YAAY,SAEnB;AAEF,YAAW,QAAoC;;AAEjD,QAAO;;;;;;;;;;;AAYT,MAAM,aAAa,WAA+B,QAAyB;AAIzE,KAAI,IAAI,SAAS,IAAI,EAAE;EACrB,MAAM,iBAAiB,IAAI,QAAQ,IAAI;AACvC,EAAmB,IAAI,MAAM,GAAG,eAAe;AAC/C,EAAQ,IAAI,MAAM,iBAAiB,EAAE;;;;AAYzC,MAAM,gBACJ,QACA,WACA,KACA,MACA,qBACW;CACX,MAAM,EAAE,QAAQ,OAAO,mBAAmBA,kDAAwB,KAAK;CAEvE,MAAM,WAAW,UAAU,WAAW,IAAI;AAE1C,KAAI,aAAa,QAAW;AAC1B,MAAI,mBAAmB,SAAS;GAE9B,MAAM,aAAa,YAAY,GAAG,UAAU,GAAG,QAAQ;GACvD,MAAM,gBAAgB,aAAa,iBAAiB,SAAS,WAAW;AACxE,OAAI,kBAAkB,OACpB,QAAOC,4CACL,eACA,QACA,OACA,OACD;;AAGL,MAAI,mBAAmB,OACrB,QAAOA,4CACL,gBACA,QACA,OACA,OACD;AAEH,SAAO;;AAGT,QAAOA,4CAAkB,UAAU,QAAQ,OAAO,OAAwB;;AAG5E,MAAM,4BACJC,6CAAsB,SAAS,IAAI,OAAO,IAAI,EAAE;AAElD,MAAM,iCAAiC,aAAqB;AAE1D,2CAD+B,EAAE,iCAAK,CAC7B,CACP,yCAAY,UAAUC,wBAAW,KAAK,CAAC,4DAA+B,sBAAsBA,wBAAW,QAAQ,CAAC,oEACjH;;AAQH,MAAa,eACX,UAAmC,EAAE,KAClC;CACH,MAAM,mBAAmB,QAAQ;AAIjC,KACE,QAAQ,aAAa,UACrB,QAAQ,IAAI,aAAa,cAGzB,2CAD+B,EAAE,iCAAK,CAC7B,CACP,yCAAY,cAAcA,wBAAW,KAAK,CAAC,8CAAiB,cAAcA,wBAAW,KAAK,CAAC,uIAA0G,iBAAiBA,wBAAW,KAAK,CAAC,2FAA8D,WAAWA,wBAAW,KAAK,CAAC,oFAAuD,WAAWA,wBAAW,KAAK,CAAC,iBACrZ;CAGH,MAAM,gDAA8B,QAAQ,OAAwB;CAEpE,MAAM,kBAAkB,QAAQ;CAGhC,MAAM,gBAAgB,QAAQ;CAI9B,MAAM,sBAA8B,OAAO,OAAO,OAAO,MAAM;;CAG/D,MAAM,8BAAkD;EACtD,WAAW,eAAe;EAC1B,MAAM,cAAsB;AAC1B,UAAO,UAAU,UAA2B;;EAE/C,CAAC;CAEF,MAAM,mBAAmB,KAAa,GAAG,SACvC,aAAa,eAAe,EAAE,QAAW,KAAK,MAAM,iBAAiB;CAEvE,MAAM,cACJ,OACA,oBAEAC,gCAAgB,OAAO,iBAAiB,eAAe,EAAE,gBAAgB;CAE3E,MAAM,gBACJ,OACA,oBAEAC,kCAAkB,OAAO,iBAAiB,eAAe,EAAE,cAAc;CAE3E,MAAM,SAAS;EACb,QAAQ;EACR,kBAAkB,qBAAqB;EACvC,gBAAiB,QAAQ,kBACvBH,6CAAsB;EACxB,GAAG;EACH,IAAI;EACJ,KAAK,QAAyB,UAAU,QAAW,IAAI,KAAK;EAC5D,KAAK,QAAyB,UAAU,QAAW,IAAI,IAAI,EAAE;EAC7D,KAAK,SAAkB,GAAG,SAA4B;GACpD,MAAM,EAAE,QAAQ,UAAUF,kDAAwB,KAAK;AACvD,UAAOC,4CACL,SACA,QACA,OACA,eAAe,CAChB;;EAEH,GAAG;EACH,GAAG;EACH,mBAAmB,SAAiB,cAAuB;AACzD,iCAA8B,mBAAmB;;EAEnD,qBAAqB,SAAiB,cAAuB;AAC3D,iCAA8B,qBAAqB;;EAErD,mBAAmB,YAA6C;AAC9D,iCAA8B,mBAAmB;AAGjD,UAAO,EAAE;;EAEZ;;CAGD,MAAM,aAAa;EACjB,IAAI,SAAiB;AACnB,UAAO,eAAe;;EAExB,IAAI,OAAO,WAAmB;AAC5B,UAAO,UAAU,UAA2B;;EAE9C,IAAI,mBAA6B;AAC/B,UAAO,qBAAqB;;EAE9B,GAAG;EACH,IAAI;EACJ,IAAI,OAAO;EACX,IAAI,OAAO;EACX,IAAI,OAAO;EACX,GAAG;EACH,GAAG;EACJ;CAED,MAAM,2BACJ,SACA,YACG;EACH,MAAM,eAAe,QAAQ;AAC7B,MAAI,OAAO,iBAAiB,SAC1B,SAAQ,cAAc,gBAAgB,aAAa;WAC1C,gBAAgB,OAAO,iBAAiB,UAAU;GAC3D,MAAM,gBAA2B,EAAE;AACnC,OAAI,aAAa,KAAM,eAAc,KAAK,aAAa,KAAK;AAC5D,OAAI,OAAO,aAAa,WAAW,SACjC,eAAc,KAAK,aAAa,OAAO;AACzC,WAAQ,cAAc,gBACpB,aAAa,MACb,GAAG,cACJ;;;CAIL,MAAM,eAAe;EACnB;EACA,MAAM,QAAQ,WAAW,OAAO,WAAW;EAC3C,mBAAmB;EACnB,QAAQ,KAAU;AAChB,qCAAgB,KAAK,EACnB,QAAQ,QAAQ,QACjB,CAAC;AAGF,OAAI,QAAQ,kBAAkB,aAAgC;AAG9D,OAAI,OAAO,iBAAiB,KAAK;AACjC,GAAC,IAAI,OAAO,iBAA6C,MACvD;AACF,GAAC,IAAI,OAAO,iBAA6C,MAAM,OAAO;AACtE,GAAC,IAAI,OAAO,iBAA6C,MAAM,OAAO;AACtE,GAAC,IAAI,OAAO,iBAA6C,MAAM,OAAO;AACtE,GAAC,IAAI,OAAO,iBAA6C,KAAK;AAC9D,GAAC,IAAI,OAAO,iBAA6C,KACvD;AACF,GAAC,IAAI,OAAO,iBAA6C,QACvD;AAGF,OAAI,UAAU,KAAK;IACjB,aAAa;IACb,SAAS;IACV,CAAC;;EAEL;AAED,QAAO;;;;;;;;;;;;;;;;;;AAmBT,MAAa,WACX,YAiBG;CACH,MAAM,EAAE,QAAQ,eAAe,WAAW,kDAAgC;CAI1E,MAAM,mCAHkB,iBAGS,EAAE;CAInC,MAAM,YAAY,SAAS;CAE3B,MAAM,kBAAkB,SAAS;CAGjC,MAAM,gBAAgB,SAAS;CAI/B,MAAM,8BAAqB;EACzB,WAAW,cAAc;EACzB,MAAM,cAAsB;AAC1B,aAAU,UAA2B;;EAExC,CAAC;CAEF,MAAM,aACJ,KACA,GAAG,SAEH,aACE,cAAc,OACd,WACA,OAAO,IAAI,EACX,MACA,iBACD;AAEH,QAAO;EACL,QAAQ;EACU;EAClB,GAAG;EACH,IAAI;EACJ,KAAoC,QAClC,UAAU,WAAW,OAAO,IAAI,CAAC,KAAK;EACxC,KAAoC,QAClC,UAAU,WAAW,OAAO,IAAI,CAAC,IAAI,EAAE;EACzC,KAAK,SAAkB,GAAG,SAA4B;GACpD,MAAM,EAAE,QAAQ,UAAUD,kDAAwB,KAAK;AACvD,UAAOC,4CACL,SACA,QACA,OACA,cAAc,MACf;;EAEH,IACE,OACA,oBAEAG,gCACE,OACA,iBACA,cAAc,OACd,gBACD;EACH,IACE,OACA,oBAEAC,kCACE,OACA,iBACA,cAAc,OACd,cACD;EACJ"}
@@ -1,31 +0,0 @@
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
@@ -1 +0,0 @@
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,MAAM;AAGjD,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"}
@@ -1,11 +0,0 @@
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;
@@ -1,55 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,67 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,71 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
3
- const require_formats = require('./formats.cjs');
4
- const require_resolveVueMessage = require('./resolveVueMessage.cjs');
5
- let vue = require("vue");
6
- let vue_intlayer = require("vue-intlayer");
7
-
8
- //#region src/useDictionary.ts
9
- const navigatePath = (objectValue, path) => {
10
- if (!path) return objectValue;
11
- const parts = path.split(".");
12
- let current = objectValue;
13
- for (const part of parts) {
14
- if (current === null || current === void 0 || typeof current !== "object") return;
15
- current = current[part];
16
- }
17
- return current;
18
- };
19
- /**
20
- * Dictionary-accepting variant of `useI18n`.
21
- *
22
- * Used internally by the Babel optimization: instead of looking up the dictionary
23
- * at runtime by key, the Babel plugin pre-imports the dictionary JSON at build time
24
- * and passes it directly here. This enables tree-shaking of unused locale content.
25
- */
26
- const useDictionary = (dictionary, options) => {
27
- const { locale: currentLocale, setLocale, availableLocales } = (0, vue_intlayer.useLocale)();
28
- const namespacePrefix = options?.namespace;
29
- const datetimeFormats = options?.datetimeFormats;
30
- const numberFormats = options?.numberFormats;
31
- const content = (0, vue_intlayer.useDictionary)(dictionary);
32
- const localeRef = (0, vue.computed)({
33
- get: () => currentLocale.value,
34
- set: (newLocale) => {
35
- setLocale(newLocale);
36
- }
37
- });
38
- const resolveKey = (lookupKey) => namespacePrefix ? `${namespacePrefix}.${lookupKey}` : lookupKey;
39
- const lookupRaw = (key) => {
40
- const result = navigatePath(content, resolveKey(key));
41
- return result?.$raw?.value ?? result?.value ?? result;
42
- };
43
- const translateKey = (key, args) => {
44
- const { values, count, defaultMessage } = require_resolveVueMessage.parseTranslateArguments(args);
45
- const rawValue = lookupRaw(key);
46
- if (rawValue === void 0) {
47
- if (defaultMessage !== void 0) return require_resolveVueMessage.resolveVueMessage(defaultMessage, values, count, currentLocale.value);
48
- return key;
49
- }
50
- return require_resolveVueMessage.resolveVueMessage(rawValue, values, count, currentLocale.value);
51
- };
52
- const translate = (key, ...args) => translateKey(String(key), args);
53
- return {
54
- locale: localeRef,
55
- availableLocales,
56
- t: translate,
57
- tc: translate,
58
- te: (key) => lookupRaw(String(key)) !== void 0,
59
- tm: (key) => lookupRaw(String(key)) ?? {},
60
- rt: (message, ...args) => {
61
- const { values, count } = require_resolveVueMessage.parseTranslateArguments(args);
62
- return require_resolveVueMessage.resolveVueMessage(message, values, count, currentLocale.value);
63
- },
64
- d: (value, formatOrOptions) => require_formats.formatDateValue(value, formatOrOptions, currentLocale.value, datetimeFormats),
65
- n: (value, formatOrOptions) => require_formats.formatNumberValue(value, formatOrOptions, currentLocale.value, numberFormats)
66
- };
67
- };
68
-
69
- //#endregion
70
- exports.useDictionary = useDictionary;
71
- //# sourceMappingURL=useDictionary.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useDictionary.cjs","names":["parseTranslateArguments","resolveVueMessage","formatDateValue","formatNumberValue"],"sources":["../../src/useDictionary.ts"],"sourcesContent":["import type { ValidDotPathsFor } from '@intlayer/core/transpiler';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DictionaryKeys,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { computed, type WritableComputedRef } from 'vue';\nimport { useDictionary as useDictionaryBase, 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\nconst navigatePath = (objectValue: unknown, path: string): unknown => {\n if (!path) return objectValue;\n const parts = path.split('.');\n let current: unknown = objectValue;\n for (const part of parts) {\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 * Dictionary-accepting variant of `useI18n`.\n *\n * Used internally by the Babel optimization: instead of looking up the dictionary\n * at runtime by key, the Babel 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 = <\n const T extends Dictionary,\n const N extends DictionaryKeys = DictionaryKeys,\n>(\n dictionary: T,\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 namespacePrefix = options?.namespace as string | undefined;\n\n const datetimeFormats = options?.datetimeFormats as\n | DateTimeFormatsConfig\n | undefined;\n const numberFormats = options?.numberFormats as\n | NumberFormatsConfig\n | undefined;\n\n const content = useDictionaryBase(dictionary);\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 resolveKey = (lookupKey: string): string =>\n namespacePrefix ? `${namespacePrefix}.${lookupKey}` : lookupKey;\n\n const lookupRaw = (key: string): unknown => {\n // navigatePath on the returned proxy will correctly resolve nested properties\n const result = navigatePath(content, resolveKey(key));\n // For leaf nodes, we can access .value to get the real underlying primitive/node\n return (result as any)?.$raw?.value ?? (result as any)?.value ?? result;\n };\n\n const translateKey = (key: string, args: unknown[]): string => {\n const { values, count, defaultMessage } = parseTranslateArguments(args);\n const rawValue = lookupRaw(key);\n\n if (rawValue === undefined) {\n if (defaultMessage !== undefined) {\n return resolveVueMessage(\n defaultMessage,\n values,\n count,\n currentLocale.value as LocalesValues\n );\n }\n return key;\n }\n\n return resolveVueMessage(\n rawValue,\n values,\n count,\n currentLocale.value as LocalesValues\n );\n };\n\n const translate = <P extends ValidDotPathsFor<N>>(\n key: P,\n ...args: unknown[]\n ): string => translateKey(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(String(key)) !== undefined,\n tm: <P extends ValidDotPathsFor<N>>(key: P): unknown =>\n lookupRaw(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":";;;;;;;;AAmBA,MAAM,gBAAgB,aAAsB,SAA0B;AACpE,KAAI,CAAC,KAAM,QAAO;CAClB,MAAM,QAAQ,KAAK,MAAM,IAAI;CAC7B,IAAI,UAAmB;AACvB,MAAK,MAAM,QAAQ,OAAO;AACxB,MACE,YAAY,QACZ,YAAY,UACZ,OAAO,YAAY,SAEnB;AAEF,YAAW,QAAoC;;AAEjD,QAAO;;;;;;;;;AAUT,MAAa,iBAIX,YACA,YAiBG;CACH,MAAM,EAAE,QAAQ,eAAe,WAAW,kDAAgC;CAE1E,MAAM,kBAAkB,SAAS;CAEjC,MAAM,kBAAkB,SAAS;CAGjC,MAAM,gBAAgB,SAAS;CAI/B,MAAM,0CAA4B,WAAW;CAE7C,MAAM,8BAAqB;EACzB,WAAW,cAAc;EACzB,MAAM,cAAsB;AAC1B,aAAU,UAA2B;;EAExC,CAAC;CAEF,MAAM,cAAc,cAClB,kBAAkB,GAAG,gBAAgB,GAAG,cAAc;CAExD,MAAM,aAAa,QAAyB;EAE1C,MAAM,SAAS,aAAa,SAAS,WAAW,IAAI,CAAC;AAErD,SAAQ,QAAgB,MAAM,SAAU,QAAgB,SAAS;;CAGnE,MAAM,gBAAgB,KAAa,SAA4B;EAC7D,MAAM,EAAE,QAAQ,OAAO,mBAAmBA,kDAAwB,KAAK;EACvE,MAAM,WAAW,UAAU,IAAI;AAE/B,MAAI,aAAa,QAAW;AAC1B,OAAI,mBAAmB,OACrB,QAAOC,4CACL,gBACA,QACA,OACA,cAAc,MACf;AAEH,UAAO;;AAGT,SAAOA,4CACL,UACA,QACA,OACA,cAAc,MACf;;CAGH,MAAM,aACJ,KACA,GAAG,SACQ,aAAa,OAAO,IAAI,EAAE,KAAK;AAE5C,QAAO;EACL,QAAQ;EACU;EAClB,GAAG;EACH,IAAI;EACJ,KAAoC,QAClC,UAAU,OAAO,IAAI,CAAC,KAAK;EAC7B,KAAoC,QAClC,UAAU,OAAO,IAAI,CAAC,IAAI,EAAE;EAC9B,KAAK,SAAkB,GAAG,SAA4B;GACpD,MAAM,EAAE,QAAQ,UAAUD,kDAAwB,KAAK;AACvD,UAAOC,4CACL,SACA,QACA,OACA,cAAc,MACf;;EAEH,IACE,OACA,oBAEAC,gCACE,OACA,iBACA,cAAc,OACd,gBACD;EACH,IACE,OACA,oBAEAC,kCACE,OACA,iBACA,cAAc,OACd,cACD;EACJ"}
@@ -1,71 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
3
- const require_formats = require('./formats.cjs');
4
- const require_resolveVueMessage = require('./resolveVueMessage.cjs');
5
- let vue = require("vue");
6
- let vue_intlayer = require("vue-intlayer");
7
-
8
- //#region src/useDictionaryDynamic.ts
9
- const navigatePath = (objectValue, path) => {
10
- if (!path) return objectValue;
11
- const parts = path.split(".");
12
- let current = objectValue;
13
- for (const part of parts) {
14
- if (current === null || current === void 0 || typeof current !== "object") return;
15
- current = current[part];
16
- }
17
- return current;
18
- };
19
- /**
20
- * Dynamic dictionary-accepting variant of `useI18n`.
21
- *
22
- * Used internally by the Babel optimization: instead of looking up the dictionary
23
- * at runtime by key, the Babel plugin dynamically imports the dictionary JSON
24
- * (or .mjs module) based on the locale.
25
- */
26
- const useDictionaryDynamic = (dictionaryPromise, key, options) => {
27
- const { locale: currentLocale, setLocale, availableLocales } = (0, vue_intlayer.useLocale)();
28
- const namespacePrefix = options?.namespace;
29
- const datetimeFormats = options?.datetimeFormats;
30
- const numberFormats = options?.numberFormats;
31
- const content = (0, vue_intlayer.useDictionaryDynamic)(dictionaryPromise, key);
32
- const localeRef = (0, vue.computed)({
33
- get: () => currentLocale.value,
34
- set: (newLocale) => {
35
- setLocale(newLocale);
36
- }
37
- });
38
- const resolveKey = (lookupKey) => namespacePrefix ? `${namespacePrefix}.${lookupKey}` : lookupKey;
39
- const lookupRaw = (lookupKey) => {
40
- const result = navigatePath(content, resolveKey(lookupKey));
41
- return result?.$raw?.value ?? result?.value ?? result;
42
- };
43
- const translateKey = (lookupKey, args) => {
44
- const { values, count, defaultMessage } = require_resolveVueMessage.parseTranslateArguments(args);
45
- const rawValue = lookupRaw(lookupKey);
46
- if (rawValue === void 0) {
47
- if (defaultMessage !== void 0) return require_resolveVueMessage.resolveVueMessage(defaultMessage, values, count, currentLocale.value);
48
- return lookupKey;
49
- }
50
- return require_resolveVueMessage.resolveVueMessage(rawValue, values, count, currentLocale.value);
51
- };
52
- const translate = (lookupKey, ...args) => translateKey(String(lookupKey), args);
53
- return {
54
- locale: localeRef,
55
- availableLocales,
56
- t: translate,
57
- tc: translate,
58
- te: (lookupKey) => lookupRaw(String(lookupKey)) !== void 0,
59
- tm: (lookupKey) => lookupRaw(String(lookupKey)) ?? {},
60
- rt: (message, ...args) => {
61
- const { values, count } = require_resolveVueMessage.parseTranslateArguments(args);
62
- return require_resolveVueMessage.resolveVueMessage(message, values, count, currentLocale.value);
63
- },
64
- d: (value, formatOrOptions) => require_formats.formatDateValue(value, formatOrOptions, currentLocale.value, datetimeFormats),
65
- n: (value, formatOrOptions) => require_formats.formatNumberValue(value, formatOrOptions, currentLocale.value, numberFormats)
66
- };
67
- };
68
-
69
- //#endregion
70
- exports.useDictionaryDynamic = useDictionaryDynamic;
71
- //# sourceMappingURL=useDictionaryDynamic.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useDictionaryDynamic.cjs","names":["parseTranslateArguments","resolveVueMessage","formatDateValue","formatNumberValue"],"sources":["../../src/useDictionaryDynamic.ts"],"sourcesContent":["import type { ValidDotPathsFor } from '@intlayer/core/transpiler';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DictionaryKeys,\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';\nimport {\n type DateTimeFormatsConfig,\n formatDateValue,\n formatNumberValue,\n type NumberFormatsConfig,\n} from './formats';\nimport {\n parseTranslateArguments,\n resolveVueMessage,\n} from './resolveVueMessage';\n\nconst navigatePath = (objectValue: unknown, path: string): unknown => {\n if (!path) return objectValue;\n const parts = path.split('.');\n let current: unknown = objectValue;\n for (const part of parts) {\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 * Dynamic dictionary-accepting variant of `useI18n`.\n *\n * Used internally by the Babel optimization: instead of looking up the dictionary\n * at runtime by key, the Babel plugin dynamically imports the dictionary JSON\n * (or .mjs module) based on the locale.\n */\nexport const useDictionaryDynamic = <\n const T extends Dictionary,\n const K extends string,\n const N extends DictionaryKeys = DictionaryKeys,\n>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n key: K,\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 namespacePrefix = options?.namespace as string | undefined;\n\n const datetimeFormats = options?.datetimeFormats as\n | DateTimeFormatsConfig\n | undefined;\n const numberFormats = options?.numberFormats as\n | NumberFormatsConfig\n | undefined;\n\n const content = useDictionaryDynamicBase<T, any>(\n dictionaryPromise,\n key as any\n );\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 resolveKey = (lookupKey: string): string =>\n namespacePrefix ? `${namespacePrefix}.${lookupKey}` : lookupKey;\n\n const lookupRaw = (lookupKey: string): unknown => {\n // navigatePath on the returned proxy will correctly resolve nested properties\n const result = navigatePath(content, resolveKey(lookupKey));\n // For leaf nodes, we can access .value to get the real underlying primitive/node\n return (result as any)?.$raw?.value ?? (result as any)?.value ?? result;\n };\n\n const translateKey = (lookupKey: string, args: unknown[]): string => {\n const { values, count, defaultMessage } = parseTranslateArguments(args);\n const rawValue = lookupRaw(lookupKey);\n\n if (rawValue === undefined) {\n if (defaultMessage !== undefined) {\n return resolveVueMessage(\n defaultMessage,\n values,\n count,\n currentLocale.value as LocalesValues\n );\n }\n return lookupKey;\n }\n\n return resolveVueMessage(\n rawValue,\n values,\n count,\n currentLocale.value as LocalesValues\n );\n };\n\n const translate = <P extends ValidDotPathsFor<N>>(\n lookupKey: P,\n ...args: unknown[]\n ): string => translateKey(String(lookupKey), args);\n\n return {\n locale: localeRef,\n availableLocales: availableLocales as string[],\n t: translate,\n tc: translate,\n te: <P extends ValidDotPathsFor<N>>(lookupKey: P): boolean =>\n lookupRaw(String(lookupKey)) !== undefined,\n tm: <P extends ValidDotPathsFor<N>>(lookupKey: P): unknown =>\n lookupRaw(String(lookupKey)) ?? {},\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":";;;;;;;;AAuBA,MAAM,gBAAgB,aAAsB,SAA0B;AACpE,KAAI,CAAC,KAAM,QAAO;CAClB,MAAM,QAAQ,KAAK,MAAM,IAAI;CAC7B,IAAI,UAAmB;AACvB,MAAK,MAAM,QAAQ,OAAO;AACxB,MACE,YAAY,QACZ,YAAY,UACZ,OAAO,YAAY,SAEnB;AAEF,YAAW,QAAoC;;AAEjD,QAAO;;;;;;;;;AAUT,MAAa,wBAKX,mBACA,KACA,YAiBG;CACH,MAAM,EAAE,QAAQ,eAAe,WAAW,kDAAgC;CAE1E,MAAM,kBAAkB,SAAS;CAEjC,MAAM,kBAAkB,SAAS;CAGjC,MAAM,gBAAgB,SAAS;CAI/B,MAAM,iDACJ,mBACA,IACD;CAED,MAAM,8BAAqB;EACzB,WAAW,cAAc;EACzB,MAAM,cAAsB;AAC1B,aAAU,UAA2B;;EAExC,CAAC;CAEF,MAAM,cAAc,cAClB,kBAAkB,GAAG,gBAAgB,GAAG,cAAc;CAExD,MAAM,aAAa,cAA+B;EAEhD,MAAM,SAAS,aAAa,SAAS,WAAW,UAAU,CAAC;AAE3D,SAAQ,QAAgB,MAAM,SAAU,QAAgB,SAAS;;CAGnE,MAAM,gBAAgB,WAAmB,SAA4B;EACnE,MAAM,EAAE,QAAQ,OAAO,mBAAmBA,kDAAwB,KAAK;EACvE,MAAM,WAAW,UAAU,UAAU;AAErC,MAAI,aAAa,QAAW;AAC1B,OAAI,mBAAmB,OACrB,QAAOC,4CACL,gBACA,QACA,OACA,cAAc,MACf;AAEH,UAAO;;AAGT,SAAOA,4CACL,UACA,QACA,OACA,cAAc,MACf;;CAGH,MAAM,aACJ,WACA,GAAG,SACQ,aAAa,OAAO,UAAU,EAAE,KAAK;AAElD,QAAO;EACL,QAAQ;EACU;EAClB,GAAG;EACH,IAAI;EACJ,KAAoC,cAClC,UAAU,OAAO,UAAU,CAAC,KAAK;EACnC,KAAoC,cAClC,UAAU,OAAO,UAAU,CAAC,IAAI,EAAE;EACpC,KAAK,SAAkB,GAAG,SAA4B;GACpD,MAAM,EAAE,QAAQ,UAAUD,kDAAwB,KAAK;AACvD,UAAOC,4CACL,SACA,QACA,OACA,cAAc,MACf;;EAEH,IACE,OACA,oBAEAC,gCACE,OACA,iBACA,cAAc,OACd,gBACD;EACH,IACE,OACA,oBAEAC,kCACE,OACA,iBACA,cAAc,OACd,cACD;EACJ"}