@intlayer/docs 7.0.4-canary.0 → 7.0.4
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/blog/ar/intlayer_with_i18next.md +68 -106
- package/blog/ar/intlayer_with_next-i18next.md +84 -288
- package/blog/ar/intlayer_with_next-intl.md +58 -337
- package/blog/ar/intlayer_with_react-i18next.md +68 -290
- package/blog/ar/intlayer_with_react-intl.md +63 -266
- package/blog/de/intlayer_with_i18next.md +77 -97
- package/blog/de/intlayer_with_next-i18next.md +69 -296
- package/blog/de/intlayer_with_next-intl.md +59 -340
- package/blog/de/intlayer_with_react-i18next.md +68 -290
- package/blog/de/intlayer_with_react-intl.md +62 -264
- package/blog/en/intlayer_with_i18next.md +36 -1638
- package/blog/en/intlayer_with_next-i18next.md +22 -847
- package/blog/en/intlayer_with_next-intl.md +32 -1053
- package/blog/en/intlayer_with_react-i18next.md +38 -764
- package/blog/en/intlayer_with_react-intl.md +42 -1018
- package/blog/en-GB/intlayer_with_i18next.md +67 -103
- package/blog/en-GB/intlayer_with_next-i18next.md +71 -292
- package/blog/en-GB/intlayer_with_next-intl.md +58 -337
- package/blog/en-GB/intlayer_with_react-i18next.md +67 -289
- package/blog/en-GB/intlayer_with_react-intl.md +61 -264
- package/blog/es/intlayer_with_i18next.md +67 -103
- package/blog/es/intlayer_with_next-i18next.md +71 -296
- package/blog/es/intlayer_with_next-intl.md +57 -338
- package/blog/es/intlayer_with_react-i18next.md +68 -290
- package/blog/es/intlayer_with_react-intl.md +62 -265
- package/blog/fr/intlayer_with_i18next.md +66 -104
- package/blog/fr/intlayer_with_next-i18next.md +82 -285
- package/blog/fr/intlayer_with_next-intl.md +57 -338
- package/blog/fr/intlayer_with_react-i18next.md +67 -289
- package/blog/fr/intlayer_with_react-intl.md +61 -264
- package/blog/hi/intlayer_with_i18next.md +68 -104
- package/blog/hi/intlayer_with_next-i18next.md +74 -299
- package/blog/hi/intlayer_with_next-intl.md +57 -239
- package/blog/hi/intlayer_with_react-i18next.md +69 -291
- package/blog/hi/intlayer_with_react-intl.md +65 -268
- package/blog/id/intlayer_with_i18next.md +126 -0
- package/blog/id/intlayer_with_next-i18next.md +142 -0
- package/blog/id/intlayer_with_next-intl.md +113 -0
- package/blog/id/intlayer_with_react-i18next.md +124 -0
- package/blog/id/intlayer_with_react-intl.md +122 -0
- package/blog/it/intlayer_with_i18next.md +67 -103
- package/blog/it/intlayer_with_next-i18next.md +71 -296
- package/blog/it/intlayer_with_next-intl.md +57 -338
- package/blog/it/intlayer_with_react-i18next.md +68 -290
- package/blog/it/intlayer_with_react-intl.md +62 -265
- package/blog/ja/intlayer_with_i18next.md +68 -103
- package/blog/ja/intlayer_with_next-i18next.md +85 -283
- package/blog/ja/intlayer_with_next-intl.md +58 -336
- package/blog/ja/intlayer_with_react-i18next.md +68 -290
- package/blog/ja/intlayer_with_react-intl.md +62 -264
- package/blog/ko/intlayer_with_i18next.md +80 -96
- package/blog/ko/intlayer_with_next-i18next.md +85 -287
- package/blog/ko/intlayer_with_next-intl.md +68 -327
- package/blog/ko/intlayer_with_react-i18next.md +68 -290
- package/blog/ko/intlayer_with_react-intl.md +64 -266
- package/blog/pl/intlayer_with_i18next.md +126 -0
- package/blog/pl/intlayer_with_next-i18next.md +142 -0
- package/blog/pl/intlayer_with_next-intl.md +111 -0
- package/blog/pl/intlayer_with_react-i18next.md +124 -0
- package/blog/pl/intlayer_with_react-intl.md +122 -0
- package/blog/pt/intlayer_with_i18next.md +67 -103
- package/blog/pt/intlayer_with_next-i18next.md +72 -293
- package/blog/pt/intlayer_with_next-intl.md +57 -256
- package/blog/pt/intlayer_with_react-i18next.md +104 -78
- package/blog/pt/intlayer_with_react-intl.md +62 -266
- package/blog/ru/intlayer_with_i18next.md +66 -104
- package/blog/ru/intlayer_with_next-i18next.md +71 -296
- package/blog/ru/intlayer_with_next-intl.md +58 -337
- package/blog/ru/intlayer_with_react-i18next.md +68 -290
- package/blog/ru/intlayer_with_react-intl.md +62 -265
- package/blog/tr/intlayer_with_i18next.md +71 -107
- package/blog/tr/intlayer_with_next-i18next.md +72 -297
- package/blog/tr/intlayer_with_next-intl.md +58 -339
- package/blog/tr/intlayer_with_react-i18next.md +69 -291
- package/blog/tr/intlayer_with_react-intl.md +63 -285
- package/blog/vi/intlayer_with_i18next.md +126 -0
- package/blog/vi/intlayer_with_next-i18next.md +142 -0
- package/blog/vi/intlayer_with_next-intl.md +111 -0
- package/blog/vi/intlayer_with_react-i18next.md +124 -0
- package/blog/vi/intlayer_with_react-intl.md +122 -0
- package/blog/zh/intlayer_with_i18next.md +67 -102
- package/blog/zh/intlayer_with_next-i18next.md +72 -296
- package/blog/zh/intlayer_with_next-intl.md +58 -336
- package/blog/zh/intlayer_with_react-i18next.md +68 -290
- package/blog/zh/intlayer_with_react-intl.md +63 -106
- package/docs/ar/plugins/sync-json.md +244 -0
- package/docs/de/plugins/sync-json.md +244 -0
- package/docs/en/intlayer_cli.md +25 -0
- package/docs/en/intlayer_with_nextjs_14.md +2 -0
- package/docs/en/intlayer_with_nextjs_15.md +2 -0
- package/docs/en/intlayer_with_nextjs_16.md +2 -0
- package/docs/en/plugins/sync-json.md +1 -1
- package/docs/en-GB/plugins/sync-json.md +244 -0
- package/docs/es/plugins/sync-json.md +244 -0
- package/docs/fr/plugins/sync-json.md +244 -0
- package/docs/hi/plugins/sync-json.md +244 -0
- package/docs/id/plugins/sync-json.md +244 -0
- package/docs/it/plugins/sync-json.md +244 -0
- package/docs/ja/plugins/sync-json.md +244 -0
- package/docs/ko/plugins/sync-json.md +244 -0
- package/docs/pl/plugins/sync-json.md +244 -0
- package/docs/pt/plugins/sync-json.md +244 -0
- package/docs/ru/plugins/sync-json.md +244 -0
- package/docs/tr/plugins/sync-json.md +245 -0
- package/docs/vi/plugins/sync-json.md +244 -0
- package/docs/zh/plugins/sync-json.md +244 -0
- package/package.json +14 -14
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
---
|
|
2
|
+
createdAt: 2025-03-13
|
|
3
|
+
updatedAt: 2025-10-05
|
|
4
|
+
title: Wtyczka Sync JSON
|
|
5
|
+
description: Synchronizuj słowniki Intlayer z zewnętrznymi plikami JSON i18n (i18next, next-intl, react-intl, vue-i18n i inne). Zachowaj istniejące i18n, korzystając z Intlayer do zarządzania, tłumaczenia i testowania swoich komunikatów.
|
|
6
|
+
keywords:
|
|
7
|
+
- Intlayer
|
|
8
|
+
- Sync JSON
|
|
9
|
+
- i18next
|
|
10
|
+
- next-intl
|
|
11
|
+
- react-intl
|
|
12
|
+
- vue-i18n
|
|
13
|
+
- next-translate
|
|
14
|
+
- nuxt-i18n
|
|
15
|
+
- LinguiJS
|
|
16
|
+
- Polyglot.js
|
|
17
|
+
- Solid-i18next
|
|
18
|
+
- svelte-i18n
|
|
19
|
+
- i18n
|
|
20
|
+
- tłumaczenia
|
|
21
|
+
slugs:
|
|
22
|
+
- doc
|
|
23
|
+
- plugin
|
|
24
|
+
- sync-json
|
|
25
|
+
history:
|
|
26
|
+
- version: 6.1.6
|
|
27
|
+
date: 2025-10-05
|
|
28
|
+
changes: Pierwsza dokumentacja wtyczki Sync JSON
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
# Sync JSON (mosty i18n)
|
|
32
|
+
|
|
33
|
+
Użyj Intlayer jako dodatku do istniejącego stosu i18n. Ta wtyczka utrzymuje synchronizację Twoich komunikatów JSON ze słownikami Intlayer, dzięki czemu możesz:
|
|
34
|
+
|
|
35
|
+
- Zachować i18next, next-intl, react-intl, vue-i18n, next-translate, nuxt-i18n, Solid-i18next, svelte-i18n itp.
|
|
36
|
+
- Zarządzać i tłumaczyć swoje komunikaty za pomocą Intlayer (CLI, CI, dostawcy, CMS), bez konieczności refaktoryzacji aplikacji.
|
|
37
|
+
- Dostarczać samouczki i treści SEO skierowane do każdego ekosystemu, jednocześnie sugerując Intlayer jako warstwę zarządzania JSON.
|
|
38
|
+
|
|
39
|
+
Uwagi i obecny zakres:
|
|
40
|
+
|
|
41
|
+
- Eksport do CMS działa dla tłumaczeń i klasycznego tekstu.
|
|
42
|
+
- Brak jeszcze wsparcia dla wstawek, liczby mnogiej/ICU lub zaawansowanych funkcji czasu wykonywania innych bibliotek.
|
|
43
|
+
- Edytor wizualny nie jest jeszcze obsługiwany dla wyjść i18n zewnętrznych bibliotek.
|
|
44
|
+
|
|
45
|
+
### Kiedy używać tej wtyczki
|
|
46
|
+
|
|
47
|
+
- Już korzystasz z biblioteki i18n i przechowujesz komunikaty w plikach JSON.
|
|
48
|
+
- Chcesz korzystać z wypełniania wspomaganego przez AI, testów w CI oraz operacji na treściach bez zmiany środowiska renderowania.
|
|
49
|
+
|
|
50
|
+
## Instalacja
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
pnpm add -D @intlayer/sync-json-plugin
|
|
54
|
+
# lub
|
|
55
|
+
npm i -D @intlayer/sync-json-plugin
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Szybki start
|
|
59
|
+
|
|
60
|
+
Dodaj wtyczkę do swojego pliku `intlayer.config.ts` i wskaż ją na istniejącą strukturę JSON.
|
|
61
|
+
|
|
62
|
+
```ts fileName="intlayer.config.ts"
|
|
63
|
+
import { defineConfig, Locales } from "intlayer";
|
|
64
|
+
import { syncJSON } from "@intlayer/sync-json-plugin";
|
|
65
|
+
|
|
66
|
+
export default defineConfig({
|
|
67
|
+
internationalization: {
|
|
68
|
+
locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH],
|
|
69
|
+
defaultLocale: Locales.ENGLISH,
|
|
70
|
+
},
|
|
71
|
+
|
|
72
|
+
// Synchronizuj swoje obecne pliki JSON ze słownikami Intlayer
|
|
73
|
+
plugins: [
|
|
74
|
+
syncJSON({
|
|
75
|
+
// Układ per-locale, per-namespace (np. next-intl, i18next z przestrzeniami nazw)
|
|
76
|
+
source: ({ key, locale }) => `./locales/${locale}/${key}.json`,
|
|
77
|
+
}),
|
|
78
|
+
],
|
|
79
|
+
});
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Alternatywa: pojedynczy plik na locale (częste w konfiguracjach i18next/react-intl):
|
|
83
|
+
|
|
84
|
+
```ts fileName="intlayer.config.ts"
|
|
85
|
+
plugins: [
|
|
86
|
+
syncJSON({
|
|
87
|
+
source: ({ locale }) => `./locales/${locale}.json`,
|
|
88
|
+
}),
|
|
89
|
+
];
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Jak to działa
|
|
93
|
+
|
|
94
|
+
- Odczyt: wtyczka wykrywa pliki JSON zdefiniowane przez twój builder `source` i ładuje je jako słowniki Intlayer.
|
|
95
|
+
- Zapis: po budowaniu i wypełnianiu, zapisuje zlokalizowane pliki JSON z powrotem pod te same ścieżki (z końcowym znakiem nowej linii, aby uniknąć problemów z formatowaniem).
|
|
96
|
+
- Auto‑uzupełnianie: wtyczka deklaruje ścieżkę `autoFill` dla każdego słownika. Uruchomienie `intlayer fill` domyślnie aktualizuje tylko brakujące tłumaczenia w twoich plikach JSON.
|
|
97
|
+
|
|
98
|
+
API:
|
|
99
|
+
|
|
100
|
+
```ts
|
|
101
|
+
syncJSON({
|
|
102
|
+
source: ({ key, locale }) => string, // wymagane
|
|
103
|
+
location?: string, // opcjonalna etykieta, domyślnie: "plugin"
|
|
104
|
+
priority?: number, // opcjonalny priorytet do rozstrzygania konfliktów, domyślnie: 0
|
|
105
|
+
});
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Wiele źródeł JSON i priorytet
|
|
109
|
+
|
|
110
|
+
Możesz dodać wiele wtyczek `syncJSON`, aby synchronizować różne źródła JSON. Jest to przydatne, gdy masz wiele bibliotek i18n lub różne struktury JSON w swoim projekcie.
|
|
111
|
+
|
|
112
|
+
### System priorytetów
|
|
113
|
+
|
|
114
|
+
Gdy wiele wtyczek celuje w ten sam klucz słownika, parametr `priority` decyduje, która wtyczka ma pierwszeństwo:
|
|
115
|
+
|
|
116
|
+
- Wyższe liczby priorytetu mają przewagę nad niższymi
|
|
117
|
+
- Domyślny priorytet plików `.content` to `0`
|
|
118
|
+
- Domyślny priorytet plików zawartości wtyczek to `-1`
|
|
119
|
+
- Wtyczki o tym samym priorytecie są przetwarzane w kolejności, w jakiej pojawiają się w konfiguracji
|
|
120
|
+
|
|
121
|
+
```ts fileName="intlayer.config.ts"
|
|
122
|
+
import { defineConfig, Locales } from "intlayer";
|
|
123
|
+
import { syncJSON } from "@intlayer/sync-json-plugin";
|
|
124
|
+
|
|
125
|
+
export default defineConfig({
|
|
126
|
+
internationalization: {
|
|
127
|
+
locales: [Locales.ENGLISH, Locales.FRENCH],
|
|
128
|
+
defaultLocale: Locales.ENGLISH,
|
|
129
|
+
},
|
|
130
|
+
|
|
131
|
+
plugins: [
|
|
132
|
+
// Główne źródło JSON (najwyższy priorytet)
|
|
133
|
+
syncJSON({
|
|
134
|
+
source: ({ key, locale }) => `./locales/${locale}/${key}.json`,
|
|
135
|
+
location: "main-translations",
|
|
136
|
+
priority: 10,
|
|
137
|
+
}),
|
|
138
|
+
|
|
139
|
+
// Zapasowe źródło JSON (niższy priorytet)
|
|
140
|
+
syncJSON({
|
|
141
|
+
source: ({ locale }) => `./fallback-locales/${locale}.json`,
|
|
142
|
+
location: "fallback-translations",
|
|
143
|
+
priority: 5,
|
|
144
|
+
}),
|
|
145
|
+
|
|
146
|
+
// Źródło JSON dziedziczone (najniższy priorytet)
|
|
147
|
+
syncJSON({
|
|
148
|
+
source: ({ locale }) => `/my/other/app/legacy/${locale}/messages.json`,
|
|
149
|
+
location: "legacy-translations",
|
|
150
|
+
priority: 1,
|
|
151
|
+
}),
|
|
152
|
+
],
|
|
153
|
+
});
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### Rozwiązywanie konfliktów
|
|
157
|
+
|
|
158
|
+
Gdy ten sam klucz tłumaczenia występuje w wielu źródłach JSON:
|
|
159
|
+
|
|
160
|
+
1. Wtyczka o najwyższym priorytecie decyduje o ostatecznej wartości
|
|
161
|
+
2. Źródła o niższym priorytecie są używane jako zapasowe dla brakujących kluczy
|
|
162
|
+
3. Pozwala to na utrzymanie tłumaczeń dziedziczonych podczas stopniowej migracji do nowych struktur
|
|
163
|
+
|
|
164
|
+
## Integracje
|
|
165
|
+
|
|
166
|
+
Poniżej znajdują się typowe mapowania. Zachowaj swój runtime bez zmian; dodaj tylko wtyczkę.
|
|
167
|
+
|
|
168
|
+
### i18next
|
|
169
|
+
|
|
170
|
+
Typowy układ plików: `./public/locales/{locale}/{namespace}.json` lub `./locales/{locale}/{namespace}.json`.
|
|
171
|
+
|
|
172
|
+
```ts fileName="intlayer.config.ts"
|
|
173
|
+
import { syncJSON } from "@intlayer/sync-json-plugin";
|
|
174
|
+
|
|
175
|
+
export default {
|
|
176
|
+
plugins: [
|
|
177
|
+
syncJSON({
|
|
178
|
+
source: ({ key, locale }) => `./locales/${locale}/${key}.json`,
|
|
179
|
+
}),
|
|
180
|
+
],
|
|
181
|
+
};
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### next-intl
|
|
185
|
+
|
|
186
|
+
Wiadomości JSON na locale (często `./messages/{locale}.json`) lub na namespace.
|
|
187
|
+
|
|
188
|
+
```ts fileName="intlayer.config.ts"
|
|
189
|
+
plugins: [
|
|
190
|
+
syncJSON({
|
|
191
|
+
source: ({ locale, key }) => `./messages/${locale}/${key}.json`,
|
|
192
|
+
}),
|
|
193
|
+
];
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
Zobacz także: `docs/pl/intlayer_with_next-intl.md`.
|
|
197
|
+
|
|
198
|
+
### react-intl
|
|
199
|
+
|
|
200
|
+
Pojedynczy JSON na locale jest powszechny:
|
|
201
|
+
|
|
202
|
+
```ts fileName="intlayer.config.ts"
|
|
203
|
+
plugins: [
|
|
204
|
+
syncJSON({
|
|
205
|
+
source: ({ locale }) => `./locales/${locale}.json`,
|
|
206
|
+
}),
|
|
207
|
+
];
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
### vue-i18n
|
|
211
|
+
|
|
212
|
+
Może to być pojedynczy plik na locale lub na namespace:
|
|
213
|
+
|
|
214
|
+
```ts fileName="intlayer.config.ts"
|
|
215
|
+
plugins: [
|
|
216
|
+
syncJSON({
|
|
217
|
+
source: ({ key, locale }) => `./src/locales/${locale}/${key}.json`,
|
|
218
|
+
}),
|
|
219
|
+
];
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
## CLI
|
|
223
|
+
|
|
224
|
+
Synchronizowane pliki JSON będą traktowane jak inne pliki `.content`. Oznacza to, że wszystkie polecenia intlayer będą dostępne dla synchronizowanych plików JSON. W tym:
|
|
225
|
+
|
|
226
|
+
- `intlayer content test` do testowania, czy brakuje tłumaczeń
|
|
227
|
+
- `intlayer content list` do wyświetlania listy synchronizowanych plików JSON
|
|
228
|
+
- `intlayer content fill` do uzupełniania brakujących tłumaczeń
|
|
229
|
+
- `intlayer content push` do wysyłania synchronizowanych plików JSON
|
|
230
|
+
- `intlayer content pull` do pobierania synchronizowanych plików JSON
|
|
231
|
+
|
|
232
|
+
Zobacz [Intlayer CLI](https://github.com/aymericzip/intlayer/blob/main/docs/docs/pl/intlayer_cli.md) po więcej szczegółów.
|
|
233
|
+
|
|
234
|
+
## Ograniczenia (aktualne)
|
|
235
|
+
|
|
236
|
+
- Brak wsparcia dla wstawek lub liczby mnogiej/ICU przy celowaniu w biblioteki firm trzecich.
|
|
237
|
+
- Edytor wizualny nie jest jeszcze dostępny dla środowisk uruchomieniowych innych niż Intlayer.
|
|
238
|
+
- Synchronizacja tylko plików JSON; formaty katalogów inne niż JSON nie są obsługiwane.
|
|
239
|
+
|
|
240
|
+
## Dlaczego to ma znaczenie
|
|
241
|
+
|
|
242
|
+
- Możemy polecać sprawdzone rozwiązania i18n i pozycjonować Intlayer jako dodatek.
|
|
243
|
+
- Wykorzystujemy ich SEO/słowa kluczowe z tutorialami, które kończą się sugestią użycia Intlayer do zarządzania JSON.
|
|
244
|
+
- Rozszerza docelową grupę odbiorców z „nowych projektów” na „każdy zespół już korzystający z i18n”.
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
---
|
|
2
|
+
createdAt: 2025-03-13
|
|
3
|
+
updatedAt: 2025-10-05
|
|
4
|
+
title: Plugin Sync JSON
|
|
5
|
+
description: Sincronize os dicionários Intlayer com arquivos JSON i18n de terceiros (i18next, next-intl, react-intl, vue-i18n e mais). Mantenha seu i18n existente enquanto usa o Intlayer para gerenciar, traduzir e testar suas mensagens.
|
|
6
|
+
keywords:
|
|
7
|
+
- Intlayer
|
|
8
|
+
- Sync JSON
|
|
9
|
+
- i18next
|
|
10
|
+
- next-intl
|
|
11
|
+
- react-intl
|
|
12
|
+
- vue-i18n
|
|
13
|
+
- next-translate
|
|
14
|
+
- nuxt-i18n
|
|
15
|
+
- LinguiJS
|
|
16
|
+
- Polyglot.js
|
|
17
|
+
- Solid-i18next
|
|
18
|
+
- svelte-i18n
|
|
19
|
+
- i18n
|
|
20
|
+
- traduções
|
|
21
|
+
slugs:
|
|
22
|
+
- doc
|
|
23
|
+
- plugin
|
|
24
|
+
- sync-json
|
|
25
|
+
history:
|
|
26
|
+
- version: 6.1.6
|
|
27
|
+
date: 2025-10-05
|
|
28
|
+
changes: Documentação inicial do plugin Sync JSON
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## Sync JSON (pontes i18n)
|
|
32
|
+
|
|
33
|
+
Use o Intlayer como um complemento para sua pilha i18n existente. Este plugin mantém suas mensagens JSON sincronizadas com os dicionários Intlayer para que você possa:
|
|
34
|
+
|
|
35
|
+
- Manter i18next, next-intl, react-intl, vue-i18n, next-translate, nuxt-i18n, Solid-i18next, svelte-i18n, etc.
|
|
36
|
+
- Gerenciar e traduzir suas mensagens com o Intlayer (CLI, CI, provedores, CMS), sem precisar refatorar seu aplicativo.
|
|
37
|
+
- Publicar tutoriais e conteúdo SEO direcionado a cada ecossistema, enquanto sugere o Intlayer como a camada de gerenciamento JSON.
|
|
38
|
+
|
|
39
|
+
Notas e escopo atual:
|
|
40
|
+
|
|
41
|
+
- A externalização para o CMS funciona para traduções e texto clássico.
|
|
42
|
+
- Ainda não há suporte para inserções, plurais/ICU ou recursos avançados de tempo de execução de outras bibliotecas.
|
|
43
|
+
- O editor visual ainda não é suportado para saídas i18n de terceiros.
|
|
44
|
+
|
|
45
|
+
### Quando usar este plugin
|
|
46
|
+
|
|
47
|
+
- Você já usa uma biblioteca i18n e armazena mensagens em arquivos JSON.
|
|
48
|
+
- Você deseja preenchimento assistido por IA, testes em CI e operações de conteúdo sem alterar seu tempo de execução de renderização.
|
|
49
|
+
|
|
50
|
+
## Instalação
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
pnpm add -D @intlayer/sync-json-plugin
|
|
54
|
+
# ou
|
|
55
|
+
npm i -D @intlayer/sync-json-plugin
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Início rápido
|
|
59
|
+
|
|
60
|
+
Adicione o plugin ao seu `intlayer.config.ts` e aponte para sua estrutura JSON existente.
|
|
61
|
+
|
|
62
|
+
```ts fileName="intlayer.config.ts"
|
|
63
|
+
import { defineConfig, Locales } from "intlayer";
|
|
64
|
+
import { syncJSON } from "@intlayer/sync-json-plugin";
|
|
65
|
+
|
|
66
|
+
export default defineConfig({
|
|
67
|
+
internationalization: {
|
|
68
|
+
locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH],
|
|
69
|
+
defaultLocale: Locales.ENGLISH,
|
|
70
|
+
},
|
|
71
|
+
|
|
72
|
+
// Mantenha seus arquivos JSON atuais sincronizados com os dicionários Intlayer
|
|
73
|
+
plugins: [
|
|
74
|
+
syncJSON({
|
|
75
|
+
// Layout por localidade, por namespace (por exemplo, next-intl, i18next com namespaces)
|
|
76
|
+
source: ({ key, locale }) => `./locales/${locale}/${key}.json`,
|
|
77
|
+
}),
|
|
78
|
+
],
|
|
79
|
+
});
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Alternativa: arquivo único por localidade (comum em configurações i18next/react-intl):
|
|
83
|
+
|
|
84
|
+
```ts fileName="intlayer.config.ts"
|
|
85
|
+
plugins: [
|
|
86
|
+
syncJSON({
|
|
87
|
+
source: ({ locale }) => `./locales/${locale}.json`,
|
|
88
|
+
}),
|
|
89
|
+
];
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Como funciona
|
|
93
|
+
|
|
94
|
+
- Leitura: o plugin descobre arquivos JSON a partir do seu construtor `source` e os carrega como dicionários Intlayer.
|
|
95
|
+
- Escrita: após builds e preenchimentos, ele grava o JSON localizado de volta nos mesmos caminhos (com uma nova linha final para evitar problemas de formatação).
|
|
96
|
+
- Auto-preenchimento: o plugin declara um caminho `autoFill` para cada dicionário. Executar `intlayer fill` atualiza apenas as traduções ausentes nos seus arquivos JSON por padrão.
|
|
97
|
+
|
|
98
|
+
API:
|
|
99
|
+
|
|
100
|
+
```ts
|
|
101
|
+
syncJSON({
|
|
102
|
+
source: ({ key, locale }) => string, // obrigatório
|
|
103
|
+
location?: string, // rótulo opcional, padrão: "plugin"
|
|
104
|
+
priority?: number, // prioridade opcional para resolução de conflitos, padrão: 0
|
|
105
|
+
});
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Múltiplas fontes JSON e prioridade
|
|
109
|
+
|
|
110
|
+
Você pode adicionar múltiplos plugins `syncJSON` para sincronizar diferentes fontes JSON. Isso é útil quando você tem múltiplas bibliotecas i18n ou diferentes estruturas JSON no seu projeto.
|
|
111
|
+
|
|
112
|
+
### Sistema de prioridade
|
|
113
|
+
|
|
114
|
+
Quando múltiplos plugins têm como alvo a mesma chave de dicionário, o parâmetro `priority` determina qual plugin tem precedência:
|
|
115
|
+
|
|
116
|
+
- Números de prioridade mais altos ganham sobre os mais baixos
|
|
117
|
+
- Prioridade padrão dos arquivos `.content` é `0`
|
|
118
|
+
- Prioridade padrão dos arquivos de conteúdo dos plugins é `-1`
|
|
119
|
+
- Plugins com a mesma prioridade são processados na ordem em que aparecem na configuração
|
|
120
|
+
|
|
121
|
+
```ts fileName="intlayer.config.ts"
|
|
122
|
+
import { defineConfig, Locales } from "intlayer";
|
|
123
|
+
import { syncJSON } from "@intlayer/sync-json-plugin";
|
|
124
|
+
|
|
125
|
+
export default defineConfig({
|
|
126
|
+
internationalization: {
|
|
127
|
+
locales: [Locales.ENGLISH, Locales.FRENCH],
|
|
128
|
+
defaultLocale: Locales.ENGLISH,
|
|
129
|
+
},
|
|
130
|
+
|
|
131
|
+
plugins: [
|
|
132
|
+
// Fonte JSON principal (maior prioridade)
|
|
133
|
+
syncJSON({
|
|
134
|
+
source: ({ key, locale }) => `./locales/${locale}/${key}.json`,
|
|
135
|
+
location: "main-translations",
|
|
136
|
+
priority: 10,
|
|
137
|
+
}),
|
|
138
|
+
|
|
139
|
+
// Fonte JSON de fallback (prioridade menor)
|
|
140
|
+
syncJSON({
|
|
141
|
+
source: ({ locale }) => `./fallback-locales/${locale}.json`,
|
|
142
|
+
location: "fallback-translations",
|
|
143
|
+
priority: 5,
|
|
144
|
+
}),
|
|
145
|
+
|
|
146
|
+
// Fonte JSON legado (prioridade mais baixa)
|
|
147
|
+
syncJSON({
|
|
148
|
+
source: ({ locale }) => `/my/other/app/legacy/${locale}/messages.json`,
|
|
149
|
+
location: "legacy-translations",
|
|
150
|
+
priority: 1,
|
|
151
|
+
}),
|
|
152
|
+
],
|
|
153
|
+
});
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### Resolução de conflitos
|
|
157
|
+
|
|
158
|
+
Quando a mesma chave de tradução existe em múltiplas fontes JSON:
|
|
159
|
+
|
|
160
|
+
1. O plugin com a maior prioridade determina o valor final
|
|
161
|
+
2. Fontes com prioridade menor são usadas como fallback para chaves ausentes
|
|
162
|
+
3. Isso permite manter traduções legadas enquanto migra gradualmente para novas estruturas
|
|
163
|
+
|
|
164
|
+
## Integrações
|
|
165
|
+
|
|
166
|
+
Abaixo estão mapeamentos comuns. Mantenha seu runtime intacto; apenas adicione o plugin.
|
|
167
|
+
|
|
168
|
+
### i18next
|
|
169
|
+
|
|
170
|
+
Layout típico de arquivo: `./public/locales/{locale}/{namespace}.json` ou `./locales/{locale}/{namespace}.json`.
|
|
171
|
+
|
|
172
|
+
```ts fileName="intlayer.config.ts"
|
|
173
|
+
import { syncJSON } from "@intlayer/sync-json-plugin";
|
|
174
|
+
|
|
175
|
+
export default {
|
|
176
|
+
plugins: [
|
|
177
|
+
syncJSON({
|
|
178
|
+
source: ({ key, locale }) => `./locales/${locale}/${key}.json`,
|
|
179
|
+
}),
|
|
180
|
+
],
|
|
181
|
+
};
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### next-intl
|
|
185
|
+
|
|
186
|
+
Mensagens JSON por localidade (frequentemente `./messages/{locale}.json`) ou por namespace.
|
|
187
|
+
|
|
188
|
+
```ts fileName="intlayer.config.ts"
|
|
189
|
+
plugins: [
|
|
190
|
+
syncJSON({
|
|
191
|
+
source: ({ locale, key }) => `./messages/${locale}/${key}.json`,
|
|
192
|
+
}),
|
|
193
|
+
];
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
Veja também: `docs/pt/intlayer_with_next-intl.md`.
|
|
197
|
+
|
|
198
|
+
### react-intl
|
|
199
|
+
|
|
200
|
+
JSON único por localidade é comum:
|
|
201
|
+
|
|
202
|
+
```ts fileName="intlayer.config.ts"
|
|
203
|
+
plugins: [
|
|
204
|
+
syncJSON({
|
|
205
|
+
source: ({ locale }) => `./locales/${locale}.json`,
|
|
206
|
+
}),
|
|
207
|
+
];
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
### vue-i18n
|
|
211
|
+
|
|
212
|
+
Pode ser um único arquivo por localidade ou por namespace:
|
|
213
|
+
|
|
214
|
+
```ts fileName="intlayer.config.ts"
|
|
215
|
+
plugins: [
|
|
216
|
+
syncJSON({
|
|
217
|
+
source: ({ key, locale }) => `./src/locales/${locale}/${key}.json`,
|
|
218
|
+
}),
|
|
219
|
+
];
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
## CLI
|
|
223
|
+
|
|
224
|
+
Os arquivos JSON sincronizados serão considerados como outros arquivos `.content`. Isso significa que todos os comandos do intlayer estarão disponíveis para os arquivos JSON sincronizados. Incluindo:
|
|
225
|
+
|
|
226
|
+
- `intlayer content test` para testar se há traduções faltando
|
|
227
|
+
- `intlayer content list` para listar os arquivos JSON sincronizados
|
|
228
|
+
- `intlayer content fill` para preencher as traduções faltantes
|
|
229
|
+
- `intlayer content push` para enviar os arquivos JSON sincronizados
|
|
230
|
+
- `intlayer content pull` para puxar os arquivos JSON sincronizados
|
|
231
|
+
|
|
232
|
+
Veja [Intlayer CLI](https://github.com/aymericzip/intlayer/blob/main/docs/docs/pt/intlayer_cli.md) para mais detalhes.
|
|
233
|
+
|
|
234
|
+
## Limitações (atuais)
|
|
235
|
+
|
|
236
|
+
- Sem suporte para inserções ou plurais/ICU ao direcionar bibliotecas de terceiros.
|
|
237
|
+
- Editor visual ainda não disponível para runtimes que não sejam Intlayer.
|
|
238
|
+
- Sincronização apenas de JSON; formatos de catálogo não JSON não são suportados.
|
|
239
|
+
|
|
240
|
+
## Por que isso importa
|
|
241
|
+
|
|
242
|
+
- Podemos recomendar soluções i18n consolidadas e posicionar o Intlayer como um complemento.
|
|
243
|
+
- Aproveitamos o SEO/palavras-chave delas com tutoriais que terminam sugerindo o Intlayer para gerenciar JSON.
|
|
244
|
+
- Expande o público-alvo de “novos projetos” para “qualquer equipe que já usa i18n”.
|