@intlayer/svelte-i18n 9.5.10

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.
Files changed (51) hide show
  1. package/README.md +329 -0
  2. package/dist/esm/configuration.mjs +98 -0
  3. package/dist/esm/configuration.mjs.map +1 -0
  4. package/dist/esm/createMessageFormatter.mjs +49 -0
  5. package/dist/esm/createMessageFormatter.mjs.map +1 -0
  6. package/dist/esm/formatters.mjs +53 -0
  7. package/dist/esm/formatters.mjs.map +1 -0
  8. package/dist/esm/helpers.mjs +86 -0
  9. package/dist/esm/helpers.mjs.map +1 -0
  10. package/dist/esm/index.mjs +9 -0
  11. package/dist/esm/locale.mjs +35 -0
  12. package/dist/esm/locale.mjs.map +1 -0
  13. package/dist/esm/plugin/index.mjs +35 -0
  14. package/dist/esm/plugin/index.mjs.map +1 -0
  15. package/dist/esm/registryLookup.mjs +57 -0
  16. package/dist/esm/registryLookup.mjs.map +1 -0
  17. package/dist/esm/runtimeMessages.mjs +42 -0
  18. package/dist/esm/runtimeMessages.mjs.map +1 -0
  19. package/dist/esm/stores.mjs +36 -0
  20. package/dist/esm/stores.mjs.map +1 -0
  21. package/dist/esm/types.mjs +0 -0
  22. package/dist/esm/useDictionary.mjs +46 -0
  23. package/dist/esm/useDictionary.mjs.map +1 -0
  24. package/dist/esm/useDictionaryDynamic.mjs +50 -0
  25. package/dist/esm/useDictionaryDynamic.mjs.map +1 -0
  26. package/dist/types/configuration.d.ts +18 -0
  27. package/dist/types/configuration.d.ts.map +1 -0
  28. package/dist/types/createMessageFormatter.d.ts +18 -0
  29. package/dist/types/createMessageFormatter.d.ts.map +1 -0
  30. package/dist/types/formatters.d.ts +10 -0
  31. package/dist/types/formatters.d.ts.map +1 -0
  32. package/dist/types/helpers.d.ts +49 -0
  33. package/dist/types/helpers.d.ts.map +1 -0
  34. package/dist/types/index.d.ts +9 -0
  35. package/dist/types/locale.d.ts +21 -0
  36. package/dist/types/locale.d.ts.map +1 -0
  37. package/dist/types/plugin/index.d.ts +11 -0
  38. package/dist/types/plugin/index.d.ts.map +1 -0
  39. package/dist/types/registryLookup.d.ts +14 -0
  40. package/dist/types/registryLookup.d.ts.map +1 -0
  41. package/dist/types/runtimeMessages.d.ts +18 -0
  42. package/dist/types/runtimeMessages.d.ts.map +1 -0
  43. package/dist/types/stores.d.ts +17 -0
  44. package/dist/types/stores.d.ts.map +1 -0
  45. package/dist/types/types.d.ts +64 -0
  46. package/dist/types/types.d.ts.map +1 -0
  47. package/dist/types/useDictionary.d.ts +39 -0
  48. package/dist/types/useDictionary.d.ts.map +1 -0
  49. package/dist/types/useDictionaryDynamic.d.ts +16 -0
  50. package/dist/types/useDictionaryDynamic.d.ts.map +1 -0
  51. package/package.json +108 -0
package/README.md ADDED
@@ -0,0 +1,329 @@
1
+ <p align="center">
2
+ <a href="https://intlayer.org" rel="">
3
+ <img src="https://raw.githubusercontent.com/aymericzip/intlayer/main/docs/assets/cover.webp" width="60%" alt="Intlayer Logo" />
4
+ </a>
5
+ </p>
6
+
7
+ <h1 align="center">
8
+ <strong>Per-component i18n</strong>
9
+ </h1>
10
+
11
+ <h2 align="center">
12
+ <strong>AI-powered translation. Visual Editor. Multilingual CMS.</strong>
13
+ </h2>
14
+
15
+ <br />
16
+
17
+ <p align="center">
18
+ <a href="https://intlayer.org/doc/concept/content" rel="">Docs</a> •
19
+ <a href="https://intlayer.org/doc/environment/nextjs" rel="">Next.js</a> •
20
+ <a href="https://intlayer.org/doc/environment/vite-and-react" rel="">React + Vite</a> •
21
+ <a href="https://intlayer.org/doc/concept/cms" rel="">CMS</a> •
22
+ <a href="https://discord.gg/7uxamYVeCk" rel="noopener noreferrer nofollow">Discord</a>
23
+ </p>
24
+ <p align="center" style="margin-top:15px;">
25
+ <a href="https://www.npmjs.com/package/intlayer" target="_blank" rel="noopener noreferrer nofollow"><img src="https://img.shields.io/npm/v/intlayer?style=for-the-badge&labelColor=FFFFFF&color=000000&logoColor=FFFFFF" alt="npm version" height="24"/></a>
26
+ <a href="https://github.com/aymericzip/intlayer/stargazers" target="_blank" rel="noopener noreferrer nofollow"><img src="https://img.shields.io/github/stars/aymericzip/intlayer?style=for-the-badge&labelColor=000000&color=FFFFFF&logo=github&logoColor=FFD700" alt="GitHub Stars" height="24"/></a>
27
+ <a href="https://www.npmjs.org/package/intlayer" target="_blank" rel="noopener noreferrer nofollow"><img src="https://img.shields.io/npm/dm/intlayer?style=for-the-badge&labelColor=000000&color=FFFFFF&logoColor=000000&cacheSeconds=86400" alt="monthly downloads" height="24"/></a>
28
+ <a href="https://github.com/aymericzip/intlayer/blob/main/LICENSE" target="_blank" rel="noopener noreferrer nofollow"><img src="https://img.shields.io/github/license/aymericzip/intlayer?style=for-the-badge&labelColor=000000&color=FFFFFF&logoColor=000000&cacheSeconds=86400" alt="license"/></a>
29
+ <a href="https://github.com/aymericzip/intlayer/commits/main" target="_blank" rel="noopener noreferrer nofollow"><img src="https://img.shields.io/github/last-commit/aymericzip/intlayer?style=for-the-badge&labelColor=000000&color=FFFFFF&logoColor=000000&cacheSeconds=86400" alt="last commit"/>
30
+ </a>
31
+ </p>
32
+
33
+ ![Watch the video](https://github.com/aymericzip/intlayer/blob/main/docs/assets/demo_video.gif)
34
+
35
+ <a href="https://intlayer.org/doc/concept/content" rel="">
36
+ <img src="https://img.shields.io/badge/Get_Started-FFFFFF?style=for-the-badge&logo=rocket&logoColor=black" />
37
+ </a>
38
+
39
+ ## What is Intlayer?
40
+
41
+ Most i18n libraries are either too complex, too rigid, or not built for modern frameworks.
42
+
43
+ Intlayer is a **modern i18n solution** for web and mobile apps.
44
+ It’s framework-agnostic, **AI-powered**, and includes a free **CMS & visual editor**.
45
+
46
+ With **per-locale content files**, **TypeScript autocompletion**, **tree-shakable dictionaries**, and **CI/CD integration**, Intlayer makes internationalization **faster, cleaner, and smarter**.
47
+
48
+ ## Keys benefits of Intlayer:
49
+
50
+ | Feature | Description |
51
+ | --------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
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
+ | <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
+ | <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.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
+ | <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
+ | <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
+ | <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) |
59
+ | <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/server_component.png?raw=true" alt="Feature" width="700"> | **Consistent Server Component Implementation**<br><br>Perfectly suited for Next.js server components, use the same implementation for both client and server components, no need to pass your `t` function across each server component. <br><br> - [Server Components](https://intlayer.org/doc/environment/nextjs#step-7-utilize-content-in-your-code) |
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
+ | <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
+ | <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.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
+ | <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
+ | <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.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
+ | <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
+ | <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
+
72
+ ## 📦 Installation
73
+
74
+ Start your journey with Intlayer today and experience a smoother, more powerful approach to internationalization.
75
+
76
+ <a href="https://intlayer.org/doc/concept/content" rel="">
77
+ <img src="https://img.shields.io/badge/Get_Started-FFFFFF?style=for-the-badge&logo=rocket&logoColor=black" />
78
+ </a>
79
+
80
+ ```bash
81
+ npm install intlayer react-intlayer
82
+ ```
83
+
84
+ ⚡ Quick Start (Next.js)
85
+
86
+ ```ts
87
+ // intlayer.config.ts
88
+ import { Locales, type IntlayerConfig } from "intlayer";
89
+
90
+ const config: IntlayerConfig = {
91
+ internationalization: {
92
+ locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH],
93
+ defaultLocale: Locales.ENGLISH,
94
+ },
95
+ };
96
+
97
+ export default config;
98
+ ```
99
+
100
+ ```ts
101
+ // app/home.content.ts
102
+ import { t, type Dictionary } from "intlayer";
103
+
104
+ const content = {
105
+ key: "home",
106
+ content: {
107
+ title: t({
108
+ en: "Home",
109
+ fr: "Accueil",
110
+ es: "Inicio",
111
+ }),
112
+ },
113
+ } satisfies Dictionary;
114
+
115
+ export default content;
116
+ ```
117
+
118
+ ```tsx
119
+ // app/page.tsx
120
+ import { useIntlayer } from "react-intlayer";
121
+
122
+ const HomePage = () => {
123
+ const { title } = useIntlayer("home");
124
+
125
+ return <h1>{title}</h1>;
126
+ };
127
+ ```
128
+
129
+ <a href="https://intlayer.org/doc/environment/nextjs"> Get the full guide → </a>
130
+
131
+ ## 🎥 Live tutorial on YouTube
132
+
133
+ [![How to Internationalize your application using Intlayer](https://i.ytimg.com/vi/e_PPG7PTqGU/hqdefault.jpg?sqp=-oaymwEcCNACELwBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLDtyJ4uYotEjl12nZ_gZKZ_kjEgOQ)](https://youtu.be/e_PPG7PTqGU?si=GyU_KpVhr61razRw)
134
+
135
+ <a href="https://intlayer.org/doc/concept/content" rel="">
136
+ <img src="https://img.shields.io/badge/Get_Started-FFFFFF?style=for-the-badge&logo=rocket&logoColor=black" />
137
+ </a>
138
+
139
+ ## Table of Contents
140
+
141
+ Explore our comprehensive documentation to get started with Intlayer and learn how to integrate it into your projects.
142
+
143
+ <details open>
144
+ <summary style="font-size:16px; font-weight:bold;">📘 Get Started</summary>
145
+ <ul>
146
+ <li><a href="https://intlayer.org/doc/why" rel=''>Why Intlayer?</a></li>
147
+ <li><a href="https://intlayer.org/doc" rel=''>Introduction</a></li>
148
+ </ul>
149
+ </details>
150
+
151
+ <details>
152
+ <summary style="font-size:16px; font-weight:bold;">⚙️ Concept</summary>
153
+ <ul>
154
+ <li><a href="https://intlayer.org/doc/concept/how-works-intlayer" rel=''>How Intlayer Works</a></li>
155
+ <li><a href="https://intlayer.org/doc/concept/configuration" rel=''>Configuration</a></li>
156
+ <li><a href="https://intlayer.org/doc/concept/cli" rel=''>Intlayer CLI</a></li>
157
+ <li><a href="https://intlayer.org/doc/compiler" rel=''>Compiler</a></li>
158
+
159
+ <li><a href="https://intlayer.org/doc/concept/editor" rel=''>Intlayer Editor</a></li>
160
+ <li><a href="https://intlayer.org/doc/concept/cms" rel=''>Intlayer CMS</a></li>
161
+ <li><a href="https://intlayer.org/doc/concept/content" rel=''>Dictionary</a>
162
+ <ul>
163
+ <li><a href="https://intlayer.org/doc/concept/per-locale-file" rel=''>Per-Locale Content Declaration File</a></li>
164
+ <li><a href="https://intlayer.org/doc/concept/content/translation" rel=''>Translation</a></li>
165
+ <li><a href="https://intlayer.org/doc/concept/content/enumeration" rel=''>Enumeration</a></li>
166
+ <li><a href="https://intlayer.org/doc/concept/content/condition" rel=''>Condition</a></li>
167
+ <li><a href="https://intlayer.org/doc/concept/content/nesting" rel=''>Nesting</a></li>
168
+ <li><a href="https://intlayer.org/doc/concept/content/markdown" rel=''>Markdown</a></li>
169
+ <li><a href="https://intlayer.org/doc/concept/content/function-fetching" rel=''>Function Fetching</a></li>
170
+ <li><a href="https://intlayer.org/doc/concept/content/insertion" rel=''>Insertion</a></li>
171
+ <li><a href="https://intlayer.org/doc/concept/content/file" rel=''>File</a></li>
172
+ </ul>
173
+ </li>
174
+ </ul>
175
+ </details>
176
+
177
+ <details open>
178
+ <summary style="font-size:16px; font-weight:bold;">🌐 Environment</summary>
179
+ <ul>
180
+ <li><a href="https://intlayer.org/doc/environment/nextjs" rel=''>Intlayer with Next.js 16</a>
181
+ <ul>
182
+ <li><a href="https://intlayer.org/doc/environment/nextjs/15" rel=''>Next.js 15</a></li>
183
+ <li><a href="https://intlayer.org/doc/environment/nextjs/14" rel=''>Next.js 14 (App Router)</a></li>
184
+ <li><a href="https://intlayer.org/doc/environment/nextjs/next-with-page-router" rel=''>Next.js Page Router</a></li>
185
+ <li><a href="https://intlayer.org/doc/environment/nextjs/compiler" rel=''>Next.js using Compiler</a></li>
186
+ </ul>
187
+ </li>
188
+ <li><a href="https://intlayer.org/doc/environment/create-react-app" rel=''>React CRA</a></li>
189
+ <li><a href="https://intlayer.org/doc/environment/vite-and-react" rel=''>Vite + React</a></li>
190
+ <li><a href="https://intlayer.org/doc/environment/vite-and-react" rel=''>Vite + React using Compiler</a></li>
191
+ <li><a href="https://intlayer.org/doc/environment/vite-and-react/react-router-v7" rel=''>React-router-v7</a></li>
192
+ <li><a href="https://intlayer.org/doc/environment/remix-3" rel=''>Remix 3</a></li>
193
+ <li><a href="https://intlayer.org/doc/environment/tanstack-start" rel=''>Tanstack start</a>
194
+ <ul>
195
+ <li><a href="https://intlayer.org/doc/environment/tanstack-start/solid" rel=''>Solid</a></li>
196
+ </ul>
197
+ </li>
198
+ <li><a href="https://intlayer.org/doc/environment/astro" rel=''>Astro</a>
199
+ <ul>
200
+ <li><a href="https://intlayer.org/doc/environment/astro/react" rel=''>React</a></li>
201
+ <li><a href="https://intlayer.org/doc/environment/astro/vue" rel=''>Vue</a></li>
202
+ <li><a href="https://intlayer.org/doc/environment/astro/svelte" rel=''>Svelte</a></li>
203
+ <li><a href="https://intlayer.org/doc/environment/astro/solid" rel=''>Solid</a></li>
204
+ <li><a href="https://intlayer.org/doc/environment/astro/lit" rel=''>Lit</a></li>
205
+ </ul>
206
+ </li>
207
+
208
+ <li><a href="https://intlayer.org/doc/environment/react-native-and-expo" rel=''>React Native</a></li>
209
+ <li><a href="https://intlayer.org/doc/environment/vite-and-svelte" rel=''>Vite + Svelte</a></li>
210
+ <li><a href="https://intlayer.org/doc/environment/sveltekit" rel=''>SvelteKit</a></li>
211
+ <li><a href="https://intlayer.org/doc/environment/vite-and-preact" rel=''>Vite + Preact</a></li>
212
+ <li><a href="https://intlayer.org/doc/environment/vite-and-vue" rel=''>Vite + Vue</a></li>
213
+ <li><a href="https://intlayer.org/doc/environment/nuxt-and-vue" rel=''>Vite + Nuxt</a></li>
214
+ <li><a href="https://intlayer.org/doc/environment/vite-and-solid" rel=''>Vite + Solid</a></li>
215
+ <li><a href="https://intlayer.org/doc/environment/solid-start" rel=''>Solid Start</a></li>
216
+ <li><a href="https://intlayer.org/doc/environment/angular" rel=''>Angular</a></li> <li>
217
+ <a href="https://intlayer.org/doc/environment/express" rel=''>Backend</a>
218
+ <ul>
219
+ <li><a href="https://intlayer.org/doc/environment/express" rel=''>Express</a></li>
220
+ <li><a href="https://intlayer.org/doc/environment/nest" rel=''>NestJS</a></li>
221
+ <li><a href="https://intlayer.org/doc/environment/fastify" rel=''>Fastify</a></li>
222
+ <li><a href="https://intlayer.org/doc/environment/adonisjs" rel=''>AdonisJS</a></li>
223
+ <li><a href="https://intlayer.org/doc/environment/hono" rel=''>Hono</a></li>
224
+ <li><a href="https://intlayer.org/doc/environment/elysia" rel=''>Elysia</a></li>
225
+ </ul>
226
+ </li>
227
+ </ul>
228
+ </details>
229
+
230
+ <details>
231
+ <summary style="font-size:16px; font-weight:bold;">📊 Benchmark</summary>
232
+ <ul>
233
+ <li><a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/benchmark/nextjs.md" rel=''>Next.js</a></li>
234
+ <li><a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/benchmark/tanstack.md" rel=''>TanStack Start</a></li>
235
+ <li><a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/benchmark/vue.md" rel=''>Vue</a></li>
236
+ <li><a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/benchmark/solid.md" rel=''>Solid</a></li>
237
+ <li><a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/benchmark/svelte.md" rel=''>Svelte</a></li>
238
+ </ul>
239
+ </details>
240
+
241
+ <details>
242
+ <summary style="font-size:16px; font-weight:bold;">📰 Blog</summary>
243
+ <ul>
244
+ <li><a href="https://github.com/aymericzip/intlayer/blob/main/docs/blog/en/what_is_internationalization.md" rel=''>What is i18n</a></li>
245
+ <li><a href="https://intlayer.org/blog/SEO-and-i18n" rel=''>i18n and SEO</a></li>
246
+ <li><a href="https://intlayer.org/blog/intlayer-with-next-i18next" rel=''>Intlayer and i18next</a></li>
247
+ <li><a href="https://intlayer.org/blog/intlayer-with-react-i18next" rel=''>Intlayer and react-intl</a></li>
248
+ <li><a href="https://intlayer.org/blog/intlayer-with-next-intl" rel=''>Intlayer and next-intl</a></li>
249
+ </ul>
250
+ </details>
251
+
252
+ ## Multilingual content management system
253
+
254
+ More than an i18n library, Intlayer is a complete **multilingual content management system**. A full CMS is available for free at [app.intlayer.org](https://app.intlayer.org).
255
+
256
+ Intlayer connects **developers**, **copywriters**, and **AI agents** in one workflow for creating and maintaining multilingual websites effortlessly.Intlayer replaces the following stack in a single solution:
257
+
258
+ - i18n solutions (e.g. `i18next`, `next-intl`, `vue-i18n`)
259
+ - TMSs (Translation Management Systems) (e.g. Crowdin, Phrase, Lokalise)
260
+ - Feature flags
261
+ - Headless CMSs (e.g. Contentful, Strapi, Sanity)
262
+
263
+ ![CMS Preview](https://github.com/aymericzip/intlayer/blob/main/docs/assets/CMS.webp?raw=true)
264
+
265
+ ## 🌐 Readme in other languages
266
+
267
+ <p align="center">
268
+ <a href="https://github.com/aymericzip/intlayer/blob/main/readme.md">English</a> •
269
+ <a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/zh/readme.md">简体中文</a> •
270
+ <a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/ru/readme.md">Русский</a> •
271
+ <a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/ja/readme.md">日本語</a> •
272
+ <a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/fr/readme.md">Français</a> •
273
+ <a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/ko/readme.md">한국어</a> •
274
+ <a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/es/readme.md">Español</a> •
275
+ <a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/de/readme.md">Deutsch</a> •
276
+ <a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/ar/readme.md">العربية</a> •
277
+ <a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/it/readme.md">Italiano</a> •
278
+ <a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/en-GB/readme.md">English (UK)</a> •
279
+ <a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/pt/readme.md">Português</a> •
280
+ <a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/hi/readme.md">हिन्दी</a> •
281
+ <a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/tr/readme.md">Türkçe</a>
282
+ </p>
283
+
284
+ ## 🤝 Community
285
+
286
+ Intlayer is built with and for the community and we’d love your input!
287
+
288
+ - Have a suggestion? [Open an issue](https://github.com/aymericzip/intlayer/issues)
289
+ - Found a bug or improvement? [Submit a PR](https://github.com/aymericzip/intlayer/pulls)
290
+ - Need help or want to connect? [Join our Discord](https://discord.gg/7uxamYVeCk)
291
+
292
+ You can also follow us on :
293
+
294
+ <div>
295
+ <br/>
296
+ <p align="center">
297
+ <a href="https://discord.gg/528mBV4N" target="blank" rel='noopener noreferrer nofollow'><img align="center"
298
+ src="https://img.shields.io/badge/discord-5865F2.svg?style=for-the-badge&logo=discord&logoColor=white"
299
+ alt="Intlayer Discord" height="30"/></a>
300
+ <a href="https://www.linkedin.com/company/intlayerorg" target="blank" rel='noopener noreferrer nofollow'><img align="center"
301
+ src="https://img.shields.io/badge/linkedin-%231DA1F2.svg?style=for-the-badge&logo=linkedin&logoColor=white"
302
+ alt="Intlayer LinkedIn" height="30"/></a>
303
+ <a href="https://www.instagram.com/intlayer/" target="blank" rel='noopener noreferrer nofollow'><img align="center"
304
+ src="https://img.shields.io/badge/instagram-%23E4405F.svg?style=for-the-badge&logo=Instagram&logoColor=white"
305
+ alt="Intlayer Instagram" height="30"/></a>
306
+ <a href="https://x.com/Intlayer183096" target="blank" rel='noopener noreferrer nofollow'><img align="center"
307
+ src="https://img.shields.io/badge/x-1DA1F2.svg?style=for-the-badge&logo=x&logoColor=white"
308
+ alt="Intlayer X" height="30"/></a>
309
+ <a href="https://www.youtube.com/@intlayer" target="blank" rel='noopener noreferrer nofollow'><img align="center"
310
+ src="https://img.shields.io/badge/youtube-FF0000.svg?style=for-the-badge&logo=youtube&logoColor=white"
311
+ alt="Intlayer YouTube" height="30"/></a>
312
+ <a href="https://www.tiktok.com/@intlayer" target="blank" rel='noopener noreferrer nofollow'><img align="center"
313
+ src="https://img.shields.io/badge/tiktok-000000.svg?style=for-the-badge&logo=tiktok&logoColor=white"
314
+ alt="Intlayer TikTok" height="30"/></a>
315
+ <br>
316
+ </p>
317
+ </div>
318
+
319
+ ### Contribution
320
+
321
+ For more detailed guidelines on contributing to this project, please refer to the [`CONTRIBUTING.md`](https://github.com/aymericzip/intlayer/blob/main/CONTRIBUTING.md) file. It contains essential information on our development process, commit message conventions, and release procedures. Your contributions are valuable to us, and we appreciate your efforts in making this project better!
322
+
323
+ Contribute on [GitHub](https://github.com/aymericzip/intlayer), [GitLab](https://gitlab.com/ay.pineau/intlayer), or [Bitbucket](https://bitbucket.org/intlayer/intlayer/).
324
+
325
+ ### Thank You for the Support
326
+
327
+ 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-).
328
+
329
+ [![Star History Chart](https://api.star-history.com/svg?repos=aymericzip/intlayer&type=Date)](https://star-history.com/#aymericzip/intlayer&Date)
@@ -0,0 +1,98 @@
1
+ import { internationalization } from "@intlayer/config/built";
2
+
3
+ //#region src/configuration.ts
4
+ /** svelte-i18n's built-in named formats (intl-messageformat defaults). */
5
+ const defaultFormats = {
6
+ number: {
7
+ scientific: { notation: "scientific" },
8
+ engineering: { notation: "engineering" },
9
+ compactLong: {
10
+ notation: "compact",
11
+ compactDisplay: "long"
12
+ },
13
+ compactShort: {
14
+ notation: "compact",
15
+ compactDisplay: "short"
16
+ }
17
+ },
18
+ date: {
19
+ short: {
20
+ month: "numeric",
21
+ day: "numeric",
22
+ year: "2-digit"
23
+ },
24
+ medium: {
25
+ month: "short",
26
+ day: "numeric",
27
+ year: "numeric"
28
+ },
29
+ long: {
30
+ month: "long",
31
+ day: "numeric",
32
+ year: "numeric"
33
+ },
34
+ full: {
35
+ weekday: "long",
36
+ month: "long",
37
+ day: "numeric",
38
+ year: "numeric"
39
+ }
40
+ },
41
+ time: {
42
+ short: {
43
+ hour: "numeric",
44
+ minute: "numeric"
45
+ },
46
+ medium: {
47
+ hour: "numeric",
48
+ minute: "numeric",
49
+ second: "numeric"
50
+ },
51
+ long: {
52
+ hour: "numeric",
53
+ minute: "numeric",
54
+ second: "numeric",
55
+ timeZoneName: "short"
56
+ },
57
+ full: {
58
+ hour: "numeric",
59
+ minute: "numeric",
60
+ second: "numeric",
61
+ timeZoneName: "short"
62
+ }
63
+ }
64
+ };
65
+ /** Locale used when nothing else is set: intlayer's configured default. */
66
+ const configDefaultLocale = internationalization?.defaultLocale ?? "en";
67
+ /** Locales declared in the intlayer configuration. */
68
+ const configLocales = internationalization?.locales ?? [configDefaultLocale];
69
+ /** Options set through `init()`, read by every store. */
70
+ const runtimeOptions = {
71
+ fallbackLocale: configDefaultLocale,
72
+ formats: defaultFormats
73
+ };
74
+ /**
75
+ * Applies `init()` options, merging custom formats over the defaults.
76
+ */
77
+ const setRuntimeOptions = (options) => {
78
+ const { formats, ...rest } = options;
79
+ Object.assign(runtimeOptions, rest);
80
+ if (formats) runtimeOptions.formats = {
81
+ number: {
82
+ ...defaultFormats.number,
83
+ ...formats.number
84
+ },
85
+ date: {
86
+ ...defaultFormats.date,
87
+ ...formats.date
88
+ },
89
+ time: {
90
+ ...defaultFormats.time,
91
+ ...formats.time
92
+ }
93
+ };
94
+ };
95
+
96
+ //#endregion
97
+ export { configDefaultLocale, configLocales, defaultFormats, runtimeOptions, setRuntimeOptions };
98
+ //# sourceMappingURL=configuration.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"configuration.mjs","names":[],"sources":["../../src/configuration.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport type { ConfigureOptions, Formats } from './types';\n\n/** svelte-i18n's built-in named formats (intl-messageformat defaults). */\nexport const defaultFormats: Formats = {\n number: {\n scientific: { notation: 'scientific' },\n engineering: { notation: 'engineering' },\n compactLong: { notation: 'compact', compactDisplay: 'long' },\n compactShort: { notation: 'compact', compactDisplay: 'short' },\n },\n date: {\n short: { month: 'numeric', day: 'numeric', year: '2-digit' },\n medium: { month: 'short', day: 'numeric', year: 'numeric' },\n long: { month: 'long', day: 'numeric', year: 'numeric' },\n full: { weekday: 'long', month: 'long', day: 'numeric', year: 'numeric' },\n },\n time: {\n short: { hour: 'numeric', minute: 'numeric' },\n medium: { hour: 'numeric', minute: 'numeric', second: 'numeric' },\n long: {\n hour: 'numeric',\n minute: 'numeric',\n second: 'numeric',\n timeZoneName: 'short',\n },\n full: {\n hour: 'numeric',\n minute: 'numeric',\n second: 'numeric',\n timeZoneName: 'short',\n },\n },\n};\n\n/** Locale used when nothing else is set: intlayer's configured default. */\nexport const configDefaultLocale = (internationalization?.defaultLocale ??\n 'en') as string;\n\n/** Locales declared in the intlayer configuration. */\nexport const configLocales = (internationalization?.locales ?? [\n configDefaultLocale,\n]) as string[];\n\n/** Options set through `init()`, read by every store. */\nexport const runtimeOptions: Omit<ConfigureOptions, 'formats'> & {\n formats: Formats;\n} = {\n fallbackLocale: configDefaultLocale,\n formats: defaultFormats,\n};\n\n/**\n * Applies `init()` options, merging custom formats over the defaults.\n */\nexport const setRuntimeOptions = (options: Partial<ConfigureOptions>): void => {\n const { formats, ...rest } = options;\n\n Object.assign(runtimeOptions, rest);\n\n if (formats) {\n runtimeOptions.formats = {\n number: { ...defaultFormats.number, ...formats.number },\n date: { ...defaultFormats.date, ...formats.date },\n time: { ...defaultFormats.time, ...formats.time },\n };\n }\n};\n"],"mappings":";;;;AAIA,MAAa,iBAA0B;CACrC,QAAQ;EACN,YAAY,EAAE,UAAU,aAAa;EACrC,aAAa,EAAE,UAAU,cAAc;EACvC,aAAa;GAAE,UAAU;GAAW,gBAAgB;EAAO;EAC3D,cAAc;GAAE,UAAU;GAAW,gBAAgB;EAAQ;CAC/D;CACA,MAAM;EACJ,OAAO;GAAE,OAAO;GAAW,KAAK;GAAW,MAAM;EAAU;EAC3D,QAAQ;GAAE,OAAO;GAAS,KAAK;GAAW,MAAM;EAAU;EAC1D,MAAM;GAAE,OAAO;GAAQ,KAAK;GAAW,MAAM;EAAU;EACvD,MAAM;GAAE,SAAS;GAAQ,OAAO;GAAQ,KAAK;GAAW,MAAM;EAAU;CAC1E;CACA,MAAM;EACJ,OAAO;GAAE,MAAM;GAAW,QAAQ;EAAU;EAC5C,QAAQ;GAAE,MAAM;GAAW,QAAQ;GAAW,QAAQ;EAAU;EAChE,MAAM;GACJ,MAAM;GACN,QAAQ;GACR,QAAQ;GACR,cAAc;EAChB;EACA,MAAM;GACJ,MAAM;GACN,QAAQ;GACR,QAAQ;GACR,cAAc;EAChB;CACF;AACF;;AAGA,MAAa,sBAAuB,sBAAsB,iBACxD;;AAGF,MAAa,gBAAiB,sBAAsB,WAAW,CAC7D,mBACF;;AAGA,MAAa,iBAET;CACF,gBAAgB;CAChB,SAAS;AACX;;;;AAKA,MAAa,qBAAqB,YAA6C;CAC7E,MAAM,EAAE,SAAS,GAAG,SAAS;CAE7B,OAAO,OAAO,gBAAgB,IAAI;CAElC,IAAI,SACF,eAAe,UAAU;EACvB,QAAQ;GAAE,GAAG,eAAe;GAAQ,GAAG,QAAQ;EAAO;EACtD,MAAM;GAAE,GAAG,eAAe;GAAM,GAAG,QAAQ;EAAK;EAChD,MAAM;GAAE,GAAG,eAAe;GAAM,GAAG,QAAQ;EAAK;CAClD;AAEJ"}
@@ -0,0 +1,49 @@
1
+ import { configDefaultLocale, runtimeOptions } from "./configuration.mjs";
2
+ import { interpolateMessage, resolveMessageNodeToString } from "@intlayer/core/messageFormat";
3
+
4
+ //#region src/createMessageFormatter.ts
5
+ /**
6
+ * Whether a looked-up value can be rendered as a message: a string, an
7
+ * interpreted callable, or an intlayer node (compiled runtime ICU) — not a
8
+ * plain subtree.
9
+ */
10
+ const isRenderableMessage = (message) => typeof message === "string" || typeof message === "function" || Array.isArray(message) || typeof message === "object" && message !== null && "nodeType" in message;
11
+ /**
12
+ * Builds the `$_` function for the active locale on top of a lookup.
13
+ *
14
+ * Resolution follows svelte-i18n: the requested locale, then the
15
+ * `fallbackLocale` from `init()`, then `handleMissingMessage`, then the
16
+ * `default` message, then the id itself. Intlayer dictionaries arrive already
17
+ * converted to nodes, so no message parser is involved here.
18
+ *
19
+ * @param activeLocale - The current `$locale` value.
20
+ * @param lookup - Where messages are read from (registry, bound dictionary…).
21
+ */
22
+ const createMessageFormatter = (activeLocale, lookup) => (idOrMessage, options) => {
23
+ const message = typeof idOrMessage === "string" ? {
24
+ ...options,
25
+ id: idOrMessage
26
+ } : {
27
+ ...options,
28
+ ...idOrMessage
29
+ };
30
+ const { id, values = {}, default: defaultMessage } = message;
31
+ const targetLocale = message.locale ?? activeLocale ?? configDefaultLocale;
32
+ const { fallbackLocale } = runtimeOptions;
33
+ const candidateLocales = fallbackLocale && fallbackLocale !== targetLocale ? [targetLocale, fallbackLocale] : [targetLocale];
34
+ for (const candidateLocale of candidateLocales) {
35
+ const content = lookup(id, candidateLocale);
36
+ if (isRenderableMessage(content)) return resolveMessageNodeToString(content, values, candidateLocale);
37
+ }
38
+ const handledMessage = runtimeOptions.handleMissingMessage?.({
39
+ locale: targetLocale,
40
+ id,
41
+ defaultValue: defaultMessage
42
+ });
43
+ if (typeof handledMessage === "string") return handledMessage;
44
+ return defaultMessage === void 0 ? id : interpolateMessage(defaultMessage, values, targetLocale);
45
+ };
46
+
47
+ //#endregion
48
+ export { createMessageFormatter };
49
+ //# sourceMappingURL=createMessageFormatter.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createMessageFormatter.mjs","names":[],"sources":["../../src/createMessageFormatter.ts"],"sourcesContent":["import {\n interpolateMessage,\n resolveMessageNodeToString,\n} from '@intlayer/core/messageFormat';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { configDefaultLocale, runtimeOptions } from './configuration';\nimport type { MessageFormatter, MessageObject } from './types';\n\n/** Reads the raw message (string, node or subtree) of an id for a locale. */\nexport type MessageLookup = (id: string, locale: string) => unknown;\n\n/**\n * Whether a looked-up value can be rendered as a message: a string, an\n * interpreted callable, or an intlayer node (compiled runtime ICU) — not a\n * plain subtree.\n */\nconst isRenderableMessage = (message: unknown): boolean =>\n typeof message === 'string' ||\n typeof message === 'function' ||\n Array.isArray(message) ||\n (typeof message === 'object' && message !== null && 'nodeType' in message);\n\n/**\n * Builds the `$_` function for the active locale on top of a lookup.\n *\n * Resolution follows svelte-i18n: the requested locale, then the\n * `fallbackLocale` from `init()`, then `handleMissingMessage`, then the\n * `default` message, then the id itself. Intlayer dictionaries arrive already\n * converted to nodes, so no message parser is involved here.\n *\n * @param activeLocale - The current `$locale` value.\n * @param lookup - Where messages are read from (registry, bound dictionary…).\n */\nexport const createMessageFormatter =\n (\n activeLocale: string | null | undefined,\n lookup: MessageLookup\n ): MessageFormatter =>\n (idOrMessage: string | MessageObject, options?: Omit<MessageObject, 'id'>) => {\n const message: MessageObject =\n typeof idOrMessage === 'string'\n ? { ...options, id: idOrMessage }\n : { ...options, ...idOrMessage };\n\n const { id, values = {}, default: defaultMessage } = message;\n const targetLocale = message.locale ?? activeLocale ?? configDefaultLocale;\n const { fallbackLocale } = runtimeOptions;\n\n const candidateLocales =\n fallbackLocale && fallbackLocale !== targetLocale\n ? [targetLocale, fallbackLocale]\n : [targetLocale];\n\n for (const candidateLocale of candidateLocales) {\n const content = lookup(id, candidateLocale);\n\n if (isRenderableMessage(content)) {\n return resolveMessageNodeToString(\n content,\n values,\n candidateLocale as LocalesValues\n );\n }\n }\n\n const handledMessage = runtimeOptions.handleMissingMessage?.({\n locale: targetLocale,\n id,\n defaultValue: defaultMessage,\n });\n if (typeof handledMessage === 'string') return handledMessage;\n\n return defaultMessage === undefined\n ? id\n : interpolateMessage(\n defaultMessage,\n values,\n targetLocale as LocalesValues\n );\n };\n"],"mappings":";;;;;;;;;AAgBA,MAAM,uBAAuB,YAC3B,OAAO,YAAY,YACnB,OAAO,YAAY,cACnB,MAAM,QAAQ,OAAO,KACpB,OAAO,YAAY,YAAY,YAAY,QAAQ,cAAc;;;;;;;;;;;;AAapE,MAAa,0BAET,cACA,YAED,aAAqC,YAAwC;CAC5E,MAAM,UACJ,OAAO,gBAAgB,WACnB;EAAE,GAAG;EAAS,IAAI;CAAY,IAC9B;EAAE,GAAG;EAAS,GAAG;CAAY;CAEnC,MAAM,EAAE,IAAI,SAAS,CAAC,GAAG,SAAS,mBAAmB;CACrD,MAAM,eAAe,QAAQ,UAAU,gBAAgB;CACvD,MAAM,EAAE,mBAAmB;CAE3B,MAAM,mBACJ,kBAAkB,mBAAmB,eACjC,CAAC,cAAc,cAAc,IAC7B,CAAC,YAAY;CAEnB,KAAK,MAAM,mBAAmB,kBAAkB;EAC9C,MAAM,UAAU,OAAO,IAAI,eAAe;EAE1C,IAAI,oBAAoB,OAAO,GAC7B,OAAO,2BACL,SACA,QACA,eACF;CAEJ;CAEA,MAAM,iBAAiB,eAAe,uBAAuB;EAC3D,QAAQ;EACR;EACA,cAAc;CAChB,CAAC;CACD,IAAI,OAAO,mBAAmB,UAAU,OAAO;CAE/C,OAAO,mBAAmB,SACtB,KACA,mBACE,gBACA,QACA,YACF;AACN"}
@@ -0,0 +1,53 @@
1
+ import { configDefaultLocale, runtimeOptions } from "./configuration.mjs";
2
+
3
+ //#region src/formatters.ts
4
+ const numberFormatters = /* @__PURE__ */ new Map();
5
+ const dateTimeFormatters = /* @__PURE__ */ new Map();
6
+ /** Cache key of one formatter: locale plus its serialised options. */
7
+ const toCacheKey = (locale, options) => `${locale}|${JSON.stringify(options)}`;
8
+ /**
9
+ * Splits svelte-i18n formatter options into the target locale and the `Intl`
10
+ * options, expanding a named `format` preset from `runtimeOptions.formats`.
11
+ */
12
+ const resolveIntlOptions = (options, presets, defaultFormat) => {
13
+ const { format: formatName = defaultFormat, locale = configDefaultLocale, ...intlOptions } = options ?? {};
14
+ const preset = formatName ? presets[formatName] : void 0;
15
+ if (formatName && !preset) throw new Error(`[svelte-i18n] Unknown format "${formatName}"`);
16
+ return {
17
+ locale,
18
+ intlOptions: {
19
+ ...preset,
20
+ ...intlOptions
21
+ }
22
+ };
23
+ };
24
+ /** Memoized `Intl.NumberFormat` honouring named `number` formats. */
25
+ const getNumberFormatter = (options) => {
26
+ const { locale, intlOptions } = resolveIntlOptions(options, runtimeOptions.formats.number);
27
+ const cacheKey = toCacheKey(locale, intlOptions);
28
+ let formatter = numberFormatters.get(cacheKey);
29
+ if (!formatter) {
30
+ formatter = new Intl.NumberFormat(locale, intlOptions);
31
+ numberFormatters.set(cacheKey, formatter);
32
+ }
33
+ return formatter;
34
+ };
35
+ const createDateTimeFormatterFactory = (kind, defaultFormat) => (options) => {
36
+ const hasExplicitFields = options !== void 0 && Object.keys(options).some((key) => key !== "locale" && key !== "format");
37
+ const { locale, intlOptions } = resolveIntlOptions(options, runtimeOptions.formats[kind], hasExplicitFields ? void 0 : defaultFormat);
38
+ const cacheKey = toCacheKey(`${kind}:${locale}`, intlOptions);
39
+ let formatter = dateTimeFormatters.get(cacheKey);
40
+ if (!formatter) {
41
+ formatter = new Intl.DateTimeFormat(locale, intlOptions);
42
+ dateTimeFormatters.set(cacheKey, formatter);
43
+ }
44
+ return formatter;
45
+ };
46
+ /** Memoized `Intl.DateTimeFormat` honouring named `date` formats. */
47
+ const getDateFormatter = createDateTimeFormatterFactory("date", "short");
48
+ /** Memoized `Intl.DateTimeFormat` honouring named `time` formats. */
49
+ const getTimeFormatter = createDateTimeFormatterFactory("time", "short");
50
+
51
+ //#endregion
52
+ export { getDateFormatter, getNumberFormatter, getTimeFormatter };
53
+ //# sourceMappingURL=formatters.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formatters.mjs","names":[],"sources":["../../src/formatters.ts"],"sourcesContent":["import { configDefaultLocale, runtimeOptions } from './configuration';\nimport type {\n IntlFormatterOptions,\n MemoizedDateTimeFormatterFactoryOptional,\n MemoizedNumberFormatterFactoryOptional,\n} from './types';\n\nconst numberFormatters = new Map<string, Intl.NumberFormat>();\nconst dateTimeFormatters = new Map<string, Intl.DateTimeFormat>();\n\n/** Cache key of one formatter: locale plus its serialised options. */\nconst toCacheKey = (locale: string, options: object): string =>\n `${locale}|${JSON.stringify(options)}`;\n\n/**\n * Splits svelte-i18n formatter options into the target locale and the `Intl`\n * options, expanding a named `format` preset from `runtimeOptions.formats`.\n */\nconst resolveIntlOptions = <T extends object>(\n options: IntlFormatterOptions<T> | undefined,\n presets: Record<string, T>,\n defaultFormat?: string\n): { locale: string; intlOptions: T } => {\n const {\n format: formatName = defaultFormat,\n locale = configDefaultLocale,\n ...intlOptions\n } = options ?? ({} as IntlFormatterOptions<T>);\n\n const preset = formatName ? presets[formatName] : undefined;\n\n if (formatName && !preset) {\n throw new Error(`[svelte-i18n] Unknown format \"${formatName}\"`);\n }\n\n return {\n locale,\n intlOptions: { ...preset, ...(intlOptions as T) },\n };\n};\n\n/** Memoized `Intl.NumberFormat` honouring named `number` formats. */\nexport const getNumberFormatter: MemoizedNumberFormatterFactoryOptional = (\n options\n) => {\n const { locale, intlOptions } = resolveIntlOptions(\n options,\n runtimeOptions.formats.number\n );\n const cacheKey = toCacheKey(locale, intlOptions);\n\n let formatter = numberFormatters.get(cacheKey);\n if (!formatter) {\n formatter = new Intl.NumberFormat(locale, intlOptions);\n numberFormatters.set(cacheKey, formatter);\n }\n return formatter;\n};\n\nconst createDateTimeFormatterFactory =\n (\n kind: 'date' | 'time',\n defaultFormat: string\n ): MemoizedDateTimeFormatterFactoryOptional =>\n (options) => {\n // Explicit Intl fields replace the default preset, like svelte-i18n.\n const hasExplicitFields =\n options !== undefined &&\n Object.keys(options).some((key) => key !== 'locale' && key !== 'format');\n\n const { locale, intlOptions } = resolveIntlOptions(\n options,\n runtimeOptions.formats[kind],\n hasExplicitFields ? undefined : defaultFormat\n );\n const cacheKey = toCacheKey(`${kind}:${locale}`, intlOptions);\n\n let formatter = dateTimeFormatters.get(cacheKey);\n if (!formatter) {\n formatter = new Intl.DateTimeFormat(locale, intlOptions);\n dateTimeFormatters.set(cacheKey, formatter);\n }\n return formatter;\n };\n\n/** Memoized `Intl.DateTimeFormat` honouring named `date` formats. */\nexport const getDateFormatter = createDateTimeFormatterFactory('date', 'short');\n\n/** Memoized `Intl.DateTimeFormat` honouring named `time` formats. */\nexport const getTimeFormatter = createDateTimeFormatterFactory('time', 'short');\n"],"mappings":";;;AAOA,MAAM,mCAAmB,IAAI,IAA+B;AAC5D,MAAM,qCAAqB,IAAI,IAAiC;;AAGhE,MAAM,cAAc,QAAgB,YAClC,GAAG,OAAO,GAAG,KAAK,UAAU,OAAO;;;;;AAMrC,MAAM,sBACJ,SACA,SACA,kBACuC;CACvC,MAAM,EACJ,QAAQ,aAAa,eACrB,SAAS,qBACT,GAAG,gBACD,WAAY,CAAC;CAEjB,MAAM,SAAS,aAAa,QAAQ,cAAc;CAElD,IAAI,cAAc,CAAC,QACjB,MAAM,IAAI,MAAM,iCAAiC,WAAW,EAAE;CAGhE,OAAO;EACL;EACA,aAAa;GAAE,GAAG;GAAQ,GAAI;EAAkB;CAClD;AACF;;AAGA,MAAa,sBACX,YACG;CACH,MAAM,EAAE,QAAQ,gBAAgB,mBAC9B,SACA,eAAe,QAAQ,MACzB;CACA,MAAM,WAAW,WAAW,QAAQ,WAAW;CAE/C,IAAI,YAAY,iBAAiB,IAAI,QAAQ;CAC7C,IAAI,CAAC,WAAW;EACd,YAAY,IAAI,KAAK,aAAa,QAAQ,WAAW;EACrD,iBAAiB,IAAI,UAAU,SAAS;CAC1C;CACA,OAAO;AACT;AAEA,MAAM,kCAEF,MACA,mBAED,YAAY;CAEX,MAAM,oBACJ,YAAY,UACZ,OAAO,KAAK,OAAO,CAAC,CAAC,MAAM,QAAQ,QAAQ,YAAY,QAAQ,QAAQ;CAEzE,MAAM,EAAE,QAAQ,gBAAgB,mBAC9B,SACA,eAAe,QAAQ,OACvB,oBAAoB,SAAY,aAClC;CACA,MAAM,WAAW,WAAW,GAAG,KAAK,GAAG,UAAU,WAAW;CAE5D,IAAI,YAAY,mBAAmB,IAAI,QAAQ;CAC/C,IAAI,CAAC,WAAW;EACd,YAAY,IAAI,KAAK,eAAe,QAAQ,WAAW;EACvD,mBAAmB,IAAI,UAAU,SAAS;CAC5C;CACA,OAAO;AACT;;AAGF,MAAa,mBAAmB,+BAA+B,QAAQ,OAAO;;AAG9E,MAAa,mBAAmB,+BAA+B,QAAQ,OAAO"}