@intlayer/sync-json-plugin 7.0.0-canary.2

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 ADDED
@@ -0,0 +1,276 @@
1
+ <p align="center">
2
+ <a href="https://intlayer.org" rel="">
3
+ <img src="https://raw.githubusercontent.com/aymericzip/intlayer/main/docs/assets/cover.png" width="60%" alt="Intlayer Logo" />
4
+ </a>
5
+ </p>
6
+
7
+ <h1 align="center">
8
+ <strong> Intlayer : an Open-source, per-component i18n toolkit with AI-powered translation & CMS.</strong>
9
+ </h1>
10
+
11
+ <br />
12
+
13
+ <p align="center">
14
+ <a href="https://intlayer.org/doc/concept/content" rel="">Docs</a> •
15
+ <a href="https://intlayer.org/doc/environment/nextjs" rel="">Next.js</a> •
16
+ <a href="https://intlayer.org/doc/environment/vite-and-react" rel="">React + Vite</a> •
17
+ <a href="https://intlayer.org/doc/concept/cms" rel="">CMS</a> •
18
+ <a href="https://discord.gg/7uxamYVeCk" rel="noopener noreferrer nofollow">Discord</a>
19
+ </p>
20
+ <p align="center" style="margin-top:15px;">
21
+ <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>
22
+ <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>
23
+ <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" alt="monthly downloads" height="24"/></a>
24
+ <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" alt="license"/></a>
25
+ <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" alt="last commit"/>
26
+ </a>
27
+ </p>
28
+
29
+ ![Watch the video](https://github.com/aymericzip/intlayer/blob/main/docs/assets/demo_video.gif)
30
+
31
+ <a href="https://intlayer.org/doc/concept/content" rel="">
32
+ <img src="https://img.shields.io/badge/Get_Started-FFFFFF?style=for-the-badge&logo=rocket&logoColor=black" />
33
+ </a>
34
+
35
+ ## What is Intlayer?
36
+
37
+ Most i18n libraries are either too complex, too rigid, or not built for modern frameworks.
38
+
39
+ Intlayer is a **modern i18n solution** for web and mobile apps.
40
+ It’s framework-agnostic, **AI-powered**, and includes a free **CMS & visual editor**.
41
+
42
+ With **per-locale content files**, **TypeScript autocompletion**, **tree-shakable dictionaries**, and **CI/CD integration**, Intlayer makes internationalization **faster, cleaner, and smarter**.
43
+
44
+ ## Keys benefits of Intlayer:
45
+
46
+ | Feature | Description |
47
+ | --------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
48
+ | <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/frameworks.png?raw=true" alt="Feature" width="700"> | **Cross-Frameworks Support**<br><br>Intlayer is compatible with all major frameworks and libraries, including Next.js, React, Vite, Vue.js, Nuxt, Preact, Express, and more. |
49
+ | <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/javascript_content_management.png?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) |
50
+ | <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) |
51
+ | <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) |
52
+ | <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) |
53
+ | <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) |
54
+ | <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) |
55
+ | <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) |
56
+ | <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) |
57
+ | <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) |
58
+ | <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/visual_editor.png?raw=true" alt="Feature" width="700"> | **Free Visual Editor & CMS**<br><br>A free visual editor and CMS are available for content writers, removing the need for a localization platform. Keep your content synchronized using Git, or externalize it totally or partially with the CMS.<br><br> - [Intlayer Editor](https://intlayer.org/doc/concept/editor) <br> - [Intlayer CMS](https://intlayer.org/doc/concept/cms) |
59
+ | <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/bundle.png?raw=true" alt="Feature" width="700"> | **Tree-shakable Content**<br><br>Tree-shakable content, reducing the size of the final bundle. Loads content per component, excluding any unused content from your bundle. Supports lazy loading to enhance app loading efficiency. <br><br> - [App build optimization](https://intlayer.org/doc/concept/how-works-intlayer#app-build-optimization) |
60
+ | <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/static_rendering.png?raw=true" alt="Feature" width="700"> | **Static Rendering**<br><br>Doesn't block Static Rendering. <br><br> - [Next.js integration](https://intlayer.org/doc/environment/nextjs) |
61
+ | <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) |
62
+ | <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) |
63
+ | <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/vscode_extension.png?raw=true" alt="Feature" width="700"> | **VSCode Extension**<br><br>Intlayer provides a VSCode extension to help you manage your content and translations, builting your dictionaries, translating your content, and more. <br><br> - [VSCode Extension](https://intlayer.org/doc/vs-code-extension) |
64
+ | <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, and react-intl. <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) |
65
+
66
+ ---
67
+
68
+ ## 📦 Installation
69
+
70
+ Start your journey with Intlayer today and experience a smoother, more powerful approach to internationalization.
71
+
72
+ <a href="https://intlayer.org/doc/concept/content" rel="">
73
+ <img src="https://img.shields.io/badge/Get_Started-FFFFFF?style=for-the-badge&logo=rocket&logoColor=black" />
74
+ </a>
75
+
76
+ ```bash
77
+ npm install intlayer react-intlayer
78
+ ```
79
+
80
+ ⚡ Quick Start (Next.js)
81
+
82
+ ```ts
83
+ // intlayer.config.ts
84
+ import { Locales, type IntlayerConfig } from "intlayer";
85
+
86
+ const config: IntlayerConfig = {
87
+ internationalization: {
88
+ locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH],
89
+ defaultLocale: Locales.ENGLISH,
90
+ },
91
+ };
92
+
93
+ export default config;
94
+ ```
95
+
96
+ ```ts
97
+ // app/home.content.ts
98
+ import { t, type Dictionary } from "intlayer";
99
+
100
+ const content = {
101
+ key: "home",
102
+ content: {
103
+ title: t({
104
+ en: "Home",
105
+ fr: "Accueil",
106
+ es: "Inicio",
107
+ }),
108
+ },
109
+ } satisfies Dictionary;
110
+
111
+ export default content;
112
+ ```
113
+
114
+ ```tsx
115
+ // app/page.tsx
116
+ import { useIntlayer } from "react-intlayer";
117
+
118
+ const HomePage = () => {
119
+ const { title } = useIntlayer("home");
120
+
121
+ return <h1>{title}</h1>;
122
+ };
123
+ ```
124
+
125
+ <a href="https://intlayer.org/doc/environment/nextjs"> Get the full guide → </a>
126
+
127
+ ## 🎥 Live tutorial on YouTube
128
+
129
+ [![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)
130
+
131
+ <a href="https://intlayer.org/doc/concept/content" rel="">
132
+ <img src="https://img.shields.io/badge/Get_Started-FFFFFF?style=for-the-badge&logo=rocket&logoColor=black" />
133
+ </a>
134
+
135
+ ## Table of Contents
136
+
137
+ Explore our comprehensive documentation to get started with Intlayer and learn how to integrate it into your projects.
138
+
139
+ <details open>
140
+ <summary style="font-size:16px; font-weight:bold;">📘 Get Started</summary>
141
+ <ul>
142
+ <li><a href="https://intlayer.org/doc/why" rel=''>Why Intlayer?</a></li>
143
+ <li><a href="https://intlayer.org/doc" rel=''>Introduction</a></li>
144
+ </ul>
145
+ </details>
146
+
147
+ <details>
148
+ <summary style="font-size:16px; font-weight:bold;">⚙️ Concept</summary>
149
+ <ul>
150
+ <li><a href="https://intlayer.org/doc/concept/how-works-intlayer" rel=''>How Intlayer Works</a></li>
151
+ <li><a href="https://intlayer.org/doc/concept/configuration" rel=''>Configuration</a></li>
152
+ <li><a href="https://intlayer.org/doc/concept/cli" rel=''>Intlayer CLI</a></li>
153
+ <li><a href="https://intlayer.org/doc/concept/editor" rel=''>Intlayer Editor</a></li>
154
+ <li><a href="https://intlayer.org/doc/concept/cms" rel=''>Intlayer CMS</a></li>
155
+ <li><a href="https://intlayer.org/doc/concept/content" rel=''>Dictionary</a>
156
+ <ul>
157
+ <li><a href="https://intlayer.org/doc/concept/content/per-locale-file" rel=''>Per-Locale Content Declaration File</a></li>
158
+ <li><a href="https://intlayer.org/doc/concept/content/translation" rel=''>Translation</a></li>
159
+ <li><a href="https://intlayer.org/doc/concept/content/enumeration" rel=''>Enumeration</a></li>
160
+ <li><a href="https://intlayer.org/doc/concept/content/condition" rel=''>Condition</a></li>
161
+ <li><a href="https://intlayer.org/doc/concept/content/nesting" rel=''>Nesting</a></li>
162
+ <li><a href="https://intlayer.org/doc/concept/content/markdown" rel=''>Markdown</a></li>
163
+ <li><a href="https://intlayer.org/doc/concept/content/function-fetching" rel=''>Function Fetching</a></li>
164
+ <li><a href="https://intlayer.org/doc/concept/content/insertion" rel=''>Insertion</a></li>
165
+ <li><a href="https://intlayer.org/doc/concept/content/file" rel=''>File</a></li>
166
+ </ul>
167
+ </li>
168
+ </ul>
169
+ </details>
170
+
171
+ <details open>
172
+ <summary style="font-size:16px; font-weight:bold;">🌐 Environment</summary>
173
+ <ul>
174
+ <li><a href="https://intlayer.org/doc/environment/nextjs" rel=''>Intlayer with Next.js 15</a>
175
+ <ul>
176
+ <li><a href="https://intlayer.org/doc/environment/nextjs/14" rel=''>Next.js 14 (App Router)</a></li>
177
+ <li><a href="https://intlayer.org/doc/environment/nextjs/next-with-Page-Router" rel=''>Next.js Page Router</a></li>
178
+ </ul>
179
+ </li>
180
+ <li><a href="https://intlayer.org/doc/environment/create-react-app" rel=''>React CRA</a></li>
181
+ <li><a href="https://intlayer.org/doc/environment/vite-and-react" rel=''>Vite + React</a>
182
+ <ul>
183
+ <li><a href="https://intlayer.org/doc/environment/vite-and-react/react-router-v7" rel=''>React-router-v7</a></li>
184
+ <li><a href="https://intlayer.org/doc/environment/vite-and-react/tanstack-start" rel=''>Tanstack start</a></li>
185
+ </ul>
186
+ </li>
187
+ <li><a href="https://intlayer.org/doc/environment/react-native-and-expo" rel=''>React Native</a></li>
188
+ <li><a href="https://intlayer.org/doc/environment/lynx-and-react" rel=''>Lynx + React</a></li>
189
+ <li><a href="https://intlayer.org/doc/environment/vite-and-svelte" rel=''>Vite + Svelte</a></li>
190
+ <li><a href="https://intlayer.org/doc/environment/vite-and-preact" rel=''>Vite + Preact</a></li>
191
+ <li><a href="https://intlayer.org/doc/environment/vite-and-vue" rel=''>Vite + Vue</a></li>
192
+ <li><a href="https://intlayer.org/doc/environment/vite-and-nuxt" rel=''>Vite + Nuxt</a></li>
193
+ <li><a href="https://intlayer.org/doc/environment/vite-and-solid" rel=''>Vite + Solid</a></li>
194
+ <li><a href="https://intlayer.org/doc/environment/angular" rel=''>Angular</a></li>
195
+ <li><a href="https://intlayer.org/doc/environment/express" rel=''>Express</a></li>
196
+ <li><a href="https://intlayer.org/doc/environment/nest" rel=''>NestJS</a></li>
197
+ </ul>
198
+ </details>
199
+
200
+ <details>
201
+ <summary style="font-size:16px; font-weight:bold;">📰 Blog</summary>
202
+ <ul>
203
+ <li><a href="https://github.com/aymericzip/intlayer/blob/main/docs/blog/en/what_is_internationalization.md" rel=''>What is i18n</a></li>
204
+ <li><a href="https://intlayer.org/blog/SEO-and-i18n" rel=''>i18n and SEO</a></li>
205
+ <li><a href="https://intlayer.org/blog/intlayer-with-next-i18next" rel=''>Intlayer and i18next</a></li>
206
+ <li><a href="https://intlayer.org/blog/intlayer-with-react-i18next" rel=''>Intlayer and react-intl</a></li>
207
+ <li><a href="https://intlayer.org/blog/intlayer-with-next-intl" rel=''>Intlayer and next-intl</a></li>
208
+ </ul>
209
+ </details>
210
+
211
+ ## 🌐 Readme in other languages
212
+
213
+ <p align="center">
214
+ <a href="https://github.com/aymericzip/intlayer/blob/main/readme.md">English</a> •
215
+ <a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/zh/readme.md">简体中文</a> •
216
+ <a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/ru/readme.md">Русский</a> •
217
+ <a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/ja/readme.md">日本語</a> •
218
+ <a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/fr/readme.md">Français</a> •
219
+ <a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/ko/readme.md">한국어</a> •
220
+ <a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/es/readme.md">Español</a> •
221
+ <a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/de/readme.md">Deutsch</a> •
222
+ <a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/ar/readme.md">العربية</a> •
223
+ <a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/it/readme.md">Italiano</a> •
224
+ <a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/en-GB/readme.md">English (UK)</a> •
225
+ <a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/pt/readme.md">Português</a> •
226
+ <a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/hi/readme.md">हिन्दी</a> •
227
+ <a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/tr/readme.md">Türkçe</a>
228
+ </p>
229
+
230
+ ## 🤝 Community
231
+
232
+ Intlayer is built with and for the community and we’d love your input!
233
+
234
+ - Have a suggestion? [Open an issue](https://github.com/aymericzip/intlayer/issues)
235
+ - Found a bug or improvement? [Submit a PR](https://github.com/aymericzip/intlayer/pulls)
236
+ - Need help or want to connect? [Join our Discord](https://discord.gg/7uxamYVeCk)
237
+
238
+ You can also follow us on :
239
+
240
+ <div>
241
+ <br/>
242
+ <p align="center">
243
+ <a href="https://discord.gg/528mBV4N" target="blank" rel='noopener noreferrer nofollow'><img align="center"
244
+ src="https://img.shields.io/badge/discord-5865F2.svg?style=for-the-badge&logo=discord&logoColor=white"
245
+ alt="Intlayer Discord" height="30"/></a>
246
+ <a href="https://www.linkedin.com/company/intlayerorg" target="blank" rel='noopener noreferrer nofollow'><img align="center"
247
+ src="https://img.shields.io/badge/linkedin-%231DA1F2.svg?style=for-the-badge&logo=linkedin&logoColor=white"
248
+ alt="Intlayer LinkedIn" height="30"/></a>
249
+ <a href="https://www.facebook.com/intlayer" target="blank" rel='noopener noreferrer nofollow'><img align="center"
250
+ src="https://img.shields.io/badge/facebook-4267B2.svg?style=for-the-badge&logo=facebook&logoColor=white"
251
+ alt="Intlayer Facebook" height="30"/></a>
252
+ <a href="https://www.instagram.com/intlayer/" target="blank" rel='noopener noreferrer nofollow'><img align="center"
253
+ src="https://img.shields.io/badge/instagram-%23E4405F.svg?style=for-the-badge&logo=Instagram&logoColor=white"
254
+ alt="Intlayer Instagram" height="30"/></a>
255
+ <a href="https://x.com/Intlayer183096" target="blank" rel='noopener noreferrer nofollow'><img align="center"
256
+ src="https://img.shields.io/badge/x-1DA1F2.svg?style=for-the-badge&logo=x&logoColor=white"
257
+ alt="Intlayer X" height="30"/></a>
258
+ <a href="https://www.youtube.com/@intlayer" target="blank" rel='noopener noreferrer nofollow'><img align="center"
259
+ src="https://img.shields.io/badge/youtube-FF0000.svg?style=for-the-badge&logo=youtube&logoColor=white"
260
+ alt="Intlayer YouTube" height="30"/></a>
261
+ <a href="https://www.tiktok.com/@intlayer" target="blank" rel='noopener noreferrer nofollow'><img align="center"
262
+ src="https://img.shields.io/badge/tiktok-000000.svg?style=for-the-badge&logo=tiktok&logoColor=white"
263
+ alt="Intlayer TikTok" height="30"/></a>
264
+ <br>
265
+ </p>
266
+ </div>
267
+
268
+ ### Contribution
269
+
270
+ 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!
271
+
272
+ ### Thank You for the Support
273
+
274
+ 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-).
275
+
276
+ [![Star History Chart](https://api.star-history.com/svg?repos=aymericzip/intlayer&type=Date)](https://star-history.com/#aymericzip/intlayer&Date)
@@ -0,0 +1,25 @@
1
+ //#region rolldown:runtime
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") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
22
+
23
+ //#endregion
24
+
25
+ exports.__toESM = __toESM;
@@ -0,0 +1,132 @@
1
+ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
2
+ let node_fs_promises = require("node:fs/promises");
3
+ node_fs_promises = require_rolldown_runtime.__toESM(node_fs_promises);
4
+ let node_path = require("node:path");
5
+ node_path = require_rolldown_runtime.__toESM(node_path);
6
+ let __intlayer_chokidar = require("@intlayer/chokidar");
7
+ __intlayer_chokidar = require_rolldown_runtime.__toESM(__intlayer_chokidar);
8
+ let fast_glob = require("fast-glob");
9
+ fast_glob = require_rolldown_runtime.__toESM(fast_glob);
10
+
11
+ //#region src/index.ts
12
+ const escapeRegex = (str) => str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
13
+ const extractKeyAndLocaleFromPath = (filePath, maskPattern, locales) => {
14
+ const keyPlaceholder = "{{__KEY__}}";
15
+ const localePlaceholder = "{{__LOCALE__}}";
16
+ const escapedMask = escapeRegex(maskPattern);
17
+ const localesAlternation = locales.join("|");
18
+ let regexStr = `^${escapedMask}$`;
19
+ regexStr = regexStr.replace(escapeRegex(localePlaceholder), `(?<locale>${localesAlternation})`);
20
+ if (maskPattern.includes(keyPlaceholder)) regexStr = regexStr.replace(escapeRegex(keyPlaceholder), "(?<key>[^/]+)");
21
+ const match = new RegExp(regexStr).exec(filePath);
22
+ let locale;
23
+ let key;
24
+ if (match?.groups) {
25
+ locale = match.groups.locale;
26
+ key = match.groups.key ?? "index";
27
+ }
28
+ return {
29
+ key,
30
+ locale
31
+ };
32
+ };
33
+ const listMessages = (builder, configuration) => {
34
+ const { content, internationalization } = configuration;
35
+ const baseDir = content.baseDir;
36
+ const locales = internationalization.locales;
37
+ const globPattern = builder({
38
+ key: "*",
39
+ locale: `{${locales.map((locale) => locale).join(",")}}`
40
+ });
41
+ const maskPattern = builder({
42
+ key: "{{__KEY__}}",
43
+ locale: "{{__LOCALE__}}"
44
+ });
45
+ const files = fast_glob.default.sync(globPattern, { cwd: baseDir });
46
+ const result = {};
47
+ for (const file of files) {
48
+ const { key, locale } = extractKeyAndLocaleFromPath(file, maskPattern, locales);
49
+ const absolutePath = (0, node_path.isAbsolute)(file) ? file : (0, node_path.resolve)(baseDir, file);
50
+ if (!result[locale]) result[locale] = {};
51
+ result[locale][key] = absolutePath;
52
+ }
53
+ return result;
54
+ };
55
+ const loadMessagePathMap = (source, configuration) => {
56
+ const messages = listMessages(source, configuration);
57
+ return Object.entries(messages).flatMap(([locale, keysRecord]) => Object.entries(keysRecord).map(([key, path]) => {
58
+ return {
59
+ path: (0, node_path.isAbsolute)(path) ? path : (0, node_path.resolve)(configuration.content.baseDir, path),
60
+ locale,
61
+ key
62
+ };
63
+ }));
64
+ };
65
+ const syncJSON = (options) => {
66
+ const { location, priority } = {
67
+ location: "plugin",
68
+ priority: 0,
69
+ ...options
70
+ };
71
+ return {
72
+ name: "sync-json",
73
+ loadDictionaries: async ({ configuration }) => {
74
+ const dictionariesMap = loadMessagePathMap(options.source, configuration);
75
+ let fill = options.source({
76
+ key: "{{key}}",
77
+ locale: "{{locale}}"
78
+ });
79
+ if (fill && !(0, node_path.isAbsolute)(fill)) fill = (0, node_path.join)(configuration.content.baseDir, fill);
80
+ const dictionaries = [];
81
+ for (const { locale, path, key } of dictionariesMap) {
82
+ const json = configuration.build.require(path);
83
+ const filePath = (0, node_path.relative)(configuration.content.baseDir, path);
84
+ const dictionary = {
85
+ key,
86
+ locale,
87
+ fill,
88
+ localId: `${key}::${location}::${filePath}`,
89
+ location,
90
+ filled: locale !== configuration.internationalization.defaultLocale ? true : void 0,
91
+ content: json,
92
+ filePath,
93
+ priority
94
+ };
95
+ dictionaries.push(dictionary);
96
+ }
97
+ return dictionaries;
98
+ },
99
+ afterBuild: async ({ dictionaries, configuration }) => {
100
+ const { getLocalizedContent } = await import("@intlayer/core");
101
+ const locales = configuration.internationalization.locales;
102
+ await (0, __intlayer_chokidar.parallelize)(Object.entries(dictionaries.mergedDictionaries).flatMap(([key, dictionary]) => locales.map((locale) => ({
103
+ key,
104
+ dictionary: dictionary.dictionary,
105
+ locale
106
+ }))), async ({ key, dictionary, locale }) => {
107
+ const builderPath = options.source({
108
+ key,
109
+ locale
110
+ });
111
+ const localizedContent = getLocalizedContent(JSON.parse(JSON.stringify(dictionary.content)), locale, {
112
+ dictionaryKey: key,
113
+ keyPath: []
114
+ });
115
+ await (0, node_fs_promises.mkdir)((0, node_path.dirname)(builderPath), { recursive: true });
116
+ await (0, node_fs_promises.writeFile)(builderPath, `${JSON.stringify(localizedContent, null, 2)}\n`, "utf-8");
117
+ });
118
+ },
119
+ formatOutput: ({ dictionary }) => {
120
+ if (!dictionary.filePath || !dictionary.locale) return dictionary;
121
+ if ((0, node_path.resolve)(options.source({
122
+ key: dictionary.key,
123
+ locale: dictionary.locale
124
+ })) !== (0, node_path.resolve)(dictionary.filePath)) return dictionary;
125
+ return dictionary.content;
126
+ }
127
+ };
128
+ };
129
+
130
+ //#endregion
131
+ exports.syncJSON = syncJSON;
132
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","names":["locale: Locale | undefined","key: string | undefined","fg","result: MessagesRecord","messages: MessagesRecord","dictionariesMap: DictionariesMap","fill: string","dictionaries: Dictionary[]","json: JSONContent","dictionary: Dictionary"],"sources":["../../src/index.ts"],"sourcesContent":["import { mkdir, writeFile } from 'node:fs/promises';\nimport { dirname, isAbsolute, join, relative, resolve } from 'node:path';\nimport { parallelize } from '@intlayer/chokidar';\nimport type {\n ContentNode,\n Dictionary,\n IntlayerConfig,\n LocalDictionaryId,\n Locale,\n LocalesValues,\n Plugin,\n} from '@intlayer/types';\nimport fg from 'fast-glob';\n\ntype JSONContent = Record<string, any>;\n\ntype Builder = ({\n key,\n locale,\n}: {\n key: string;\n locale: LocalesValues | (string & {});\n}) => string;\n\ntype MessagesRecord = Record<Locale, Record<Dictionary['key'], FilePath>>;\n\nconst escapeRegex = (str: string) => str.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n\nconst extractKeyAndLocaleFromPath = (\n filePath: string,\n maskPattern: string,\n locales: Locale[]\n) => {\n const keyPlaceholder = '{{__KEY__}}';\n const localePlaceholder = '{{__LOCALE__}}';\n\n const escapedMask = escapeRegex(maskPattern);\n const localesAlternation = locales.join('|');\n\n // Build a regex from the mask to capture locale (and key if present)\n let regexStr = `^${escapedMask}$`;\n\n regexStr = regexStr.replace(\n escapeRegex(localePlaceholder),\n `(?<locale>${localesAlternation})`\n );\n\n if (maskPattern.includes(keyPlaceholder)) {\n regexStr = regexStr.replace(escapeRegex(keyPlaceholder), '(?<key>[^/]+)');\n }\n\n const maskRegex = new RegExp(regexStr);\n\n const match = maskRegex.exec(filePath);\n\n let locale: Locale | undefined;\n let key: string | undefined;\n\n if (match?.groups) {\n locale = match.groups.locale as Locale | undefined;\n key = (match.groups.key as string | undefined) ?? 'index';\n }\n\n return {\n key,\n locale,\n };\n};\n\nconst listMessages = (\n builder: Builder,\n configuration: IntlayerConfig\n): MessagesRecord => {\n const { content, internationalization } = configuration;\n\n const baseDir = content.baseDir;\n const locales = internationalization.locales as Locale[];\n\n const localePattern = `{${locales.map((locale) => locale).join(',')}}`;\n\n const globPattern = builder({ key: '*', locale: localePattern });\n const maskPattern = builder({ key: '{{__KEY__}}', locale: '{{__LOCALE__}}' });\n\n const files = fg.sync(globPattern, {\n cwd: baseDir,\n });\n\n const result: MessagesRecord = {} as MessagesRecord;\n\n for (const file of files) {\n const { key, locale } = extractKeyAndLocaleFromPath(\n file,\n maskPattern,\n locales\n );\n\n const absolutePath = isAbsolute(file) ? file : resolve(baseDir, file);\n\n if (!result[locale as Locale]) {\n result[locale as Locale] = {};\n }\n\n result[locale as Locale][key as Dictionary['key']] = absolutePath;\n }\n\n return result;\n};\n\ntype FilePath = string;\n\ntype DictionariesMap = { path: string; locale: Locale; key: string }[];\n\nconst loadMessagePathMap = (\n source: MessagesRecord | Builder,\n configuration: IntlayerConfig\n) => {\n const messages: MessagesRecord = listMessages(\n source as Builder,\n configuration\n );\n\n const dictionariesPathMap: DictionariesMap = Object.entries(messages).flatMap(\n ([locale, keysRecord]) =>\n Object.entries(keysRecord).map(([key, path]) => {\n const absolutePath = isAbsolute(path)\n ? path\n : resolve(configuration.content.baseDir, path);\n\n return {\n path: absolutePath,\n locale,\n key,\n } as DictionariesMap[number];\n })\n );\n\n return dictionariesPathMap;\n};\n\ntype SyncJSONPluginOptions = {\n /**\n * The source of the plugin.\n * Is a function to build the source from the key and locale.\n *\n * ```ts\n * syncJSON({\n * source: ({ key, locale }) => `./messages/${locale}/${key}.json`\n * })\n * ```\n */\n source: Builder;\n\n /**\n * Because Intlayer transform the JSON files into Dictionary, we need to identify the plugin in the dictionary.\n * Used to identify the plugin in the dictionary.\n *\n * In the case you have multiple plugins, you can use this to identify the plugin in the dictionary.\n *\n * ```ts\n * const config ={\n * plugins: [\n * syncJSON({\n * source: ({ key, locale }) => `./resources/${locale}/${key}.json`\n * location: 'plugin-i18next',\n * }),\n * syncJSON({\n * source: ({ key, locale }) => `./messages/${locale}/${key}.json`\n * location: 'plugin-next-intl',\n * }),\n * ]\n * }\n * ```\n */\n location?: string;\n\n /**\n * The priority of the dictionaries created by the plugin.\n *\n * In the case of conflicts with remote dictionaries, or .content files, the dictionary with the highest priority will override the other dictionaries.\n *\n * Default is -1. (.content file priority is 0)\n *\n */\n priority?: number;\n};\n\nexport const syncJSON = (options: SyncJSONPluginOptions): Plugin => {\n const { location, priority } = {\n location: 'plugin',\n priority: 0,\n ...options,\n };\n\n return {\n name: 'sync-json',\n\n loadDictionaries: async ({ configuration }) => {\n const dictionariesMap: DictionariesMap = loadMessagePathMap(\n options.source,\n configuration\n );\n\n let fill: string = options.source({\n key: '{{key}}',\n locale: '{{locale}}',\n });\n\n if (fill && !isAbsolute(fill)) {\n fill = join(configuration.content.baseDir, fill);\n }\n\n const dictionaries: Dictionary[] = [];\n\n for (const { locale, path, key } of dictionariesMap) {\n const json: JSONContent = configuration.build.require(path as string);\n\n const filePath = relative(configuration.content.baseDir, path);\n\n const dictionary: Dictionary = {\n key,\n locale,\n fill,\n localId: `${key}::${location}::${filePath}` as LocalDictionaryId,\n location: location as Dictionary['location'],\n filled:\n locale !== configuration.internationalization.defaultLocale\n ? true\n : undefined,\n content: json,\n filePath,\n priority,\n };\n\n dictionaries.push(dictionary);\n }\n\n return dictionaries;\n },\n afterBuild: async ({ dictionaries, configuration }) => {\n // Dynamic import to avoid circular dependency as core package import config, that load esbuild, that load the config file, that load the plugin\n const { getLocalizedContent } = await import('@intlayer/core');\n\n const locales = configuration.internationalization.locales;\n\n type RecordList = {\n key: string;\n dictionary: Dictionary;\n locale: Locale;\n };\n\n const recordList: RecordList[] = Object.entries(\n dictionaries.mergedDictionaries\n ).flatMap(([key, dictionary]) =>\n locales.map((locale) => ({\n key,\n dictionary: dictionary.dictionary as Dictionary,\n locale,\n }))\n );\n\n await parallelize(recordList, async ({ key, dictionary, locale }) => {\n const builderPath = options.source({\n key,\n locale,\n });\n\n // Remove function, Symbol, etc. as it can be written as JSON\n const flatContent = JSON.parse(JSON.stringify(dictionary.content));\n\n const localizedContent = getLocalizedContent(\n flatContent as unknown as ContentNode,\n locale,\n {\n dictionaryKey: key,\n keyPath: [],\n }\n );\n\n // Ensure directory exists before writing the file\n await mkdir(dirname(builderPath), { recursive: true });\n\n const stringContent = JSON.stringify(localizedContent, null, 2);\n\n await writeFile(\n builderPath,\n `${stringContent}\\n`, // Add a new line at the end of the file to avoid formatting issues with VSCode\n 'utf-8'\n );\n });\n },\n formatOutput: ({ dictionary }) => {\n if (!dictionary.filePath || !dictionary.locale) return dictionary;\n\n const builderPath = options.source({\n key: dictionary.key,\n locale: dictionary.locale,\n });\n\n // It's not one of the JSON that we synchronize, don't modify it\n if (resolve(builderPath) !== resolve(dictionary.filePath)) {\n return dictionary;\n }\n\n return dictionary.content;\n },\n };\n};\n"],"mappings":";;;;;;;;;;;AA0BA,MAAM,eAAe,QAAgB,IAAI,QAAQ,uBAAuB,OAAO;AAE/E,MAAM,+BACJ,UACA,aACA,YACG;CACH,MAAM,iBAAiB;CACvB,MAAM,oBAAoB;CAE1B,MAAM,cAAc,YAAY,YAAY;CAC5C,MAAM,qBAAqB,QAAQ,KAAK,IAAI;CAG5C,IAAI,WAAW,IAAI,YAAY;AAE/B,YAAW,SAAS,QAClB,YAAY,kBAAkB,EAC9B,aAAa,mBAAmB,GACjC;AAED,KAAI,YAAY,SAAS,eAAe,CACtC,YAAW,SAAS,QAAQ,YAAY,eAAe,EAAE,gBAAgB;CAK3E,MAAM,QAFY,IAAI,OAAO,SAAS,CAEd,KAAK,SAAS;CAEtC,IAAIA;CACJ,IAAIC;AAEJ,KAAI,OAAO,QAAQ;AAC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O;AAGT,UAAO,WAAW;;EAErB"}
@@ -0,0 +1,127 @@
1
+ import { mkdir, writeFile } from "node:fs/promises";
2
+ import { dirname, isAbsolute, join, relative, resolve } from "node:path";
3
+ import { parallelize } from "@intlayer/chokidar";
4
+ import fg from "fast-glob";
5
+
6
+ //#region src/index.ts
7
+ const escapeRegex = (str) => str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
8
+ const extractKeyAndLocaleFromPath = (filePath, maskPattern, locales) => {
9
+ const keyPlaceholder = "{{__KEY__}}";
10
+ const localePlaceholder = "{{__LOCALE__}}";
11
+ const escapedMask = escapeRegex(maskPattern);
12
+ const localesAlternation = locales.join("|");
13
+ let regexStr = `^${escapedMask}$`;
14
+ regexStr = regexStr.replace(escapeRegex(localePlaceholder), `(?<locale>${localesAlternation})`);
15
+ if (maskPattern.includes(keyPlaceholder)) regexStr = regexStr.replace(escapeRegex(keyPlaceholder), "(?<key>[^/]+)");
16
+ const match = new RegExp(regexStr).exec(filePath);
17
+ let locale;
18
+ let key;
19
+ if (match?.groups) {
20
+ locale = match.groups.locale;
21
+ key = match.groups.key ?? "index";
22
+ }
23
+ return {
24
+ key,
25
+ locale
26
+ };
27
+ };
28
+ const listMessages = (builder, configuration) => {
29
+ const { content, internationalization } = configuration;
30
+ const baseDir = content.baseDir;
31
+ const locales = internationalization.locales;
32
+ const globPattern = builder({
33
+ key: "*",
34
+ locale: `{${locales.map((locale) => locale).join(",")}}`
35
+ });
36
+ const maskPattern = builder({
37
+ key: "{{__KEY__}}",
38
+ locale: "{{__LOCALE__}}"
39
+ });
40
+ const files = fg.sync(globPattern, { cwd: baseDir });
41
+ const result = {};
42
+ for (const file of files) {
43
+ const { key, locale } = extractKeyAndLocaleFromPath(file, maskPattern, locales);
44
+ const absolutePath = isAbsolute(file) ? file : resolve(baseDir, file);
45
+ if (!result[locale]) result[locale] = {};
46
+ result[locale][key] = absolutePath;
47
+ }
48
+ return result;
49
+ };
50
+ const loadMessagePathMap = (source, configuration) => {
51
+ const messages = listMessages(source, configuration);
52
+ return Object.entries(messages).flatMap(([locale, keysRecord]) => Object.entries(keysRecord).map(([key, path]) => {
53
+ return {
54
+ path: isAbsolute(path) ? path : resolve(configuration.content.baseDir, path),
55
+ locale,
56
+ key
57
+ };
58
+ }));
59
+ };
60
+ const syncJSON = (options) => {
61
+ const { location, priority } = {
62
+ location: "plugin",
63
+ priority: 0,
64
+ ...options
65
+ };
66
+ return {
67
+ name: "sync-json",
68
+ loadDictionaries: async ({ configuration }) => {
69
+ const dictionariesMap = loadMessagePathMap(options.source, configuration);
70
+ let fill = options.source({
71
+ key: "{{key}}",
72
+ locale: "{{locale}}"
73
+ });
74
+ if (fill && !isAbsolute(fill)) fill = join(configuration.content.baseDir, fill);
75
+ const dictionaries = [];
76
+ for (const { locale, path, key } of dictionariesMap) {
77
+ const json = configuration.build.require(path);
78
+ const filePath = relative(configuration.content.baseDir, path);
79
+ const dictionary = {
80
+ key,
81
+ locale,
82
+ fill,
83
+ localId: `${key}::${location}::${filePath}`,
84
+ location,
85
+ filled: locale !== configuration.internationalization.defaultLocale ? true : void 0,
86
+ content: json,
87
+ filePath,
88
+ priority
89
+ };
90
+ dictionaries.push(dictionary);
91
+ }
92
+ return dictionaries;
93
+ },
94
+ afterBuild: async ({ dictionaries, configuration }) => {
95
+ const { getLocalizedContent } = await import("@intlayer/core");
96
+ const locales = configuration.internationalization.locales;
97
+ await parallelize(Object.entries(dictionaries.mergedDictionaries).flatMap(([key, dictionary]) => locales.map((locale) => ({
98
+ key,
99
+ dictionary: dictionary.dictionary,
100
+ locale
101
+ }))), async ({ key, dictionary, locale }) => {
102
+ const builderPath = options.source({
103
+ key,
104
+ locale
105
+ });
106
+ const localizedContent = getLocalizedContent(JSON.parse(JSON.stringify(dictionary.content)), locale, {
107
+ dictionaryKey: key,
108
+ keyPath: []
109
+ });
110
+ await mkdir(dirname(builderPath), { recursive: true });
111
+ await writeFile(builderPath, `${JSON.stringify(localizedContent, null, 2)}\n`, "utf-8");
112
+ });
113
+ },
114
+ formatOutput: ({ dictionary }) => {
115
+ if (!dictionary.filePath || !dictionary.locale) return dictionary;
116
+ if (resolve(options.source({
117
+ key: dictionary.key,
118
+ locale: dictionary.locale
119
+ })) !== resolve(dictionary.filePath)) return dictionary;
120
+ return dictionary.content;
121
+ }
122
+ };
123
+ };
124
+
125
+ //#endregion
126
+ export { syncJSON };
127
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":["locale: Locale | undefined","key: string | undefined","result: MessagesRecord","messages: MessagesRecord","dictionariesMap: DictionariesMap","fill: string","dictionaries: Dictionary[]","json: JSONContent","dictionary: Dictionary"],"sources":["../../src/index.ts"],"sourcesContent":["import { mkdir, writeFile } from 'node:fs/promises';\nimport { dirname, isAbsolute, join, relative, resolve } from 'node:path';\nimport { parallelize } from '@intlayer/chokidar';\nimport type {\n ContentNode,\n Dictionary,\n IntlayerConfig,\n LocalDictionaryId,\n Locale,\n LocalesValues,\n Plugin,\n} from '@intlayer/types';\nimport fg from 'fast-glob';\n\ntype JSONContent = Record<string, any>;\n\ntype Builder = ({\n key,\n locale,\n}: {\n key: string;\n locale: LocalesValues | (string & {});\n}) => string;\n\ntype MessagesRecord = Record<Locale, Record<Dictionary['key'], FilePath>>;\n\nconst escapeRegex = (str: string) => str.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n\nconst extractKeyAndLocaleFromPath = (\n filePath: string,\n maskPattern: string,\n locales: Locale[]\n) => {\n const keyPlaceholder = '{{__KEY__}}';\n const localePlaceholder = '{{__LOCALE__}}';\n\n const escapedMask = escapeRegex(maskPattern);\n const localesAlternation = locales.join('|');\n\n // Build a regex from the mask to capture locale (and key if present)\n let regexStr = `^${escapedMask}$`;\n\n regexStr = regexStr.replace(\n escapeRegex(localePlaceholder),\n `(?<locale>${localesAlternation})`\n );\n\n if (maskPattern.includes(keyPlaceholder)) {\n regexStr = regexStr.replace(escapeRegex(keyPlaceholder), '(?<key>[^/]+)');\n }\n\n const maskRegex = new RegExp(regexStr);\n\n const match = maskRegex.exec(filePath);\n\n let locale: Locale | undefined;\n let key: string | undefined;\n\n if (match?.groups) {\n locale = match.groups.locale as Locale | undefined;\n key = (match.groups.key as string | undefined) ?? 'index';\n }\n\n return {\n key,\n locale,\n };\n};\n\nconst listMessages = (\n builder: Builder,\n configuration: IntlayerConfig\n): MessagesRecord => {\n const { content, internationalization } = configuration;\n\n const baseDir = content.baseDir;\n const locales = internationalization.locales as Locale[];\n\n const localePattern = `{${locales.map((locale) => locale).join(',')}}`;\n\n const globPattern = builder({ key: '*', locale: localePattern });\n const maskPattern = builder({ key: '{{__KEY__}}', locale: '{{__LOCALE__}}' });\n\n const files = fg.sync(globPattern, {\n cwd: baseDir,\n });\n\n const result: MessagesRecord = {} as MessagesRecord;\n\n for (const file of files) {\n const { key, locale } = extractKeyAndLocaleFromPath(\n file,\n maskPattern,\n locales\n );\n\n const absolutePath = isAbsolute(file) ? file : resolve(baseDir, file);\n\n if (!result[locale as Locale]) {\n result[locale as Locale] = {};\n }\n\n result[locale as Locale][key as Dictionary['key']] = absolutePath;\n }\n\n return result;\n};\n\ntype FilePath = string;\n\ntype DictionariesMap = { path: string; locale: Locale; key: string }[];\n\nconst loadMessagePathMap = (\n source: MessagesRecord | Builder,\n configuration: IntlayerConfig\n) => {\n const messages: MessagesRecord = listMessages(\n source as Builder,\n configuration\n );\n\n const dictionariesPathMap: DictionariesMap = Object.entries(messages).flatMap(\n ([locale, keysRecord]) =>\n Object.entries(keysRecord).map(([key, path]) => {\n const absolutePath = isAbsolute(path)\n ? path\n : resolve(configuration.content.baseDir, path);\n\n return {\n path: absolutePath,\n locale,\n key,\n } as DictionariesMap[number];\n })\n );\n\n return dictionariesPathMap;\n};\n\ntype SyncJSONPluginOptions = {\n /**\n * The source of the plugin.\n * Is a function to build the source from the key and locale.\n *\n * ```ts\n * syncJSON({\n * source: ({ key, locale }) => `./messages/${locale}/${key}.json`\n * })\n * ```\n */\n source: Builder;\n\n /**\n * Because Intlayer transform the JSON files into Dictionary, we need to identify the plugin in the dictionary.\n * Used to identify the plugin in the dictionary.\n *\n * In the case you have multiple plugins, you can use this to identify the plugin in the dictionary.\n *\n * ```ts\n * const config ={\n * plugins: [\n * syncJSON({\n * source: ({ key, locale }) => `./resources/${locale}/${key}.json`\n * location: 'plugin-i18next',\n * }),\n * syncJSON({\n * source: ({ key, locale }) => `./messages/${locale}/${key}.json`\n * location: 'plugin-next-intl',\n * }),\n * ]\n * }\n * ```\n */\n location?: string;\n\n /**\n * The priority of the dictionaries created by the plugin.\n *\n * In the case of conflicts with remote dictionaries, or .content files, the dictionary with the highest priority will override the other dictionaries.\n *\n * Default is -1. (.content file priority is 0)\n *\n */\n priority?: number;\n};\n\nexport const syncJSON = (options: SyncJSONPluginOptions): Plugin => {\n const { location, priority } = {\n location: 'plugin',\n priority: 0,\n ...options,\n };\n\n return {\n name: 'sync-json',\n\n loadDictionaries: async ({ configuration }) => {\n const dictionariesMap: DictionariesMap = loadMessagePathMap(\n options.source,\n configuration\n );\n\n let fill: string = options.source({\n key: '{{key}}',\n locale: '{{locale}}',\n });\n\n if (fill && !isAbsolute(fill)) {\n fill = join(configuration.content.baseDir, fill);\n }\n\n const dictionaries: Dictionary[] = [];\n\n for (const { locale, path, key } of dictionariesMap) {\n const json: JSONContent = configuration.build.require(path as string);\n\n const filePath = relative(configuration.content.baseDir, path);\n\n const dictionary: Dictionary = {\n key,\n locale,\n fill,\n localId: `${key}::${location}::${filePath}` as LocalDictionaryId,\n location: location as Dictionary['location'],\n filled:\n locale !== configuration.internationalization.defaultLocale\n ? true\n : undefined,\n content: json,\n filePath,\n priority,\n };\n\n dictionaries.push(dictionary);\n }\n\n return dictionaries;\n },\n afterBuild: async ({ dictionaries, configuration }) => {\n // Dynamic import to avoid circular dependency as core package import config, that load esbuild, that load the config file, that load the plugin\n const { getLocalizedContent } = await import('@intlayer/core');\n\n const locales = configuration.internationalization.locales;\n\n type RecordList = {\n key: string;\n dictionary: Dictionary;\n locale: Locale;\n };\n\n const recordList: RecordList[] = Object.entries(\n dictionaries.mergedDictionaries\n ).flatMap(([key, dictionary]) =>\n locales.map((locale) => ({\n key,\n dictionary: dictionary.dictionary as Dictionary,\n locale,\n }))\n );\n\n await parallelize(recordList, async ({ key, dictionary, locale }) => {\n const builderPath = options.source({\n key,\n locale,\n });\n\n // Remove function, Symbol, etc. as it can be written as JSON\n const flatContent = JSON.parse(JSON.stringify(dictionary.content));\n\n const localizedContent = getLocalizedContent(\n flatContent as unknown as ContentNode,\n locale,\n {\n dictionaryKey: key,\n keyPath: [],\n }\n );\n\n // Ensure directory exists before writing the file\n await mkdir(dirname(builderPath), { recursive: true });\n\n const stringContent = JSON.stringify(localizedContent, null, 2);\n\n await writeFile(\n builderPath,\n `${stringContent}\\n`, // Add a new line at the end of the file to avoid formatting issues with VSCode\n 'utf-8'\n );\n });\n },\n formatOutput: ({ dictionary }) => {\n if (!dictionary.filePath || !dictionary.locale) return dictionary;\n\n const builderPath = options.source({\n key: dictionary.key,\n locale: dictionary.locale,\n });\n\n // It's not one of the JSON that we synchronize, don't modify it\n if (resolve(builderPath) !== resolve(dictionary.filePath)) {\n return dictionary;\n }\n\n return dictionary.content;\n },\n };\n};\n"],"mappings":";;;;;;AA0BA,MAAM,eAAe,QAAgB,IAAI,QAAQ,uBAAuB,OAAO;AAE/E,MAAM,+BACJ,UACA,aACA,YACG;CACH,MAAM,iBAAiB;CACvB,MAAM,oBAAoB;CAE1B,MAAM,cAAc,YAAY,YAAY;CAC5C,MAAM,qBAAqB,QAAQ,KAAK,IAAI;CAG5C,IAAI,WAAW,IAAI,YAAY;AAE/B,YAAW,SAAS,QAClB,YAAY,kBAAkB,EAC9B,aAAa,mBAAmB,GACjC;AAED,KAAI,YAAY,SAAS,eAAe,CACtC,YAAW,SAAS,QAAQ,YAAY,eAAe,EAAE,gBAAgB;CAK3E,MAAM,QAFY,IAAI,OAAO,SAAS,CAEd,KAA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AAO;AAQvD,OAAI,QANgB,QAAQ,OAAO;IACjC,KAAK,WAAW;IAChB,QAAQ,WAAW;IACpB,CAAC,CAGsB,KAAK,QAAQ,WAAW,SAAS,CACvD,QAAO;AAGT,UAAO,WAAW;;EAErB"}
@@ -0,0 +1,58 @@
1
+ import { LocalesValues, Plugin } from "@intlayer/types";
2
+
3
+ //#region src/index.d.ts
4
+ type Builder = ({
5
+ key,
6
+ locale
7
+ }: {
8
+ key: string;
9
+ locale: LocalesValues | (string & {});
10
+ }) => string;
11
+ type SyncJSONPluginOptions = {
12
+ /**
13
+ * The source of the plugin.
14
+ * Is a function to build the source from the key and locale.
15
+ *
16
+ * ```ts
17
+ * syncJSON({
18
+ * source: ({ key, locale }) => `./messages/${locale}/${key}.json`
19
+ * })
20
+ * ```
21
+ */
22
+ source: Builder;
23
+ /**
24
+ * Because Intlayer transform the JSON files into Dictionary, we need to identify the plugin in the dictionary.
25
+ * Used to identify the plugin in the dictionary.
26
+ *
27
+ * In the case you have multiple plugins, you can use this to identify the plugin in the dictionary.
28
+ *
29
+ * ```ts
30
+ * const config ={
31
+ * plugins: [
32
+ * syncJSON({
33
+ * source: ({ key, locale }) => `./resources/${locale}/${key}.json`
34
+ * location: 'plugin-i18next',
35
+ * }),
36
+ * syncJSON({
37
+ * source: ({ key, locale }) => `./messages/${locale}/${key}.json`
38
+ * location: 'plugin-next-intl',
39
+ * }),
40
+ * ]
41
+ * }
42
+ * ```
43
+ */
44
+ location?: string;
45
+ /**
46
+ * The priority of the dictionaries created by the plugin.
47
+ *
48
+ * In the case of conflicts with remote dictionaries, or .content files, the dictionary with the highest priority will override the other dictionaries.
49
+ *
50
+ * Default is -1. (.content file priority is 0)
51
+ *
52
+ */
53
+ priority?: number;
54
+ };
55
+ declare const syncJSON: (options: SyncJSONPluginOptions) => Plugin;
56
+ //#endregion
57
+ export { syncJSON };
58
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/index.ts"],"sourcesContent":[],"mappings":";;;KAgBK,OAAA;;;;;EAAA,MAAA,EAKK,aALE,GAAA,CAAA,MAAA,GAAA,CAAA,CAAA,CAAA;CACV,EAAA,GAAA,MAAA;KA0HG,qBAAA,GAzHH;EAGQ;;AAAa;AAqKvB;;;;;;;UApCU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAoCG,oBAAqB,0BAAwB"}
package/package.json ADDED
@@ -0,0 +1,102 @@
1
+ {
2
+ "name": "@intlayer/sync-json-plugin",
3
+ "version": "7.0.0-canary.2",
4
+ "private": false,
5
+ "description": "A plugin for Intlayer that syncs JSON files to dictionaries.",
6
+ "keywords": [
7
+ "intlayer",
8
+ "json",
9
+ "plugin",
10
+ "sync"
11
+ ],
12
+ "homepage": "https://intlayer.org",
13
+ "bugs": {
14
+ "url": "https://github.com/aymericzip/intlayer/issues"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/aymericzip/intlayer.git"
19
+ },
20
+ "license": "Apache-2.0",
21
+ "author": {
22
+ "name": "Aymeric PINEAU",
23
+ "url": "https://github.com/aymericzip"
24
+ },
25
+ "contributors": [
26
+ {
27
+ "name": "Aymeric Pineau",
28
+ "email": "ay.pineau@gmail.com",
29
+ "url": "https://github.com/aymericzip"
30
+ }
31
+ ],
32
+ "sideEffects": false,
33
+ "exports": {
34
+ ".": {
35
+ "types": "./dist/types/index.d.ts",
36
+ "require": "./dist/cjs/index.cjs",
37
+ "import": "./dist/esm/index.mjs"
38
+ },
39
+ "./package.json": "./package.json"
40
+ },
41
+ "main": "dist/cjs/index.cjs",
42
+ "module": "dist/esm/index.mjs",
43
+ "types": "dist/types/index.d.ts",
44
+ "typesVersions": {
45
+ "*": {
46
+ "package.json": [
47
+ "./package.json"
48
+ ]
49
+ }
50
+ },
51
+ "files": [
52
+ "./dist",
53
+ "./package.json"
54
+ ],
55
+ "scripts": {
56
+ "build": "tsdown --config tsdown.config.ts",
57
+ "build:ci": "tsdown --config tsdown.config.ts",
58
+ "clean": "rimraf ./dist .turbo",
59
+ "dev": "tsdown --config tsdown.config.ts --watch",
60
+ "format": "biome format . --check",
61
+ "format:fix": "biome format --write .",
62
+ "lint": "biome lint .",
63
+ "lint:fix": "biome lint --write .",
64
+ "process-files": "ts-node src/transpiler/processFilesCLI.ts --dir $npm_config_dir --extension $npm_config_extension --no-node-snapshot",
65
+ "prepublish": "cp -f ../../../README.md ./README.md",
66
+ "test": "vitest run",
67
+ "test:watch": "vitest",
68
+ "typecheck": "tsc --noEmit --project tsconfig.types.json"
69
+ },
70
+ "dependencies": {
71
+ "@intlayer/chokidar": "7.0.0-canary.2",
72
+ "@intlayer/config": "7.0.0-canary.2",
73
+ "@intlayer/core": "7.0.0-canary.2",
74
+ "fast-glob": "3.3.3"
75
+ },
76
+ "devDependencies": {
77
+ "@types/node": "24.9.1",
78
+ "@utils/ts-config": "7.0.0-canary.2",
79
+ "@utils/ts-config-types": "7.0.0-canary.2",
80
+ "@utils/tsdown-config": "7.0.0-canary.2",
81
+ "rimraf": "6.0.1",
82
+ "tsdown": "0.15.9",
83
+ "typescript": "5.9.3",
84
+ "vitest": "4.0.3"
85
+ },
86
+ "peerDependencies": {
87
+ "@intlayer/config": "7.0.0-canary.2",
88
+ "@intlayer/core": "7.0.0-canary.2",
89
+ "intlayer": "7.0.0-canary.2"
90
+ },
91
+ "peerDependenciesMeta": {
92
+ "intlayer": {
93
+ "optional": true
94
+ }
95
+ },
96
+ "engines": {
97
+ "node": ">=14.18"
98
+ },
99
+ "bug": {
100
+ "url": "https://github.com/aymericzip/intlayer/issues"
101
+ }
102
+ }