@intlayer/use-intl 9.5.3 → 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 +8 -8
- package/dist/esm/client/index.mjs +1 -1
- package/dist/esm/index.mjs +1 -1
- package/package.json +11 -10
- package/dist/cjs/_virtual/_rolldown/runtime.cjs +0 -29
- package/dist/cjs/client/IntlProvider.cjs +0 -30
- package/dist/cjs/client/IntlProvider.cjs.map +0 -1
- package/dist/cjs/client/helpers.cjs +0 -49
- package/dist/cjs/client/helpers.cjs.map +0 -1
- package/dist/cjs/client/index.cjs +0 -27
- package/dist/cjs/client/index.cjs.map +0 -1
- package/dist/cjs/client/useLocale.cjs +0 -20
- package/dist/cjs/client/useLocale.cjs.map +0 -1
- package/dist/cjs/client/useTranslations.cjs +0 -39
- package/dist/cjs/client/useTranslations.cjs.map +0 -1
- package/dist/cjs/core/createFormatter.cjs +0 -23
- package/dist/cjs/core/createFormatter.cjs.map +0 -1
- package/dist/cjs/core/createTranslator.cjs +0 -30
- package/dist/cjs/core/createTranslator.cjs.map +0 -1
- package/dist/cjs/core/errors.cjs +0 -42
- package/dist/cjs/core/errors.cjs.map +0 -1
- package/dist/cjs/core/hasLocale.cjs +0 -23
- package/dist/cjs/core/hasLocale.cjs.map +0 -1
- package/dist/cjs/core/index.cjs +0 -13
- package/dist/cjs/core/initializeConfig.cjs +0 -25
- package/dist/cjs/core/initializeConfig.cjs.map +0 -1
- package/dist/cjs/core/types.cjs +0 -0
- package/dist/cjs/index.cjs +0 -30
- package/dist/cjs/plugin/index.cjs +0 -80
- package/dist/cjs/plugin/index.cjs.map +0 -1
- package/dist/cjs/shared/intlFormatter.cjs +0 -63
- package/dist/cjs/shared/intlFormatter.cjs.map +0 -1
- package/dist/cjs/shared/namespaceTranslator.cjs +0 -122
- package/dist/cjs/shared/namespaceTranslator.cjs.map +0 -1
- package/dist/cjs/shared/translateFunctionTypes.cjs +0 -0
- package/dist/cjs/useDictionary.cjs +0 -37
- package/dist/cjs/useDictionary.cjs.map +0 -1
- package/dist/cjs/useDictionaryDynamic.cjs +0 -31
- package/dist/cjs/useDictionaryDynamic.cjs.map +0 -1
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.
|
|
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.
|
|
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.
|
|
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.
|
|
64
|
-
| <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/bundle.
|
|
65
|
-
| <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/static_rendering.
|
|
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.
|
|
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
|
-

|
|
266
266
|
|
|
267
267
|
## 🌐 Readme in other languages
|
|
268
268
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { useDictionaryDynamic } from "../useDictionaryDynamic.mjs";
|
|
2
1
|
import { useDictionary } from "../useDictionary.mjs";
|
|
2
|
+
import { useDictionaryDynamic } from "../useDictionaryDynamic.mjs";
|
|
3
3
|
import { useFormatter, useMessages, useNow, useTimeZone } from "./helpers.mjs";
|
|
4
4
|
import { IntlProvider } from "./IntlProvider.mjs";
|
|
5
5
|
import { useLocale } from "./useLocale.mjs";
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createDictionaryTranslator } from "./shared/namespaceTranslator.mjs";
|
|
2
|
-
import { useDictionaryDynamic } from "./useDictionaryDynamic.mjs";
|
|
3
2
|
import { useDictionary } from "./useDictionary.mjs";
|
|
3
|
+
import { useDictionaryDynamic } from "./useDictionaryDynamic.mjs";
|
|
4
4
|
import { useFormatter, useMessages, useNow, useTimeZone } from "./client/helpers.mjs";
|
|
5
5
|
import { IntlProvider } from "./client/IntlProvider.mjs";
|
|
6
6
|
import { useLocale } from "./client/useLocale.mjs";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intlayer/use-intl",
|
|
3
|
-
"version": "9.5.
|
|
3
|
+
"version": "9.5.4-canary.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "use-intl API adapter for intlayer — useTranslations, useLocale, useFormatter, IntlProvider, createTranslator backed by react-intlayer",
|
|
6
6
|
"keywords": [
|
|
@@ -83,19 +83,20 @@
|
|
|
83
83
|
"prepublish": "cp -f ../../README.md ./README.md",
|
|
84
84
|
"publish": "bun publish || true",
|
|
85
85
|
"publish:canary": "bun publish --access public --tag canary || true",
|
|
86
|
+
"publish:ci": "bun ../../scripts/publish-package.mjs",
|
|
86
87
|
"publish:latest": "bun publish --access public --tag latest || true",
|
|
87
88
|
"test": "bun --bun vitest run",
|
|
88
89
|
"test:watch": "bun --bun vitest",
|
|
89
90
|
"typecheck": "tsc --noEmit --project tsconfig.types.json"
|
|
90
91
|
},
|
|
91
92
|
"dependencies": {
|
|
92
|
-
"@intlayer/config": "9.5.
|
|
93
|
-
"@intlayer/core": "9.5.
|
|
94
|
-
"@intlayer/dictionaries-entry": "9.5.
|
|
95
|
-
"@intlayer/engine": "9.5.
|
|
96
|
-
"@intlayer/types": "9.5.
|
|
97
|
-
"react-intlayer": "9.5.
|
|
98
|
-
"vite-intlayer": "9.5.
|
|
93
|
+
"@intlayer/config": "9.5.4-canary.0",
|
|
94
|
+
"@intlayer/core": "9.5.4-canary.0",
|
|
95
|
+
"@intlayer/dictionaries-entry": "9.5.4-canary.0",
|
|
96
|
+
"@intlayer/engine": "9.5.4-canary.0",
|
|
97
|
+
"@intlayer/types": "9.5.4-canary.0",
|
|
98
|
+
"react-intlayer": "9.5.4-canary.0",
|
|
99
|
+
"vite-intlayer": "9.5.4-canary.0"
|
|
99
100
|
},
|
|
100
101
|
"devDependencies": {
|
|
101
102
|
"@types/node": "^22",
|
|
@@ -106,9 +107,9 @@
|
|
|
106
107
|
"rimraf": "6.1.3",
|
|
107
108
|
"tsdown": "0.23.0",
|
|
108
109
|
"typescript": "7.0.2",
|
|
109
|
-
"use-intl": "4.14.
|
|
110
|
+
"use-intl": "4.14.5",
|
|
110
111
|
"vite": "8.3.0",
|
|
111
|
-
"vitest": "5.0.
|
|
112
|
+
"vitest": "5.0.1"
|
|
112
113
|
},
|
|
113
114
|
"peerDependencies": {
|
|
114
115
|
"react": ">=16.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,30 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
5
|
-
let react_intlayer = require("react-intlayer");
|
|
6
|
-
let react_jsx_runtime = require("react/jsx-runtime");
|
|
7
|
-
let _intlayer_config_built = require("@intlayer/config/built");
|
|
8
|
-
let _intlayer_config_colors = require("@intlayer/config/colors");
|
|
9
|
-
let _intlayer_config_logger = require("@intlayer/config/logger");
|
|
10
|
-
|
|
11
|
-
//#region src/client/IntlProvider.tsx
|
|
12
|
-
/**
|
|
13
|
-
* Drop-in for use-intl's `IntlProvider`.
|
|
14
|
-
*
|
|
15
|
-
* Wraps Intlayer's `IntlayerProvider`, seeding the client locale from the
|
|
16
|
-
* `locale` prop. `messages`, `formats`, `now`, `timeZone`, `onError`, and
|
|
17
|
-
* `getMessageFallback` are accepted for API compatibility but have no effect —
|
|
18
|
-
* Intlayer uses its own compiled dictionaries.
|
|
19
|
-
*/
|
|
20
|
-
const IntlProvider = ({ locale, children, messages: _messages, formats: _formats, now: _now, timeZone: _timeZone, onError: _onError, getMessageFallback: _getMessageFallback }) => {
|
|
21
|
-
if (process.env.NODE_ENV === "development" && typeof _messages !== "undefined") (0, _intlayer_config_logger.getAppLogger)({ log: _intlayer_config_built.log })(`${(0, _intlayer_config_logger.colorize)("IntlProvider", _intlayer_config_colors.CYAN)} do not pass the messages prop with intlayer. Messages are loaded automatically under the hood for bundle optimization reason`);
|
|
22
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_intlayer.IntlayerProvider, {
|
|
23
|
-
locale,
|
|
24
|
-
children
|
|
25
|
-
}, String(locale));
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
//#endregion
|
|
29
|
-
exports.IntlProvider = IntlProvider;
|
|
30
|
-
//# sourceMappingURL=IntlProvider.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"IntlProvider.cjs","names":["CYAN","IntlayerProvider"],"sources":["../../../src/client/IntlProvider.tsx"],"sourcesContent":["'use client';\n\nimport { log } from '@intlayer/config/built';\nimport { CYAN } from '@intlayer/config/colors';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport type { ComponentProps } from 'react';\nimport { IntlayerProvider } from 'react-intlayer';\nimport type { IntlProvider as _IntlProvider } from 'use-intl';\n\n/**\n * Drop-in for use-intl's `IntlProvider`.\n *\n * Wraps Intlayer's `IntlayerProvider`, seeding the client locale from the\n * `locale` prop. `messages`, `formats`, `now`, `timeZone`, `onError`, and\n * `getMessageFallback` are accepted for API compatibility but have no effect —\n * Intlayer uses its own compiled dictionaries.\n */\nexport const IntlProvider: typeof _IntlProvider = ({\n locale,\n children,\n messages: _messages,\n formats: _formats,\n now: _now,\n timeZone: _timeZone,\n onError: _onError,\n getMessageFallback: _getMessageFallback,\n}) => {\n if (\n process.env.NODE_ENV === 'development' &&\n typeof _messages !== 'undefined'\n ) {\n const appLogger = getAppLogger({ log });\n appLogger(\n `${colorize('IntlProvider', CYAN)} do not pass the messages prop with intlayer. Messages are loaded automatically under the hood for bundle optimization reason`\n );\n }\n\n // `key={locale}` re-seeds the client locale context when the locale changes,\n // so consumers re-render in the new language.\n return (\n <IntlayerProvider key={String(locale)} locale={locale as LocalesValues}>\n {children}\n </IntlayerProvider>\n );\n};\n\n/**\n * Props accepted by {@link IntlProvider}. `messages` is deprecated — Intlayer\n * loads content from compiled dictionaries automatically.\n */\nexport type IntlProviderProps = Omit<\n ComponentProps<typeof _IntlProvider>,\n 'messages' | 'locale'\n> & {\n /**\n * @deprecated has no use case with intlayer. Messages are loaded\n * automatically under the hood for bundle optimization reason.\n */\n messages?: never;\n /** The active locale. */\n locale: LocalesValues;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAkBA,MAAa,gBAAsC,EACjD,QACA,UACA,UAAU,WACV,SAAS,UACT,KAAK,MACL,UAAU,WACV,SAAS,UACT,oBAAoB,0BAChB;AACJ,KACE,QAAQ,IAAI,aAAa,iBACzB,OAAO,cAAc,YAGrB,2CAD+B,EAAE,iCAAK,CAC7B,CACP,yCAAY,gBAAgBA,6BAAK,CAAC,+HACnC;AAKH,QACE,2CAACC,iCAAD;EAA+C;EAC5C;EACgB,EAFI,OAAO,OAAO,CAElB"}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
5
|
-
const require_shared_intlFormatter = require('../shared/intlFormatter.cjs');
|
|
6
|
-
let react_intlayer = require("react-intlayer");
|
|
7
|
-
let _intlayer_config_built = require("@intlayer/config/built");
|
|
8
|
-
let _intlayer_config_colors = require("@intlayer/config/colors");
|
|
9
|
-
let _intlayer_config_logger = require("@intlayer/config/logger");
|
|
10
|
-
|
|
11
|
-
//#region src/client/helpers.ts
|
|
12
|
-
/**
|
|
13
|
-
* Drop-in for use-intl's `useNow`.
|
|
14
|
-
* Returns the current `Date`. The `updateInterval` option is ignored.
|
|
15
|
-
*/
|
|
16
|
-
const useNow = () => /* @__PURE__ */ new Date();
|
|
17
|
-
/**
|
|
18
|
-
* Drop-in for use-intl's `useTimeZone`.
|
|
19
|
-
* Returns the system time zone resolved from `Intl.DateTimeFormat`.
|
|
20
|
-
*/
|
|
21
|
-
const useTimeZone = () => Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
22
|
-
/**
|
|
23
|
-
* Drop-in for use-intl's `useMessages`.
|
|
24
|
-
*
|
|
25
|
-
* @deprecated useMessages has no use case with intlayer.
|
|
26
|
-
* Messages are loaded automatically under the hood.
|
|
27
|
-
* @returns An empty object.
|
|
28
|
-
*/
|
|
29
|
-
const useMessages = () => {
|
|
30
|
-
if (process.env.NODE_ENV === "development") (0, _intlayer_config_logger.getAppLogger)({ log: _intlayer_config_built.log })(`${(0, _intlayer_config_logger.colorize)("useMessages", _intlayer_config_colors.CYAN)} has no use case with intlayer. Messages are loaded automatically under the hood for bundle optimization reason`);
|
|
31
|
-
return {};
|
|
32
|
-
};
|
|
33
|
-
/**
|
|
34
|
-
* Drop-in for use-intl's `useFormatter`.
|
|
35
|
-
* Returns locale-aware formatters backed by the native `Intl.*` APIs:
|
|
36
|
-
* `dateTime`, `number`, `dateTimeRange`, `relativeTime`, `list`, and
|
|
37
|
-
* `displayName`.
|
|
38
|
-
*/
|
|
39
|
-
const useFormatter = () => {
|
|
40
|
-
const { locale } = (0, react_intlayer.useLocale)();
|
|
41
|
-
return require_shared_intlFormatter.buildIntlFormatter(locale ?? "en");
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
//#endregion
|
|
45
|
-
exports.useFormatter = useFormatter;
|
|
46
|
-
exports.useMessages = useMessages;
|
|
47
|
-
exports.useNow = useNow;
|
|
48
|
-
exports.useTimeZone = useTimeZone;
|
|
49
|
-
//# sourceMappingURL=helpers.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.cjs","names":["CYAN","buildIntlFormatter"],"sources":["../../../src/client/helpers.ts"],"sourcesContent":["'use client';\n\nimport { log } from '@intlayer/config/built';\nimport { CYAN } from '@intlayer/config/colors';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport { useLocale as useLocaleIntlayer } from 'react-intlayer';\nimport type {\n useFormatter as _useFormatter,\n useMessages as _useMessages,\n useNow as _useNow,\n useTimeZone as _useTimeZone,\n} from 'use-intl';\nimport { buildIntlFormatter } from '../shared/intlFormatter';\n\n/**\n * Drop-in for use-intl's `useNow`.\n * Returns the current `Date`. The `updateInterval` option is ignored.\n */\nexport const useNow: typeof _useNow = () => new Date();\n\n/**\n * Drop-in for use-intl's `useTimeZone`.\n * Returns the system time zone resolved from `Intl.DateTimeFormat`.\n */\nexport const useTimeZone: typeof _useTimeZone = () =>\n Intl.DateTimeFormat().resolvedOptions().timeZone;\n\n/**\n * Drop-in for use-intl's `useMessages`.\n *\n * @deprecated useMessages has no use case with intlayer.\n * Messages are loaded automatically under the hood.\n * @returns An empty object.\n */\nexport const useMessages: typeof _useMessages = () => {\n if (process.env.NODE_ENV === 'development') {\n const appLogger = getAppLogger({ log });\n appLogger(\n `${colorize('useMessages', CYAN)} has no use case with intlayer. Messages are loaded automatically under the hood for bundle optimization reason`\n );\n }\n\n return {} as ReturnType<typeof _useMessages>;\n};\n\n/**\n * Drop-in for use-intl's `useFormatter`.\n * Returns locale-aware formatters backed by the native `Intl.*` APIs:\n * `dateTime`, `number`, `dateTimeRange`, `relativeTime`, `list`, and\n * `displayName`.\n */\nexport const useFormatter: typeof _useFormatter = () => {\n const { locale } = useLocaleIntlayer();\n return buildIntlFormatter((locale as string) ?? 'en');\n};\n"],"mappings":";;;;;;;;;;;;;;;AAkBA,MAAa,+BAA+B,IAAI,MAAM;;;;;AAMtD,MAAa,oBACX,KAAK,gBAAgB,CAAC,iBAAiB,CAAC;;;;;;;;AAS1C,MAAa,oBAAyC;AACpD,KAAI,QAAQ,IAAI,aAAa,cAE3B,2CAD+B,EAAE,iCAAK,CAC7B,CACP,yCAAY,eAAeA,6BAAK,CAAC,iHAClC;AAGH,QAAO,EAAE;;;;;;;;AASX,MAAa,qBAA2C;CACtD,MAAM,EAAE,0CAA8B;AACtC,QAAOC,gDAAoB,UAAqB,KAAK"}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_useDictionaryDynamic = require('../useDictionaryDynamic.cjs');
|
|
3
|
-
const require_useDictionary = require('../useDictionary.cjs');
|
|
4
|
-
const require_client_helpers = require('./helpers.cjs');
|
|
5
|
-
const require_client_IntlProvider = require('./IntlProvider.cjs');
|
|
6
|
-
const require_client_useLocale = require('./useLocale.cjs');
|
|
7
|
-
const require_client_useTranslations = require('./useTranslations.cjs');
|
|
8
|
-
|
|
9
|
-
//#region src/client/index.ts
|
|
10
|
-
/**
|
|
11
|
-
* @internal Private use-intl export, kept so aliased `_useExtracted` imports
|
|
12
|
-
* resolve. Not part of the supported public surface.
|
|
13
|
-
*/
|
|
14
|
-
const _useExtracted = () => ({});
|
|
15
|
-
|
|
16
|
-
//#endregion
|
|
17
|
-
exports.IntlProvider = require_client_IntlProvider.IntlProvider;
|
|
18
|
-
exports._useExtracted = _useExtracted;
|
|
19
|
-
exports.useDictionary = require_useDictionary.useDictionary;
|
|
20
|
-
exports.useDictionaryDynamic = require_useDictionaryDynamic.useDictionaryDynamic;
|
|
21
|
-
exports.useFormatter = require_client_helpers.useFormatter;
|
|
22
|
-
exports.useLocale = require_client_useLocale.useLocale;
|
|
23
|
-
exports.useMessages = require_client_helpers.useMessages;
|
|
24
|
-
exports.useNow = require_client_helpers.useNow;
|
|
25
|
-
exports.useTimeZone = require_client_helpers.useTimeZone;
|
|
26
|
-
exports.useTranslations = require_client_useTranslations.useTranslations;
|
|
27
|
-
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":[],"sources":["../../../src/client/index.ts"],"sourcesContent":["export { useDictionary } from '../useDictionary';\nexport { useDictionaryDynamic } from '../useDictionaryDynamic';\nexport { useFormatter, useMessages, useNow, useTimeZone } from './helpers';\nexport { IntlProvider, type IntlProviderProps } from './IntlProvider';\nexport { useLocale } from './useLocale';\nexport { useTranslations } from './useTranslations';\n\n/**\n * @internal Private use-intl export, kept so aliased `_useExtracted` imports\n * resolve. Not part of the supported public surface.\n */\nexport const _useExtracted = (): Record<string, never> => ({});\n"],"mappings":";;;;;;;;;;;;;AAWA,MAAa,uBAA8C,EAAE"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
5
|
-
let react_intlayer = require("react-intlayer");
|
|
6
|
-
|
|
7
|
-
//#region src/client/useLocale.ts
|
|
8
|
-
/**
|
|
9
|
-
* Drop-in for use-intl's `useLocale`.
|
|
10
|
-
*
|
|
11
|
-
* Returns the active locale string from Intlayer's client context.
|
|
12
|
-
*/
|
|
13
|
-
const useLocale = () => {
|
|
14
|
-
const { locale } = (0, react_intlayer.useLocale)();
|
|
15
|
-
return locale;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
//#endregion
|
|
19
|
-
exports.useLocale = useLocale;
|
|
20
|
-
//# sourceMappingURL=useLocale.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useLocale.cjs","names":[],"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["'use client';\n\nimport { useLocale as useLocaleIntlayer } from 'react-intlayer';\nimport type { useLocale as _useLocale } from 'use-intl';\n\n/**\n * Drop-in for use-intl's `useLocale`.\n *\n * Returns the active locale string from Intlayer's client context.\n */\nexport const useLocale: typeof _useLocale = () => {\n const { locale } = useLocaleIntlayer();\n return locale as ReturnType<typeof _useLocale>;\n};\n"],"mappings":";;;;;;;;;;;;AAUA,MAAa,kBAAqC;CAChD,MAAM,EAAE,0CAA8B;AACtC,QAAO"}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
5
|
-
const require_shared_namespaceTranslator = require('../shared/namespaceTranslator.cjs');
|
|
6
|
-
let react_intlayer = require("react-intlayer");
|
|
7
|
-
let react = require("react");
|
|
8
|
-
|
|
9
|
-
//#region src/client/useTranslations.ts
|
|
10
|
-
/**
|
|
11
|
-
* Drop-in for use-intl's `useTranslations`.
|
|
12
|
-
*
|
|
13
|
-
* Messages support ICU MessageFormat syntax: simple arguments (`{name}`),
|
|
14
|
-
* plural (`{count, plural, one {…} other {…}}`, `#`), select, and formatted
|
|
15
|
-
* arguments (`{value, number}`). Rich text is available through `t.rich()`
|
|
16
|
-
* and `t.markup()`.
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* ```tsx
|
|
20
|
-
* const t = useTranslations('about');
|
|
21
|
-
* t('counter.label'); // ✓ typed
|
|
22
|
-
* t('items', { count: 3 }); // ICU plural
|
|
23
|
-
*
|
|
24
|
-
* // Scoped to a nested object (use-intl idiom)
|
|
25
|
-
* const t = useTranslations('about.counter');
|
|
26
|
-
* t('label'); // resolves about → counter.label
|
|
27
|
-
*
|
|
28
|
-
* // Rich text
|
|
29
|
-
* t.rich('terms', { link: (chunks) => <a href="/terms">{chunks}</a> });
|
|
30
|
-
* ```
|
|
31
|
-
*/
|
|
32
|
-
const useTranslations = ((namespace) => {
|
|
33
|
-
const { locale: currentLocale } = (0, react.useContext)(react_intlayer.IntlayerClientContext) ?? {};
|
|
34
|
-
return (0, react.useMemo)(() => require_shared_namespaceTranslator.createNamespaceTranslator(currentLocale, namespace), [currentLocale, namespace]);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
//#endregion
|
|
38
|
-
exports.useTranslations = useTranslations;
|
|
39
|
-
//# sourceMappingURL=useTranslations.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useTranslations.cjs","names":["IntlayerClientContext","createNamespaceTranslator"],"sources":["../../../src/client/useTranslations.ts"],"sourcesContent":["'use client';\n\nimport type {\n DictionaryKeys,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { useContext, useMemo } from 'react';\nimport { IntlayerClientContext } from 'react-intlayer';\nimport { createNamespaceTranslator } from '../shared/namespaceTranslator';\nimport type {\n LooseTranslateFunction,\n TranslateFunction,\n} from '../shared/translateFunctionTypes';\n\n/**\n * Overload set for {@link useTranslations}:\n *\n * 1. A bare dictionary key → fully-typed `t()` (autocompleted dot-paths).\n * 2. A nested namespace `'dictionary.sub.scope'` → `t()` accepts relative\n * `string` paths, matching use-intl's scoped-namespace behaviour.\n * 3. No namespace → root scope; the first segment of each key designates\n * the dictionary (`t('about.title')`).\n */\ntype UseTranslations = {\n <N extends DictionaryKeys>(namespace: N): TranslateFunction<N>;\n (namespace: `${string}.${string}`): LooseTranslateFunction;\n (): LooseTranslateFunction;\n};\n\n/**\n * Drop-in for use-intl's `useTranslations`.\n *\n * Messages support ICU MessageFormat syntax: simple arguments (`{name}`),\n * plural (`{count, plural, one {…} other {…}}`, `#`), select, and formatted\n * arguments (`{value, number}`). Rich text is available through `t.rich()`\n * and `t.markup()`.\n *\n * @example\n * ```tsx\n * const t = useTranslations('about');\n * t('counter.label'); // ✓ typed\n * t('items', { count: 3 }); // ICU plural\n *\n * // Scoped to a nested object (use-intl idiom)\n * const t = useTranslations('about.counter');\n * t('label'); // resolves about → counter.label\n *\n * // Rich text\n * t.rich('terms', { link: (chunks) => <a href=\"/terms\">{chunks}</a> });\n * ```\n */\nexport const useTranslations = ((namespace?: string) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext) ?? {};\n\n return useMemo(\n () => createNamespaceTranslator(currentLocale as LocalesValues, namespace),\n [currentLocale, namespace]\n );\n}) as UseTranslations;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmDA,MAAa,oBAAoB,cAAuB;CACtD,MAAM,EAAE,QAAQ,wCAA6BA,qCAAsB,IAAI,EAAE;AAEzE,iCACQC,6DAA0B,eAAgC,UAAU,EAC1E,CAAC,eAAe,UAAU,CAC3B"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_shared_intlFormatter = require('../shared/intlFormatter.cjs');
|
|
3
|
-
|
|
4
|
-
//#region src/core/createFormatter.ts
|
|
5
|
-
/**
|
|
6
|
-
* Drop-in for use-intl's `createFormatter`.
|
|
7
|
-
*
|
|
8
|
-
* Returns locale-aware formatters backed by the native `Intl.*` APIs:
|
|
9
|
-
* `dateTime`, `number`, `dateTimeRange`, `relativeTime`, `list`, and
|
|
10
|
-
* `displayName`. `now`, `timeZone`, `formats`, and `onError` are accepted for
|
|
11
|
-
* API compatibility but only `locale` influences the output.
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```ts
|
|
15
|
-
* const format = createFormatter({ locale: 'en' });
|
|
16
|
-
* format.number(1234.5, { style: 'currency', currency: 'USD' });
|
|
17
|
-
* ```
|
|
18
|
-
*/
|
|
19
|
-
const createFormatter = ({ locale }) => require_shared_intlFormatter.buildIntlFormatter(locale);
|
|
20
|
-
|
|
21
|
-
//#endregion
|
|
22
|
-
exports.createFormatter = createFormatter;
|
|
23
|
-
//# sourceMappingURL=createFormatter.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createFormatter.cjs","names":["buildIntlFormatter"],"sources":["../../../src/core/createFormatter.ts"],"sourcesContent":["import type { createFormatter as _createFormatter } from 'use-intl';\nimport { buildIntlFormatter } from '../shared/intlFormatter';\n\n/**\n * Drop-in for use-intl's `createFormatter`.\n *\n * Returns locale-aware formatters backed by the native `Intl.*` APIs:\n * `dateTime`, `number`, `dateTimeRange`, `relativeTime`, `list`, and\n * `displayName`. `now`, `timeZone`, `formats`, and `onError` are accepted for\n * API compatibility but only `locale` influences the output.\n *\n * @example\n * ```ts\n * const format = createFormatter({ locale: 'en' });\n * format.number(1234.5, { style: 'currency', currency: 'USD' });\n * ```\n */\nexport const createFormatter: typeof _createFormatter = ({ locale }) =>\n buildIntlFormatter(locale);\n"],"mappings":";;;;;;;;;;;;;;;;;;AAiBA,MAAa,mBAA4C,EAAE,aACzDA,gDAAmB,OAAO"}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
|
-
const require_shared_namespaceTranslator = require('../shared/namespaceTranslator.cjs');
|
|
4
|
-
let _intlayer_config_built = require("@intlayer/config/built");
|
|
5
|
-
let _intlayer_config_colors = require("@intlayer/config/colors");
|
|
6
|
-
let _intlayer_config_logger = require("@intlayer/config/logger");
|
|
7
|
-
|
|
8
|
-
//#region src/core/createTranslator.ts
|
|
9
|
-
/**
|
|
10
|
-
* Drop-in for use-intl's `createTranslator`.
|
|
11
|
-
*
|
|
12
|
-
* Returns a translate function (with `rich`, `markup`, `raw`, `has`) that
|
|
13
|
-
* resolves messages from Intlayer's compiled dictionaries for the given
|
|
14
|
-
* `locale`. Messages support ICU MessageFormat syntax.
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```ts
|
|
18
|
-
* const t = createTranslator({ locale: 'en', namespace: 'about' });
|
|
19
|
-
* t('counter.label'); // ✓ typed
|
|
20
|
-
* t('items', { count: 3 }); // ICU plural
|
|
21
|
-
* ```
|
|
22
|
-
*/
|
|
23
|
-
const createTranslator = (({ locale, namespace, messages: _messages }) => {
|
|
24
|
-
if (process.env.NODE_ENV === "development" && _messages !== void 0) (0, _intlayer_config_logger.getAppLogger)({ log: _intlayer_config_built.log })(`${(0, _intlayer_config_logger.colorize)("createTranslator", _intlayer_config_colors.CYAN)} do not pass the messages option with intlayer. Messages are loaded automatically under the hood for bundle optimization reason`);
|
|
25
|
-
return require_shared_namespaceTranslator.createNamespaceTranslator(locale, namespace);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
//#endregion
|
|
29
|
-
exports.createTranslator = createTranslator;
|
|
30
|
-
//# sourceMappingURL=createTranslator.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createTranslator.cjs","names":["CYAN","createNamespaceTranslator"],"sources":["../../../src/core/createTranslator.ts"],"sourcesContent":["import { log } from '@intlayer/config/built';\nimport { CYAN } from '@intlayer/config/colors';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport type {\n DictionaryKeys,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { createNamespaceTranslator } from '../shared/namespaceTranslator';\nimport type {\n LooseTranslateFunction,\n TranslateFunction,\n} from '../shared/translateFunctionTypes';\n\n/**\n * Configuration accepted by {@link createTranslator}.\n *\n * Mirrors use-intl's `IntlConfig`, but `messages`, `formats`, `now`,\n * `timeZone`, `onError`, and `getMessageFallback` have no effect — Intlayer\n * resolves content from its own compiled dictionaries.\n */\nexport type CreateTranslatorConfig<N extends DictionaryKeys> = {\n /** The locale dictionaries are resolved for. */\n locale: LocalesValues;\n /** A bare dictionary key, or a nested `'dictionary.scope'` namespace. */\n namespace?: N | (string & {});\n /**\n * @deprecated has no use case with intlayer. Messages are loaded\n * automatically under the hood for bundle optimization reason.\n */\n messages?: never;\n} & Record<string, unknown>;\n\n/**\n * Overload set for {@link createTranslator}:\n *\n * 1. A bare dictionary key → fully-typed `t()` (autocompleted dot-paths).\n * 2. A nested namespace `'dictionary.sub.scope'` → `t()` accepts relative\n * `string` paths, matching use-intl's scoped-namespace behaviour.\n * 3. No namespace → root scope; the first segment of each key designates\n * the dictionary (`t('about.title')`).\n */\ntype CreateTranslator = {\n <N extends DictionaryKeys>(\n config: CreateTranslatorConfig<N> & { namespace: N }\n ): TranslateFunction<N>;\n (\n config: CreateTranslatorConfig<DictionaryKeys> & {\n namespace: `${string}.${string}`;\n }\n ): LooseTranslateFunction;\n (config: CreateTranslatorConfig<DictionaryKeys>): LooseTranslateFunction;\n};\n\n/**\n * Drop-in for use-intl's `createTranslator`.\n *\n * Returns a translate function (with `rich`, `markup`, `raw`, `has`) that\n * resolves messages from Intlayer's compiled dictionaries for the given\n * `locale`. Messages support ICU MessageFormat syntax.\n *\n * @example\n * ```ts\n * const t = createTranslator({ locale: 'en', namespace: 'about' });\n * t('counter.label'); // ✓ typed\n * t('items', { count: 3 }); // ICU plural\n * ```\n */\nexport const createTranslator = (({\n locale,\n namespace,\n messages: _messages,\n}: CreateTranslatorConfig<DictionaryKeys>) => {\n if (process.env.NODE_ENV === 'development' && _messages !== undefined) {\n const appLogger = getAppLogger({ log });\n appLogger(\n `${colorize('createTranslator', CYAN)} do not pass the messages option with intlayer. Messages are loaded automatically under the hood for bundle optimization reason`\n );\n }\n\n return createNamespaceTranslator(locale, namespace);\n}) as CreateTranslator;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAmEA,MAAa,qBAAqB,EAChC,QACA,WACA,UAAU,gBACkC;AAC5C,KAAI,QAAQ,IAAI,aAAa,iBAAiB,cAAc,OAE1D,2CAD+B,EAAE,iCAAK,CAC7B,CACP,yCAAY,oBAAoBA,6BAAK,CAAC,iIACvC;AAGH,QAAOC,6DAA0B,QAAQ,UAAU"}
|
package/dist/cjs/core/errors.cjs
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
|
|
3
|
-
//#region src/core/errors.ts
|
|
4
|
-
/**
|
|
5
|
-
* Drop-in for use-intl's `IntlErrorCode` enum.
|
|
6
|
-
*
|
|
7
|
-
* Re-implemented locally (rather than re-exported) because `use-intl` is
|
|
8
|
-
* aliased to this package at build time, so importing its runtime value would
|
|
9
|
-
* be circular.
|
|
10
|
-
*/
|
|
11
|
-
let IntlErrorCode = /* @__PURE__ */ function(IntlErrorCode) {
|
|
12
|
-
IntlErrorCode["MISSING_MESSAGE"] = "MISSING_MESSAGE";
|
|
13
|
-
IntlErrorCode["MISSING_FORMAT"] = "MISSING_FORMAT";
|
|
14
|
-
IntlErrorCode["ENVIRONMENT_FALLBACK"] = "ENVIRONMENT_FALLBACK";
|
|
15
|
-
IntlErrorCode["INSUFFICIENT_PATH"] = "INSUFFICIENT_PATH";
|
|
16
|
-
IntlErrorCode["INVALID_MESSAGE"] = "INVALID_MESSAGE";
|
|
17
|
-
IntlErrorCode["INVALID_KEY"] = "INVALID_KEY";
|
|
18
|
-
IntlErrorCode["FORMATTING_ERROR"] = "FORMATTING_ERROR";
|
|
19
|
-
return IntlErrorCode;
|
|
20
|
-
}({});
|
|
21
|
-
/**
|
|
22
|
-
* Drop-in for use-intl's `IntlError`.
|
|
23
|
-
*
|
|
24
|
-
* Carries the {@link IntlErrorCode} and the original message, matching
|
|
25
|
-
* use-intl's error shape so consumer `onError` handlers keep working.
|
|
26
|
-
*/
|
|
27
|
-
var IntlError = class extends Error {
|
|
28
|
-
code;
|
|
29
|
-
originalMessage;
|
|
30
|
-
constructor(code, originalMessage) {
|
|
31
|
-
let message = code;
|
|
32
|
-
if (originalMessage) message += `: ${originalMessage}`;
|
|
33
|
-
super(message);
|
|
34
|
-
this.code = code;
|
|
35
|
-
if (originalMessage) this.originalMessage = originalMessage;
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
//#endregion
|
|
40
|
-
exports.IntlError = IntlError;
|
|
41
|
-
exports.IntlErrorCode = IntlErrorCode;
|
|
42
|
-
//# sourceMappingURL=errors.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"errors.cjs","names":[],"sources":["../../../src/core/errors.ts"],"sourcesContent":["/**\n * Drop-in for use-intl's `IntlErrorCode` enum.\n *\n * Re-implemented locally (rather than re-exported) because `use-intl` is\n * aliased to this package at build time, so importing its runtime value would\n * be circular.\n */\nexport enum IntlErrorCode {\n MISSING_MESSAGE = 'MISSING_MESSAGE',\n MISSING_FORMAT = 'MISSING_FORMAT',\n ENVIRONMENT_FALLBACK = 'ENVIRONMENT_FALLBACK',\n INSUFFICIENT_PATH = 'INSUFFICIENT_PATH',\n INVALID_MESSAGE = 'INVALID_MESSAGE',\n INVALID_KEY = 'INVALID_KEY',\n FORMATTING_ERROR = 'FORMATTING_ERROR',\n}\n\n/**\n * Drop-in for use-intl's `IntlError`.\n *\n * Carries the {@link IntlErrorCode} and the original message, matching\n * use-intl's error shape so consumer `onError` handlers keep working.\n */\nexport class IntlError extends Error {\n public readonly code: IntlErrorCode;\n public readonly originalMessage: string | undefined;\n\n constructor(code: IntlErrorCode, originalMessage?: string) {\n let message: string = code;\n if (originalMessage) {\n message += `: ${originalMessage}`;\n }\n super(message);\n\n this.code = code;\n if (originalMessage) {\n this.originalMessage = originalMessage;\n }\n }\n}\n"],"mappings":";;;;;;;;;;AAOA,IAAY,gBAAL;AACL;AACA;AACA;AACA;AACA;AACA;AACA;;KACD;;;;;;;AAQD,IAAa,YAAb,cAA+B,MAAM;CACnC,AAAgB;CAChB,AAAgB;CAEhB,YAAY,MAAqB,iBAA0B;EACzD,IAAI,UAAkB;AACtB,MAAI,gBACF,YAAW,KAAK;AAElB,QAAM,QAAQ;AAEd,OAAK,OAAO;AACZ,MAAI,gBACF,MAAK,kBAAkB"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
|
-
let _intlayer_config_built = require("@intlayer/config/built");
|
|
4
|
-
|
|
5
|
-
//#region src/core/hasLocale.ts
|
|
6
|
-
/**
|
|
7
|
-
* Drop-in for use-intl's `hasLocale`.
|
|
8
|
-
*
|
|
9
|
-
* Narrows a locale candidate to the given locales list. When the list is
|
|
10
|
-
* omitted, the locales configured in intlayer are used.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```ts
|
|
14
|
-
* if (hasLocale(['en', 'fr'], requested)) { … }
|
|
15
|
-
* ```
|
|
16
|
-
*/
|
|
17
|
-
const hasLocale = ((locales, candidate) => {
|
|
18
|
-
return (locales ?? _intlayer_config_built.internationalization?.locales?.map(String) ?? []).includes(candidate);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
//#endregion
|
|
22
|
-
exports.hasLocale = hasLocale;
|
|
23
|
-
//# sourceMappingURL=hasLocale.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hasLocale.cjs","names":["internationalization"],"sources":["../../../src/core/hasLocale.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport type { hasLocale as _hasLocale } from 'use-intl';\n\n/**\n * Drop-in for use-intl's `hasLocale`.\n *\n * Narrows a locale candidate to the given locales list. When the list is\n * omitted, the locales configured in intlayer are used.\n *\n * @example\n * ```ts\n * if (hasLocale(['en', 'fr'], requested)) { … }\n * ```\n */\nexport const hasLocale: typeof _hasLocale = ((\n locales: readonly string[],\n candidate: unknown\n): boolean => {\n const availableLocales =\n locales ?? internationalization?.locales?.map(String) ?? [];\n return availableLocales.includes(candidate as string);\n}) as typeof _hasLocale;\n"],"mappings":";;;;;;;;;;;;;;;;AAcA,MAAa,cACX,SACA,cACY;AAGZ,SADE,WAAWA,6CAAsB,SAAS,IAAI,OAAO,IAAI,EAAE,EACrC,SAAS,UAAoB"}
|
package/dist/cjs/core/index.cjs
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_core_createFormatter = require('./createFormatter.cjs');
|
|
3
|
-
const require_core_createTranslator = require('./createTranslator.cjs');
|
|
4
|
-
const require_core_errors = require('./errors.cjs');
|
|
5
|
-
const require_core_hasLocale = require('./hasLocale.cjs');
|
|
6
|
-
const require_core_initializeConfig = require('./initializeConfig.cjs');
|
|
7
|
-
|
|
8
|
-
exports.IntlError = require_core_errors.IntlError;
|
|
9
|
-
exports.IntlErrorCode = require_core_errors.IntlErrorCode;
|
|
10
|
-
exports.createFormatter = require_core_createFormatter.createFormatter;
|
|
11
|
-
exports.createTranslator = require_core_createTranslator.createTranslator;
|
|
12
|
-
exports.hasLocale = require_core_hasLocale.hasLocale;
|
|
13
|
-
exports.initializeConfig = require_core_initializeConfig.initializeConfig;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
|
|
3
|
-
//#region src/core/initializeConfig.ts
|
|
4
|
-
/**
|
|
5
|
-
* Drop-in for use-intl's `initializeConfig`.
|
|
6
|
-
*
|
|
7
|
-
* Enhances an incoming config with defaults. With intlayer, `messages` and
|
|
8
|
-
* `formats` are not consumed at runtime (content comes from compiled
|
|
9
|
-
* dictionaries) but the shape is preserved so callers keep type-checking.
|
|
10
|
-
*/
|
|
11
|
-
const initializeConfig = ({ formats, getMessageFallback, messages, onError, ...rest }) => {
|
|
12
|
-
const finalOnError = onError ?? ((error) => error);
|
|
13
|
-
const finalGetMessageFallback = getMessageFallback ?? (({ key, namespace }) => [namespace, key].filter(Boolean).join("."));
|
|
14
|
-
return {
|
|
15
|
-
...rest,
|
|
16
|
-
formats: formats || void 0,
|
|
17
|
-
messages: messages || void 0,
|
|
18
|
-
onError: finalOnError,
|
|
19
|
-
getMessageFallback: finalGetMessageFallback
|
|
20
|
-
};
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
//#endregion
|
|
24
|
-
exports.initializeConfig = initializeConfig;
|
|
25
|
-
//# sourceMappingURL=initializeConfig.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"initializeConfig.cjs","names":[],"sources":["../../../src/core/initializeConfig.ts"],"sourcesContent":["import type { initializeConfig as _initializeConfig } from 'use-intl';\n\n/**\n * Drop-in for use-intl's `initializeConfig`.\n *\n * Enhances an incoming config with defaults. With intlayer, `messages` and\n * `formats` are not consumed at runtime (content comes from compiled\n * dictionaries) but the shape is preserved so callers keep type-checking.\n */\nexport const initializeConfig: typeof _initializeConfig = ({\n formats,\n getMessageFallback,\n messages,\n onError,\n ...rest\n}) => {\n const finalOnError = onError ?? ((error) => error);\n const finalGetMessageFallback =\n getMessageFallback ??\n (({ key, namespace }) => [namespace, key].filter(Boolean).join('.'));\n\n return {\n ...rest,\n formats: formats || undefined,\n messages: messages || undefined,\n onError: finalOnError,\n getMessageFallback: finalGetMessageFallback,\n };\n};\n"],"mappings":";;;;;;;;;;AASA,MAAa,oBAA8C,EACzD,SACA,oBACA,UACA,SACA,GAAG,WACC;CACJ,MAAM,eAAe,aAAa,UAAU;CAC5C,MAAM,0BACJ,wBACE,EAAE,KAAK,gBAAgB,CAAC,WAAW,IAAI,CAAC,OAAO,QAAQ,CAAC,KAAK,IAAI;AAErE,QAAO;EACL,GAAG;EACH,SAAS,WAAW;EACpB,UAAU,YAAY;EACtB,SAAS;EACT,oBAAoB;EACrB"}
|
package/dist/cjs/core/types.cjs
DELETED
|
File without changes
|
package/dist/cjs/index.cjs
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_useDictionaryDynamic = require('./useDictionaryDynamic.cjs');
|
|
3
|
-
const require_useDictionary = require('./useDictionary.cjs');
|
|
4
|
-
const require_client_helpers = require('./client/helpers.cjs');
|
|
5
|
-
const require_client_IntlProvider = require('./client/IntlProvider.cjs');
|
|
6
|
-
const require_client_useLocale = require('./client/useLocale.cjs');
|
|
7
|
-
const require_client_useTranslations = require('./client/useTranslations.cjs');
|
|
8
|
-
const require_client_index = require('./client/index.cjs');
|
|
9
|
-
const require_core_createFormatter = require('./core/createFormatter.cjs');
|
|
10
|
-
const require_core_createTranslator = require('./core/createTranslator.cjs');
|
|
11
|
-
const require_core_errors = require('./core/errors.cjs');
|
|
12
|
-
const require_core_hasLocale = require('./core/hasLocale.cjs');
|
|
13
|
-
const require_core_initializeConfig = require('./core/initializeConfig.cjs');
|
|
14
|
-
|
|
15
|
-
exports.IntlError = require_core_errors.IntlError;
|
|
16
|
-
exports.IntlErrorCode = require_core_errors.IntlErrorCode;
|
|
17
|
-
exports.IntlProvider = require_client_IntlProvider.IntlProvider;
|
|
18
|
-
exports._useExtracted = require_client_index._useExtracted;
|
|
19
|
-
exports.createFormatter = require_core_createFormatter.createFormatter;
|
|
20
|
-
exports.createTranslator = require_core_createTranslator.createTranslator;
|
|
21
|
-
exports.hasLocale = require_core_hasLocale.hasLocale;
|
|
22
|
-
exports.initializeConfig = require_core_initializeConfig.initializeConfig;
|
|
23
|
-
exports.useDictionary = require_useDictionary.useDictionary;
|
|
24
|
-
exports.useDictionaryDynamic = require_useDictionaryDynamic.useDictionaryDynamic;
|
|
25
|
-
exports.useFormatter = require_client_helpers.useFormatter;
|
|
26
|
-
exports.useLocale = require_client_useLocale.useLocale;
|
|
27
|
-
exports.useMessages = require_client_helpers.useMessages;
|
|
28
|
-
exports.useNow = require_client_helpers.useNow;
|
|
29
|
-
exports.useTimeZone = require_client_helpers.useTimeZone;
|
|
30
|
-
exports.useTranslations = require_client_useTranslations.useTranslations;
|
|
@@ -1,80 +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 use-intl's translation entry points.
|
|
14
|
-
*
|
|
15
|
-
* Tells the intlayer field-usage analyser how to extract the dictionary key
|
|
16
|
-
* (namespace) and consumed fields from `useTranslations` / `createTranslator`
|
|
17
|
-
* call sites, enabling accurate dictionary pruning for projects using
|
|
18
|
-
* `@intlayer/use-intl`.
|
|
19
|
-
*/
|
|
20
|
-
const USE_INTL_COMPAT_CALLERS = [{
|
|
21
|
-
callerName: "useTranslations",
|
|
22
|
-
importSources: [
|
|
23
|
-
"use-intl",
|
|
24
|
-
"use-intl/react",
|
|
25
|
-
"@intlayer/use-intl"
|
|
26
|
-
],
|
|
27
|
-
namespace: {
|
|
28
|
-
from: "argument",
|
|
29
|
-
index: 0
|
|
30
|
-
},
|
|
31
|
-
translationFunction: "return-value"
|
|
32
|
-
}, {
|
|
33
|
-
callerName: "createTranslator",
|
|
34
|
-
importSources: [
|
|
35
|
-
"use-intl",
|
|
36
|
-
"use-intl/core",
|
|
37
|
-
"@intlayer/use-intl"
|
|
38
|
-
],
|
|
39
|
-
namespace: {
|
|
40
|
-
from: "option",
|
|
41
|
-
argumentIndex: 0,
|
|
42
|
-
property: "namespace"
|
|
43
|
-
},
|
|
44
|
-
translationFunction: "return-value"
|
|
45
|
-
}];
|
|
46
|
-
/**
|
|
47
|
-
* A Vite plugin for use-intl compat that wraps vite-intlayer and configures
|
|
48
|
-
* resolve aliases so `use-intl` imports are served by `@intlayer/use-intl`.
|
|
49
|
-
*
|
|
50
|
-
* @example
|
|
51
|
-
* ```ts
|
|
52
|
-
* // vite.config.ts
|
|
53
|
-
* import useIntlVitePlugin from '@intlayer/use-intl/plugin';
|
|
54
|
-
*
|
|
55
|
-
* export default defineConfig({
|
|
56
|
-
* plugins: [useIntlVitePlugin()],
|
|
57
|
-
* });
|
|
58
|
-
* ```
|
|
59
|
-
*/
|
|
60
|
-
const useIntlVitePlugin = (options) => {
|
|
61
|
-
const intlayerConfig = (0, _intlayer_config_node.getConfiguration)();
|
|
62
|
-
const appLogger = (0, _intlayer_config_logger.getAppLogger)(intlayerConfig);
|
|
63
|
-
(0, _intlayer_chokidar_utils.runOnce)((0, node_path.join)(intlayerConfig.system.baseDir, ".intlayer", "cache", "intlayer-issues-invitation.lock"), () => {
|
|
64
|
-
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)]);
|
|
65
|
-
}, { cacheTimeoutMs: 1e3 * 60 * 60 });
|
|
66
|
-
const basePlugins = (0, vite_intlayer.intlayer)({
|
|
67
|
-
...options,
|
|
68
|
-
compatCallers: [...options?.compatCallers ?? [], ...USE_INTL_COMPAT_CALLERS]
|
|
69
|
-
});
|
|
70
|
-
const compatPlugin = {
|
|
71
|
-
name: "vite-use-intl-compat-plugin",
|
|
72
|
-
config: () => ({ resolve: { alias: { "use-intl": "@intlayer/use-intl" } } })
|
|
73
|
-
};
|
|
74
|
-
return [...Array.isArray(basePlugins) ? basePlugins : [basePlugins], compatPlugin];
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
//#endregion
|
|
78
|
-
exports.default = useIntlVitePlugin;
|
|
79
|
-
exports.useIntlVitePlugin = useIntlVitePlugin;
|
|
80
|
-
//# 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 use-intl's translation entry points.\n *\n * Tells the intlayer field-usage analyser how to extract the dictionary key\n * (namespace) and consumed fields from `useTranslations` / `createTranslator`\n * call sites, enabling accurate dictionary pruning for projects using\n * `@intlayer/use-intl`.\n */\nconst USE_INTL_COMPAT_CALLERS: CompatCallerConfig[] = [\n {\n callerName: 'useTranslations',\n importSources: ['use-intl', 'use-intl/react', '@intlayer/use-intl'],\n namespace: { from: 'argument', index: 0 },\n translationFunction: 'return-value',\n },\n {\n callerName: 'createTranslator',\n importSources: ['use-intl', 'use-intl/core', '@intlayer/use-intl'],\n namespace: { from: 'option', argumentIndex: 0, property: 'namespace' },\n translationFunction: 'return-value',\n },\n];\n\n/**\n * A Vite plugin for use-intl compat that wraps vite-intlayer and configures\n * resolve aliases so `use-intl` imports are served by `@intlayer/use-intl`.\n *\n * @example\n * ```ts\n * // vite.config.ts\n * import useIntlVitePlugin from '@intlayer/use-intl/plugin';\n *\n * export default defineConfig({\n * plugins: [useIntlVitePlugin()],\n * });\n * ```\n */\nexport const useIntlVitePlugin = (\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 ...USE_INTL_COMPAT_CALLERS,\n ],\n });\n\n const compatPlugin: PluginOption = {\n name: 'vite-use-intl-compat-plugin',\n config: () => ({\n resolve: {\n alias: {\n 'use-intl': '@intlayer/use-intl',\n },\n },\n }),\n };\n\n return [\n ...(Array.isArray(basePlugins) ? basePlugins : [basePlugins]),\n compatPlugin,\n ];\n};\n\nexport default useIntlVitePlugin;\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAgBA,MAAM,0BAAgD,CACpD;CACE,YAAY;CACZ,eAAe;EAAC;EAAY;EAAkB;EAAqB;CACnE,WAAW;EAAE,MAAM;EAAY,OAAO;EAAG;CACzC,qBAAqB;CACtB,EACD;CACE,YAAY;CACZ,eAAe;EAAC;EAAY;EAAiB;EAAqB;CAClE,WAAW;EAAE,MAAM;EAAU,eAAe;EAAG,UAAU;EAAa;CACtE,qBAAqB;CACtB,CACF;;;;;;;;;;;;;;;AAgBD,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,eAAe,EACb,SAAS,EACP,OAAO,EACL,YAAY,sBACb,EACF,EACF;EACF;AAED,QAAO,CACL,GAAI,MAAM,QAAQ,YAAY,GAAG,cAAc,CAAC,YAAY,EAC5D,aACD"}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
|
|
3
|
-
//#region src/shared/intlFormatter.ts
|
|
4
|
-
/** Time units orderable by their duration in seconds. */
|
|
5
|
-
const RELATIVE_TIME_UNITS = [
|
|
6
|
-
["year", 31536e3],
|
|
7
|
-
["month", 2628e3],
|
|
8
|
-
["week", 604800],
|
|
9
|
-
["day", 86400],
|
|
10
|
-
["hour", 3600],
|
|
11
|
-
["minute", 60],
|
|
12
|
-
["second", 1]
|
|
13
|
-
];
|
|
14
|
-
const toDate = (value) => value instanceof Date ? value : new Date(value);
|
|
15
|
-
/**
|
|
16
|
-
* Builds a use-intl compatible formatter backed by the native `Intl.*` APIs
|
|
17
|
-
* for the given locale.
|
|
18
|
-
*
|
|
19
|
-
* Shared by `useFormatter` (React hook) and `createFormatter` (non-React core).
|
|
20
|
-
*
|
|
21
|
-
* @param locale - The locale used by every `Intl.*` formatter instance.
|
|
22
|
-
* @returns A formatter exposing `dateTime`, `number`, `dateTimeRange`,
|
|
23
|
-
* `relativeTime`, `list`, and `displayName`.
|
|
24
|
-
*/
|
|
25
|
-
const buildIntlFormatter = (locale) => ({
|
|
26
|
-
dateTime: (value, options) => new Intl.DateTimeFormat(locale, options).format(value),
|
|
27
|
-
number: (value, options) => new Intl.NumberFormat(locale, options).format(value),
|
|
28
|
-
/** Formats a date range with `Intl.DateTimeFormat#formatRange`. */
|
|
29
|
-
dateTimeRange: (start, end, options) => new Intl.DateTimeFormat(locale, options).formatRange(toDate(start), toDate(end)),
|
|
30
|
-
/**
|
|
31
|
-
* Formats a date relative to now (or a reference date), automatically
|
|
32
|
-
* selecting the largest fitting unit.
|
|
33
|
-
*/
|
|
34
|
-
relativeTime: (date, nowOrOptions) => {
|
|
35
|
-
const options = nowOrOptions instanceof Date || typeof nowOrOptions === "number" ? { now: nowOrOptions } : nowOrOptions ?? {};
|
|
36
|
-
const nowDate = options.now !== void 0 ? toDate(options.now) : /* @__PURE__ */ new Date();
|
|
37
|
-
const diffInSeconds = (toDate(date).getTime() - nowDate.getTime()) / 1e3;
|
|
38
|
-
let unit = options.unit;
|
|
39
|
-
if (!unit) {
|
|
40
|
-
const absoluteDiff = Math.abs(diffInSeconds);
|
|
41
|
-
unit = RELATIVE_TIME_UNITS.find(([, unitSeconds]) => absoluteDiff >= unitSeconds)?.[0] ?? "second";
|
|
42
|
-
}
|
|
43
|
-
const unitSeconds = RELATIVE_TIME_UNITS.find(([unitName]) => unitName === unit)?.[1] ?? 1;
|
|
44
|
-
return new Intl.RelativeTimeFormat(locale, {
|
|
45
|
-
numeric: "auto",
|
|
46
|
-
style: options.style
|
|
47
|
-
}).format(Math.round(diffInSeconds / unitSeconds), unit);
|
|
48
|
-
},
|
|
49
|
-
/** Formats a list with `Intl.ListFormat`. */
|
|
50
|
-
list: (value, options) => new Intl.ListFormat(locale, options).format(value),
|
|
51
|
-
displayName: (value, optionsOrFormat, extraOptions) => {
|
|
52
|
-
const resolvedOptions = typeof optionsOrFormat === "string" ? extraOptions : optionsOrFormat;
|
|
53
|
-
try {
|
|
54
|
-
return new Intl.DisplayNames([locale], resolvedOptions ?? { type: "language" }).of(value) ?? value;
|
|
55
|
-
} catch {
|
|
56
|
-
return value;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
//#endregion
|
|
62
|
-
exports.buildIntlFormatter = buildIntlFormatter;
|
|
63
|
-
//# sourceMappingURL=intlFormatter.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"intlFormatter.cjs","names":[],"sources":["../../../src/shared/intlFormatter.ts"],"sourcesContent":["import type { createFormatter as _createFormatter } from 'use-intl';\n\n/** The formatter object shape exposed by use-intl. */\nexport type Formatter = ReturnType<typeof _createFormatter>;\n\n/** Time units orderable by their duration in seconds. */\nconst RELATIVE_TIME_UNITS: [Intl.RelativeTimeFormatUnit, number][] = [\n ['year', 31536000],\n ['month', 2628000],\n ['week', 604800],\n ['day', 86400],\n ['hour', 3600],\n ['minute', 60],\n ['second', 1],\n];\n\nconst toDate = (value: Date | number | string): Date =>\n value instanceof Date ? value : new Date(value);\n\n/**\n * Builds a use-intl compatible formatter backed by the native `Intl.*` APIs\n * for the given locale.\n *\n * Shared by `useFormatter` (React hook) and `createFormatter` (non-React core).\n *\n * @param locale - The locale used by every `Intl.*` formatter instance.\n * @returns A formatter exposing `dateTime`, `number`, `dateTimeRange`,\n * `relativeTime`, `list`, and `displayName`.\n */\nexport const buildIntlFormatter = (locale: string): Formatter =>\n ({\n dateTime: (value: Date | number, options?: Intl.DateTimeFormatOptions) =>\n new Intl.DateTimeFormat(locale, options).format(value),\n\n number: (value: number | bigint, options?: Intl.NumberFormatOptions) =>\n new Intl.NumberFormat(locale, options).format(value),\n\n /** Formats a date range with `Intl.DateTimeFormat#formatRange`. */\n dateTimeRange: (\n start: Date | number,\n end: Date | number,\n options?: Intl.DateTimeFormatOptions\n ) =>\n new Intl.DateTimeFormat(locale, options).formatRange(\n toDate(start),\n toDate(end)\n ),\n\n /**\n * Formats a date relative to now (or a reference date), automatically\n * selecting the largest fitting unit.\n */\n relativeTime: (\n date: Date | number | string,\n nowOrOptions?:\n | Date\n | number\n | {\n now?: Date | number;\n unit?: Intl.RelativeTimeFormatUnit;\n style?: Intl.RelativeTimeFormatStyle;\n numberingSystem?: string;\n }\n ) => {\n const options =\n nowOrOptions instanceof Date || typeof nowOrOptions === 'number'\n ? { now: nowOrOptions }\n : (nowOrOptions ?? {});\n\n const nowDate =\n options.now !== undefined ? toDate(options.now) : new Date();\n const diffInSeconds = (toDate(date).getTime() - nowDate.getTime()) / 1000;\n\n let unit = options.unit;\n if (!unit) {\n const absoluteDiff = Math.abs(diffInSeconds);\n unit =\n RELATIVE_TIME_UNITS.find(\n ([, unitSeconds]) => absoluteDiff >= unitSeconds\n )?.[0] ?? 'second';\n }\n\n const unitSeconds =\n RELATIVE_TIME_UNITS.find(([unitName]) => unitName === unit)?.[1] ?? 1;\n\n return new Intl.RelativeTimeFormat(locale, {\n numeric: 'auto',\n style: options.style,\n }).format(Math.round(diffInSeconds / unitSeconds), unit);\n },\n\n /** Formats a list with `Intl.ListFormat`. */\n list: (value: Iterable<string>, options?: Intl.ListFormatOptions): string =>\n new Intl.ListFormat(locale, options).format(value),\n\n displayName: (\n value: string,\n optionsOrFormat?: Intl.DisplayNamesOptions | string,\n extraOptions?: Intl.DisplayNamesOptions\n ): string => {\n const resolvedOptions =\n typeof optionsOrFormat === 'string' ? extraOptions : optionsOrFormat;\n try {\n return (\n new Intl.DisplayNames(\n [locale],\n resolvedOptions ?? { type: 'language' }\n ).of(value) ?? value\n );\n } catch {\n return value;\n }\n },\n }) as unknown as Formatter;\n"],"mappings":";;;;AAMA,MAAM,sBAA+D;CACnE,CAAC,QAAQ,QAAS;CAClB,CAAC,SAAS,OAAQ;CAClB,CAAC,QAAQ,OAAO;CAChB,CAAC,OAAO,MAAM;CACd,CAAC,QAAQ,KAAK;CACd,CAAC,UAAU,GAAG;CACd,CAAC,UAAU,EAAE;CACd;AAED,MAAM,UAAU,UACd,iBAAiB,OAAO,QAAQ,IAAI,KAAK,MAAM;;;;;;;;;;;AAYjD,MAAa,sBAAsB,YAChC;CACC,WAAW,OAAsB,YAC/B,IAAI,KAAK,eAAe,QAAQ,QAAQ,CAAC,OAAO,MAAM;CAExD,SAAS,OAAwB,YAC/B,IAAI,KAAK,aAAa,QAAQ,QAAQ,CAAC,OAAO,MAAM;;CAGtD,gBACE,OACA,KACA,YAEA,IAAI,KAAK,eAAe,QAAQ,QAAQ,CAAC,YACvC,OAAO,MAAM,EACb,OAAO,IAAI,CACZ;;;;;CAMH,eACE,MACA,iBASG;EACH,MAAM,UACJ,wBAAwB,QAAQ,OAAO,iBAAiB,WACpD,EAAE,KAAK,cAAc,GACpB,gBAAgB,EAAE;EAEzB,MAAM,UACJ,QAAQ,QAAQ,SAAY,OAAO,QAAQ,IAAI,mBAAG,IAAI,MAAM;EAC9D,MAAM,iBAAiB,OAAO,KAAK,CAAC,SAAS,GAAG,QAAQ,SAAS,IAAI;EAErE,IAAI,OAAO,QAAQ;AACnB,MAAI,CAAC,MAAM;GACT,MAAM,eAAe,KAAK,IAAI,cAAc;AAC5C,UACE,oBAAoB,MACjB,GAAG,iBAAiB,gBAAgB,YACtC,GAAG,MAAM;;EAGd,MAAM,cACJ,oBAAoB,MAAM,CAAC,cAAc,aAAa,KAAK,GAAG,MAAM;AAEtE,SAAO,IAAI,KAAK,mBAAmB,QAAQ;GACzC,SAAS;GACT,OAAO,QAAQ;GAChB,CAAC,CAAC,OAAO,KAAK,MAAM,gBAAgB,YAAY,EAAE,KAAK;;;CAI1D,OAAO,OAAyB,YAC9B,IAAI,KAAK,WAAW,QAAQ,QAAQ,CAAC,OAAO,MAAM;CAEpD,cACE,OACA,iBACA,iBACW;EACX,MAAM,kBACJ,OAAO,oBAAoB,WAAW,eAAe;AACvD,MAAI;AACF,UACE,IAAI,KAAK,aACP,CAAC,OAAO,EACR,mBAAmB,EAAE,MAAM,YAAY,CACxC,CAAC,GAAG,MAAM,IAAI;UAEX;AACN,UAAO;;;CAGZ"}
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
|
-
let _intlayer_core_interpreter = require("@intlayer/core/interpreter");
|
|
4
|
-
let _intlayer_core_messageFormat = require("@intlayer/core/messageFormat");
|
|
5
|
-
let react = require("react");
|
|
6
|
-
let react_jsx_runtime = require("react/jsx-runtime");
|
|
7
|
-
|
|
8
|
-
//#region src/shared/namespaceTranslator.tsx
|
|
9
|
-
/**
|
|
10
|
-
* Reads a dotted `path` (e.g. `counter.label`) out of a nested object value.
|
|
11
|
-
*
|
|
12
|
-
* @param objectValue - The object to read from.
|
|
13
|
-
* @param path - Dot-separated path. An empty path returns `objectValue`.
|
|
14
|
-
* @returns The value found at `path`, or `undefined` when any segment is absent.
|
|
15
|
-
*/
|
|
16
|
-
const navigatePath = (objectValue, path) => {
|
|
17
|
-
if (!path) return objectValue;
|
|
18
|
-
const parts = path.split(".");
|
|
19
|
-
let current = objectValue;
|
|
20
|
-
for (const part of parts) {
|
|
21
|
-
if (current === null || current === void 0 || typeof current !== "object") return;
|
|
22
|
-
current = current[part];
|
|
23
|
-
}
|
|
24
|
-
return current;
|
|
25
|
-
};
|
|
26
|
-
/** Splits rich values into scalar interpolation values and tag renderers. */
|
|
27
|
-
const splitRichValues = (values = {}) => {
|
|
28
|
-
const scalarValues = {};
|
|
29
|
-
const renderers = {};
|
|
30
|
-
for (const [valueKey, value] of Object.entries(values)) if (typeof value === "function") renderers[valueKey] = value;
|
|
31
|
-
else scalarValues[valueKey] = value;
|
|
32
|
-
return {
|
|
33
|
-
scalarValues,
|
|
34
|
-
renderers
|
|
35
|
-
};
|
|
36
|
-
};
|
|
37
|
-
const renderRichTokens = (tokens, renderers) => tokens.map((token, tokenIndex) => {
|
|
38
|
-
if (typeof token === "string") return token;
|
|
39
|
-
const children = renderRichTokens(token.children, renderers);
|
|
40
|
-
const renderer = renderers[token.tag];
|
|
41
|
-
if (typeof renderer === "function") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.Fragment, { children: renderer(children) }, tokenIndex);
|
|
42
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.Fragment, { children }, tokenIndex);
|
|
43
|
-
});
|
|
44
|
-
const renderMarkupTokens = (tokens, renderers) => tokens.map((token) => {
|
|
45
|
-
if (typeof token === "string") return token;
|
|
46
|
-
const children = renderMarkupTokens(token.children, renderers);
|
|
47
|
-
const renderer = renderers[token.tag];
|
|
48
|
-
if (typeof renderer === "function") return renderer(children);
|
|
49
|
-
return children;
|
|
50
|
-
}).join("");
|
|
51
|
-
/**
|
|
52
|
-
* The untyped runtime translator shared by `useTranslations` (React hook) and
|
|
53
|
-
* `createTranslator` (non-React core).
|
|
54
|
-
*
|
|
55
|
-
* Behaviour matches use-intl / next-intl:
|
|
56
|
-
* - namespace `'about'` → keys resolved inside the `about` dictionary
|
|
57
|
-
* - namespace `'about.counter'` → dictionary `about`, key prefix `counter`
|
|
58
|
-
* - no namespace → the first segment of each key is the dictionary key
|
|
59
|
-
* - messages support ICU syntax (plural, select, `#`, formatted arguments)
|
|
60
|
-
* - `t.rich` / `t.markup` map `<tag>chunks</tag>` through the provided
|
|
61
|
-
* renderers; `t.raw` returns the raw value; `t.has` checks existence
|
|
62
|
-
*
|
|
63
|
-
* @param locale - The locale dictionaries are resolved for.
|
|
64
|
-
* @param namespace - Optional dictionary key, optionally with a nested scope.
|
|
65
|
-
* @returns A translate function augmented with `has`, `raw`, `rich`, `markup`.
|
|
66
|
-
*/
|
|
67
|
-
const createNamespaceTranslator = (locale, namespace) => {
|
|
68
|
-
const [dictionaryKey, ...prefixSegments] = (namespace ?? "").split(".");
|
|
69
|
-
const keyPrefix = prefixSegments.join(".");
|
|
70
|
-
const lookup = (key) => {
|
|
71
|
-
let targetDictionaryKey = dictionaryKey;
|
|
72
|
-
let path = keyPrefix ? `${keyPrefix}.${key}` : key;
|
|
73
|
-
if (!targetDictionaryKey) {
|
|
74
|
-
const [firstSegment, ...restSegments] = key.split(".");
|
|
75
|
-
targetDictionaryKey = firstSegment;
|
|
76
|
-
path = restSegments.join(".");
|
|
77
|
-
}
|
|
78
|
-
try {
|
|
79
|
-
return navigatePath((0, _intlayer_core_interpreter.getIntlayer)(targetDictionaryKey, locale), path);
|
|
80
|
-
} catch {
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
const resolveToString = (key, values = {}) => {
|
|
85
|
-
const rawValue = lookup(key);
|
|
86
|
-
if (rawValue === null || rawValue === void 0) return void 0;
|
|
87
|
-
return (0, _intlayer_core_messageFormat.resolveMessage)(rawValue, values, locale, "icu");
|
|
88
|
-
};
|
|
89
|
-
const missingKeyFallback = (key) => namespace ? `${namespace}.${key}` : key;
|
|
90
|
-
const translate = (key, values) => resolveToString(key, values) ?? missingKeyFallback(key);
|
|
91
|
-
return Object.assign(translate, {
|
|
92
|
-
/** Returns `true` if the given key exists in the namespace. */
|
|
93
|
-
has: (key) => lookup(key) !== void 0,
|
|
94
|
-
/** Returns the raw unprocessed content for the given key. */
|
|
95
|
-
raw: (key) => lookup(key),
|
|
96
|
-
/**
|
|
97
|
-
* Resolves a message containing `<tag>chunks</tag>` markup, mapping each
|
|
98
|
-
* tag through the matching renderer in `values`.
|
|
99
|
-
*/
|
|
100
|
-
rich: (key, values) => {
|
|
101
|
-
const { scalarValues, renderers } = splitRichValues(values);
|
|
102
|
-
const message = resolveToString(key, scalarValues);
|
|
103
|
-
if (message === void 0) return missingKeyFallback(key);
|
|
104
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: renderRichTokens((0, _intlayer_core_messageFormat.parseTaggedMessage)(message), renderers) });
|
|
105
|
-
},
|
|
106
|
-
/**
|
|
107
|
-
* Resolves a message containing `<tag>chunks</tag>` markup into a string,
|
|
108
|
-
* mapping each tag through the matching string renderer in `values`.
|
|
109
|
-
*/
|
|
110
|
-
markup: (key, values) => {
|
|
111
|
-
const { scalarValues, renderers } = splitRichValues(values);
|
|
112
|
-
const message = resolveToString(key, scalarValues);
|
|
113
|
-
if (message === void 0) return missingKeyFallback(key);
|
|
114
|
-
return renderMarkupTokens((0, _intlayer_core_messageFormat.parseTaggedMessage)(message), renderers);
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
//#endregion
|
|
120
|
-
exports.createNamespaceTranslator = createNamespaceTranslator;
|
|
121
|
-
exports.navigatePath = navigatePath;
|
|
122
|
-
//# sourceMappingURL=namespaceTranslator.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"namespaceTranslator.cjs","names":["Fragment"],"sources":["../../../src/shared/namespaceTranslator.tsx"],"sourcesContent":["import { getIntlayer } from '@intlayer/core/interpreter';\nimport {\n type MessageValues,\n parseTaggedMessage,\n resolveMessage,\n type TaggedMessageToken,\n} from '@intlayer/core/messageFormat';\nimport type {\n DictionaryKeys,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { Fragment, type ReactNode } from 'react';\n\n/** Chunk renderer used by `t.rich()` — maps tag children to a React node. */\nexport type RichChunkRenderer = (chunks: ReactNode) => ReactNode;\n\n/** Chunk renderer used by `t.markup()` — maps tag children to a string. */\nexport type MarkupChunkRenderer = (chunks: string) => string;\n\n/**\n * Reads a dotted `path` (e.g. `counter.label`) out of a nested object value.\n *\n * @param objectValue - The object to read from.\n * @param path - Dot-separated path. An empty path returns `objectValue`.\n * @returns The value found at `path`, or `undefined` when any segment is absent.\n */\nexport const 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/** Splits rich values into scalar interpolation values and tag renderers. */\nconst splitRichValues = (\n values: Record<string, unknown> = {}\n): { scalarValues: MessageValues; renderers: Record<string, unknown> } => {\n const scalarValues: MessageValues = {};\n const renderers: Record<string, unknown> = {};\n\n for (const [valueKey, value] of Object.entries(values)) {\n if (typeof value === 'function') renderers[valueKey] = value;\n else scalarValues[valueKey] = value;\n }\n\n return { scalarValues, renderers };\n};\n\nconst renderRichTokens = (\n tokens: TaggedMessageToken[],\n renderers: Record<string, unknown>\n): ReactNode[] =>\n tokens.map((token, tokenIndex) => {\n if (typeof token === 'string') return token;\n\n const children = renderRichTokens(token.children, renderers);\n const renderer = renderers[token.tag];\n\n if (typeof renderer === 'function') {\n return (\n <Fragment key={tokenIndex}>\n {(renderer as RichChunkRenderer)(children)}\n </Fragment>\n );\n }\n\n // No renderer provided for the tag — render its children unwrapped\n return <Fragment key={tokenIndex}>{children}</Fragment>;\n });\n\nconst renderMarkupTokens = (\n tokens: TaggedMessageToken[],\n renderers: Record<string, unknown>\n): string =>\n tokens\n .map((token) => {\n if (typeof token === 'string') return token;\n\n const children = renderMarkupTokens(token.children, renderers);\n const renderer = renderers[token.tag];\n\n if (typeof renderer === 'function') {\n return (renderer as MarkupChunkRenderer)(children);\n }\n\n return children;\n })\n .join('');\n\n/**\n * The untyped runtime translator shared by `useTranslations` (React hook) and\n * `createTranslator` (non-React core).\n *\n * Behaviour matches use-intl / next-intl:\n * - namespace `'about'` → keys resolved inside the `about` dictionary\n * - namespace `'about.counter'` → dictionary `about`, key prefix `counter`\n * - no namespace → the first segment of each key is the dictionary key\n * - messages support ICU syntax (plural, select, `#`, formatted arguments)\n * - `t.rich` / `t.markup` map `<tag>chunks</tag>` through the provided\n * renderers; `t.raw` returns the raw value; `t.has` checks existence\n *\n * @param locale - The locale dictionaries are resolved for.\n * @param namespace - Optional dictionary key, optionally with a nested scope.\n * @returns A translate function augmented with `has`, `raw`, `rich`, `markup`.\n */\nexport const createNamespaceTranslator = (\n locale: LocalesValues,\n namespace?: string\n) => {\n const [dictionaryKey, ...prefixSegments] = (namespace ?? '').split('.');\n const keyPrefix = prefixSegments.join('.');\n\n const lookup = (key: string): unknown => {\n let targetDictionaryKey = dictionaryKey;\n let path = keyPrefix ? `${keyPrefix}.${key}` : key;\n\n if (!targetDictionaryKey) {\n // Root scope — the first key segment designates the dictionary\n const [firstSegment, ...restSegments] = key.split('.');\n targetDictionaryKey = firstSegment;\n path = restSegments.join('.');\n }\n\n try {\n const dictionary = getIntlayer(\n targetDictionaryKey as DictionaryKeys,\n locale\n );\n return navigatePath(dictionary, path);\n } catch {\n return undefined;\n }\n };\n\n const resolveToString = (\n key: string,\n values: MessageValues = {}\n ): string | undefined => {\n const rawValue = lookup(key);\n if (rawValue === null || rawValue === undefined) return undefined;\n return resolveMessage(rawValue, values, locale, 'icu');\n };\n\n const missingKeyFallback = (key: string): string =>\n namespace ? `${namespace}.${key}` : key;\n\n const translate = (key: string, values?: MessageValues): string =>\n resolveToString(key, values) ?? missingKeyFallback(key);\n\n return Object.assign(translate, {\n /** Returns `true` if the given key exists in the namespace. */\n has: (key: string): boolean => lookup(key) !== undefined,\n\n /** Returns the raw unprocessed content for the given key. */\n raw: (key: string): unknown => lookup(key),\n\n /**\n * Resolves a message containing `<tag>chunks</tag>` markup, mapping each\n * tag through the matching renderer in `values`.\n */\n rich: (key: string, values?: Record<string, unknown>): ReactNode => {\n const { scalarValues, renderers } = splitRichValues(values);\n const message = resolveToString(key, scalarValues);\n if (message === undefined) return missingKeyFallback(key);\n return <>{renderRichTokens(parseTaggedMessage(message), renderers)}</>;\n },\n\n /**\n * Resolves a message containing `<tag>chunks</tag>` markup into a string,\n * mapping each tag through the matching string renderer in `values`.\n */\n markup: (key: string, values?: Record<string, unknown>): string => {\n const { scalarValues, renderers } = splitRichValues(values);\n const message = resolveToString(key, scalarValues);\n if (message === undefined) return missingKeyFallback(key);\n return renderMarkupTokens(parseTaggedMessage(message), renderers);\n },\n });\n};\n\nexport type CompatTranslator = ReturnType<typeof createNamespaceTranslator>;\n"],"mappings":";;;;;;;;;;;;;;;AA0BA,MAAa,gBAAgB,aAAsB,SAA0B;AAC3E,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;;;AAIT,MAAM,mBACJ,SAAkC,EAAE,KACoC;CACxE,MAAM,eAA8B,EAAE;CACtC,MAAM,YAAqC,EAAE;AAE7C,MAAK,MAAM,CAAC,UAAU,UAAU,OAAO,QAAQ,OAAO,CACpD,KAAI,OAAO,UAAU,WAAY,WAAU,YAAY;KAClD,cAAa,YAAY;AAGhC,QAAO;EAAE;EAAc;EAAW;;AAGpC,MAAM,oBACJ,QACA,cAEA,OAAO,KAAK,OAAO,eAAe;AAChC,KAAI,OAAO,UAAU,SAAU,QAAO;CAEtC,MAAM,WAAW,iBAAiB,MAAM,UAAU,UAAU;CAC5D,MAAM,WAAW,UAAU,MAAM;AAEjC,KAAI,OAAO,aAAa,WACtB,QACE,2CAACA,gBAAD,YACI,SAA+B,SAAS,EACjC,EAFI,WAEJ;AAKf,QAAO,2CAACA,gBAAD,EAA4B,UAAoB,EAAjC,WAAiC;EACvD;AAEJ,MAAM,sBACJ,QACA,cAEA,OACG,KAAK,UAAU;AACd,KAAI,OAAO,UAAU,SAAU,QAAO;CAEtC,MAAM,WAAW,mBAAmB,MAAM,UAAU,UAAU;CAC9D,MAAM,WAAW,UAAU,MAAM;AAEjC,KAAI,OAAO,aAAa,WACtB,QAAQ,SAAiC,SAAS;AAGpD,QAAO;EACP,CACD,KAAK,GAAG;;;;;;;;;;;;;;;;;AAkBb,MAAa,6BACX,QACA,cACG;CACH,MAAM,CAAC,eAAe,GAAG,mBAAmB,aAAa,IAAI,MAAM,IAAI;CACvE,MAAM,YAAY,eAAe,KAAK,IAAI;CAE1C,MAAM,UAAU,QAAyB;EACvC,IAAI,sBAAsB;EAC1B,IAAI,OAAO,YAAY,GAAG,UAAU,GAAG,QAAQ;AAE/C,MAAI,CAAC,qBAAqB;GAExB,MAAM,CAAC,cAAc,GAAG,gBAAgB,IAAI,MAAM,IAAI;AACtD,yBAAsB;AACtB,UAAO,aAAa,KAAK,IAAI;;AAG/B,MAAI;AAKF,UAAO,yDAHL,qBACA,OAE4B,EAAE,KAAK;UAC/B;AACN;;;CAIJ,MAAM,mBACJ,KACA,SAAwB,EAAE,KACH;EACvB,MAAM,WAAW,OAAO,IAAI;AAC5B,MAAI,aAAa,QAAQ,aAAa,OAAW,QAAO;AACxD,0DAAsB,UAAU,QAAQ,QAAQ,MAAM;;CAGxD,MAAM,sBAAsB,QAC1B,YAAY,GAAG,UAAU,GAAG,QAAQ;CAEtC,MAAM,aAAa,KAAa,WAC9B,gBAAgB,KAAK,OAAO,IAAI,mBAAmB,IAAI;AAEzD,QAAO,OAAO,OAAO,WAAW;;EAE9B,MAAM,QAAyB,OAAO,IAAI,KAAK;;EAG/C,MAAM,QAAyB,OAAO,IAAI;;;;;EAM1C,OAAO,KAAa,WAAgD;GAClE,MAAM,EAAE,cAAc,cAAc,gBAAgB,OAAO;GAC3D,MAAM,UAAU,gBAAgB,KAAK,aAAa;AAClD,OAAI,YAAY,OAAW,QAAO,mBAAmB,IAAI;AACzD,UAAO,mFAAG,sEAAoC,QAAQ,EAAE,UAAU,EAAI;;;;;;EAOxE,SAAS,KAAa,WAA6C;GACjE,MAAM,EAAE,cAAc,cAAc,gBAAgB,OAAO;GAC3D,MAAM,UAAU,gBAAgB,KAAK,aAAa;AAClD,OAAI,YAAY,OAAW,QAAO,mBAAmB,IAAI;AACzD,UAAO,wEAAsC,QAAQ,EAAE,UAAU;;EAEpE,CAAC"}
|
|
File without changes
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
5
|
-
const require_shared_namespaceTranslator = require('./shared/namespaceTranslator.cjs');
|
|
6
|
-
let react_intlayer = require("react-intlayer");
|
|
7
|
-
|
|
8
|
-
//#region src/useDictionary.ts
|
|
9
|
-
/**
|
|
10
|
-
* Dictionary-accepting variant of `useTranslations`.
|
|
11
|
-
*
|
|
12
|
-
* Used internally by the build-time optimization: instead of looking up the
|
|
13
|
-
* dictionary at runtime by key, the babel/swc plugin pre-imports the dictionary
|
|
14
|
-
* JSON at build time and passes it directly here. This enables tree-shaking of
|
|
15
|
-
* unused locale content.
|
|
16
|
-
*
|
|
17
|
-
* @example (generated by the plugin, not written manually)
|
|
18
|
-
* import _abc from '.intlayer/dictionaries/about.json' with { type: 'json' };
|
|
19
|
-
* const t = useDictionary(_abc);
|
|
20
|
-
*/
|
|
21
|
-
const useDictionary = (dictionary, namespacePrefix) => {
|
|
22
|
-
const content = (0, react_intlayer.useDictionary)(dictionary);
|
|
23
|
-
const resolveKey = (key) => namespacePrefix ? `${namespacePrefix}.${key}` : key;
|
|
24
|
-
return Object.assign((lookup, params) => {
|
|
25
|
-
const rawValue = require_shared_namespaceTranslator.navigatePath(content, resolveKey(String(lookup)));
|
|
26
|
-
const text = String(rawValue ?? resolveKey(String(lookup)));
|
|
27
|
-
if (!params) return text;
|
|
28
|
-
return text.replace(/\{(\w+)\}/g, (_match, key) => params[key] != null ? String(params[key]) : `{${key}}`);
|
|
29
|
-
}, {
|
|
30
|
-
has: (lookup) => require_shared_namespaceTranslator.navigatePath(content, resolveKey(String(lookup))) != null,
|
|
31
|
-
raw: (lookup) => require_shared_namespaceTranslator.navigatePath(content, resolveKey(String(lookup)))
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
//#endregion
|
|
36
|
-
exports.useDictionary = useDictionary;
|
|
37
|
-
//# sourceMappingURL=useDictionary.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionary.cjs","names":["navigatePath"],"sources":["../../src/useDictionary.ts"],"sourcesContent":["'use client';\n\nimport type { ValidDotPathsFor } from '@intlayer/core/transpiler';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport { useDictionary as useDictionaryBase } from 'react-intlayer';\nimport { navigatePath } from './shared/namespaceTranslator';\n\n/**\n * Dictionary-accepting variant of `useTranslations`.\n *\n * Used internally by the build-time optimization: instead of looking up the\n * dictionary at runtime by key, the babel/swc plugin pre-imports the dictionary\n * JSON at build time and passes it directly here. This enables tree-shaking of\n * unused locale content.\n *\n * @example (generated by the plugin, not written manually)\n * import _abc from '.intlayer/dictionaries/about.json' with { type: 'json' };\n * const t = useDictionary(_abc);\n */\nexport const useDictionary = <T extends Dictionary>(\n dictionary: T,\n namespacePrefix?: string\n) => {\n const content = useDictionaryBase(dictionary);\n\n const resolveKey = (key: string): string =>\n namespacePrefix ? `${namespacePrefix}.${key}` : key;\n\n return Object.assign(\n <P extends ValidDotPathsFor<string>>(\n lookup: P,\n params?: Record<string, unknown>\n ): string => {\n const rawValue = navigatePath(content, resolveKey(String(lookup)));\n const text = String(rawValue ?? resolveKey(String(lookup)));\n if (!params) return text;\n return text.replace(/\\{(\\w+)\\}/g, (_match, key) =>\n params[key] != null ? String(params[key]) : `{${key}}`\n );\n },\n {\n has: <P extends ValidDotPathsFor<string>>(lookup: P): boolean =>\n navigatePath(content, resolveKey(String(lookup))) != null,\n raw: <P extends ValidDotPathsFor<string>>(lookup: P): unknown =>\n navigatePath(content, resolveKey(String(lookup))),\n }\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAmBA,MAAa,iBACX,YACA,oBACG;CACH,MAAM,4CAA4B,WAAW;CAE7C,MAAM,cAAc,QAClB,kBAAkB,GAAG,gBAAgB,GAAG,QAAQ;AAElD,QAAO,OAAO,QAEV,QACA,WACW;EACX,MAAM,WAAWA,gDAAa,SAAS,WAAW,OAAO,OAAO,CAAC,CAAC;EAClE,MAAM,OAAO,OAAO,YAAY,WAAW,OAAO,OAAO,CAAC,CAAC;AAC3D,MAAI,CAAC,OAAQ,QAAO;AACpB,SAAO,KAAK,QAAQ,eAAe,QAAQ,QACzC,OAAO,QAAQ,OAAO,OAAO,OAAO,KAAK,GAAG,IAAI,IAAI,GACrD;IAEH;EACE,MAA0C,WACxCA,gDAAa,SAAS,WAAW,OAAO,OAAO,CAAC,CAAC,IAAI;EACvD,MAA0C,WACxCA,gDAAa,SAAS,WAAW,OAAO,OAAO,CAAC,CAAC;EACpD,CACF"}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
5
|
-
const require_shared_namespaceTranslator = require('./shared/namespaceTranslator.cjs');
|
|
6
|
-
let react_intlayer = require("react-intlayer");
|
|
7
|
-
|
|
8
|
-
//#region src/useDictionaryDynamic.ts
|
|
9
|
-
/**
|
|
10
|
-
* Dynamic dictionary-accepting variant of `useTranslations`.
|
|
11
|
-
*
|
|
12
|
-
* Counterpart to {@link useDictionary} for dictionaries imported lazily per
|
|
13
|
-
* locale. Used internally by the build-time optimization.
|
|
14
|
-
*/
|
|
15
|
-
const useDictionaryDynamic = (dictionaryPromise, key, namespacePrefix) => {
|
|
16
|
-
const content = (0, react_intlayer.useDictionaryDynamic)(dictionaryPromise, key);
|
|
17
|
-
const resolveKey = (lookupKey) => namespacePrefix ? `${namespacePrefix}.${lookupKey}` : lookupKey;
|
|
18
|
-
return Object.assign((lookup, params) => {
|
|
19
|
-
const rawValue = require_shared_namespaceTranslator.navigatePath(content, resolveKey(String(lookup)));
|
|
20
|
-
const text = String(rawValue ?? resolveKey(String(lookup)));
|
|
21
|
-
if (!params) return text;
|
|
22
|
-
return text.replace(/\{(\w+)\}/g, (_match, key) => params[key] != null ? String(params[key]) : `{${key}}`);
|
|
23
|
-
}, {
|
|
24
|
-
has: (lookup) => require_shared_namespaceTranslator.navigatePath(content, resolveKey(String(lookup))) != null,
|
|
25
|
-
raw: (lookup) => require_shared_namespaceTranslator.navigatePath(content, resolveKey(String(lookup)))
|
|
26
|
-
});
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
//#endregion
|
|
30
|
-
exports.useDictionaryDynamic = useDictionaryDynamic;
|
|
31
|
-
//# sourceMappingURL=useDictionaryDynamic.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionaryDynamic.cjs","names":["navigatePath"],"sources":["../../src/useDictionaryDynamic.ts"],"sourcesContent":["'use client';\n\nimport type { ValidDotPathsFor } from '@intlayer/core/transpiler';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type { StrictModeLocaleMap } from '@intlayer/types/module_augmentation';\nimport { useDictionaryDynamic as useDictionaryDynamicBase } from 'react-intlayer';\nimport { navigatePath } from './shared/namespaceTranslator';\n\n/**\n * Dynamic dictionary-accepting variant of `useTranslations`.\n *\n * Counterpart to {@link useDictionary} for dictionaries imported lazily per\n * locale. Used internally by the build-time optimization.\n */\nexport const useDictionaryDynamic = <\n const T extends Dictionary,\n const K extends string,\n>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n key: K,\n namespacePrefix?: string\n) => {\n const content = useDictionaryDynamicBase<T, K>(dictionaryPromise, key);\n\n const resolveKey = (lookupKey: string): string =>\n namespacePrefix ? `${namespacePrefix}.${lookupKey}` : lookupKey;\n\n return Object.assign(\n <P extends ValidDotPathsFor<string>>(\n lookup: P,\n params?: Record<string, unknown>\n ): string => {\n const rawValue = navigatePath(content, resolveKey(String(lookup)));\n const text = String(rawValue ?? resolveKey(String(lookup)));\n if (!params) return text;\n return text.replace(/\\{(\\w+)\\}/g, (_match, key) =>\n params[key] != null ? String(params[key]) : `{${key}}`\n );\n },\n {\n has: <P extends ValidDotPathsFor<string>>(lookup: P): boolean =>\n navigatePath(content, resolveKey(String(lookup))) != null,\n raw: <P extends ValidDotPathsFor<string>>(lookup: P): unknown =>\n navigatePath(content, resolveKey(String(lookup))),\n }\n );\n};\n"],"mappings":";;;;;;;;;;;;;;AAcA,MAAa,wBAIX,mBACA,KACA,oBACG;CACH,MAAM,mDAAyC,mBAAmB,IAAI;CAEtE,MAAM,cAAc,cAClB,kBAAkB,GAAG,gBAAgB,GAAG,cAAc;AAExD,QAAO,OAAO,QAEV,QACA,WACW;EACX,MAAM,WAAWA,gDAAa,SAAS,WAAW,OAAO,OAAO,CAAC,CAAC;EAClE,MAAM,OAAO,OAAO,YAAY,WAAW,OAAO,OAAO,CAAC,CAAC;AAC3D,MAAI,CAAC,OAAQ,QAAO;AACpB,SAAO,KAAK,QAAQ,eAAe,QAAQ,QACzC,OAAO,QAAQ,OAAO,OAAO,OAAO,KAAK,GAAG,IAAI,IAAI,GACrD;IAEH;EACE,MAA0C,WACxCA,gDAAa,SAAS,WAAW,OAAO,OAAO,CAAC,CAAC,IAAI;EACvD,MAA0C,WACxCA,gDAAa,SAAS,WAAW,OAAO,OAAO,CAAC,CAAC;EACpD,CACF"}
|