@intlayer/docs 9.0.2 → 9.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/dist/cjs/generated/docs.entry.cjs +20 -0
  2. package/dist/cjs/generated/docs.entry.cjs.map +1 -1
  3. package/dist/esm/generated/docs.entry.mjs +20 -0
  4. package/dist/esm/generated/docs.entry.mjs.map +1 -1
  5. package/dist/types/generated/docs.entry.d.ts +1 -0
  6. package/dist/types/generated/docs.entry.d.ts.map +1 -1
  7. package/docs/ar/dictionary/content_file.md +24 -1
  8. package/docs/ar/dictionary/select.md +386 -0
  9. package/docs/de/dictionary/content_file.md +24 -1
  10. package/docs/de/dictionary/select.md +386 -0
  11. package/docs/en/dictionary/content_file.md +24 -1
  12. package/docs/en/dictionary/select.md +382 -0
  13. package/docs/en-GB/dictionary/content_file.md +24 -1
  14. package/docs/en-GB/dictionary/select.md +385 -0
  15. package/docs/es/dictionary/content_file.md +24 -1
  16. package/docs/es/dictionary/select.md +385 -0
  17. package/docs/fr/dictionary/content_file.md +24 -1
  18. package/docs/fr/dictionary/select.md +382 -0
  19. package/docs/hi/dictionary/content_file.md +24 -1
  20. package/docs/hi/dictionary/select.md +386 -0
  21. package/docs/id/dictionary/content_file.md +24 -1
  22. package/docs/id/dictionary/select.md +386 -0
  23. package/docs/it/dictionary/content_file.md +24 -1
  24. package/docs/it/dictionary/select.md +386 -0
  25. package/docs/ja/dictionary/content_file.md +24 -1
  26. package/docs/ja/dictionary/select.md +386 -0
  27. package/docs/ko/dictionary/content_file.md +24 -1
  28. package/docs/ko/dictionary/select.md +386 -0
  29. package/docs/pl/dictionary/content_file.md +24 -1
  30. package/docs/pl/dictionary/select.md +386 -0
  31. package/docs/pt/dictionary/content_file.md +24 -1
  32. package/docs/pt/dictionary/select.md +386 -0
  33. package/docs/ru/dictionary/content_file.md +25 -2
  34. package/docs/ru/dictionary/select.md +386 -0
  35. package/docs/tr/dictionary/content_file.md +24 -1
  36. package/docs/tr/dictionary/select.md +386 -0
  37. package/docs/uk/dictionary/content_file.md +24 -1
  38. package/docs/uk/dictionary/select.md +386 -0
  39. package/docs/vi/dictionary/content_file.md +24 -1
  40. package/docs/vi/dictionary/select.md +386 -0
  41. package/docs/zh/dictionary/content_file.md +24 -1
  42. package/docs/zh/dictionary/select.md +387 -0
  43. package/package.json +7 -7
  44. package/src/generated/docs.entry.ts +20 -0
@@ -0,0 +1,386 @@
1
+ ---
2
+ createdAt: 2026-07-30
3
+ updatedAt: 2026-07-30
4
+ title: Konten Berbasis Pilihan (Select)
5
+ description: Pelajari cara menggunakan konten berbasis pilihan di Intlayer untuk menampilkan konten secara dinamis berdasarkan nilai string sembarang. Ikuti dokumentasi ini untuk mengimplementasikan konten mirip switch secara efisien dalam proyek Anda.
6
+ keywords:
7
+ - Konten berbasis pilihan
8
+ - Select Content
9
+ - Konten Switch
10
+ - ICU select
11
+ - Rendering dinamis
12
+ - Dokumentasi
13
+ - Intlayer
14
+ - Next.js
15
+ - JavaScript
16
+ - React
17
+ slugs:
18
+ - doc
19
+ - concept
20
+ - content
21
+ - select
22
+ history:
23
+ - version: 9.1.0
24
+ date: 2026-07-30
25
+ changes: "Memperkenalkan konten berbasis pilihan"
26
+ author: aymericzip
27
+ ---
28
+
29
+ # Konten Berbasis Pilihan (Select) / Intlayer
30
+
31
+ ## Cara Kerja Select
32
+
33
+ Dalam Intlayer, konten berbasis pilihan (select) dicapai melalui fungsi `select`, yang memetakan nilai string sembarang ke konten yang sesuai. Ini setara dengan pesan ICU `{value, select, …}`, atau pernyataan `switch` dalam kode aplikasi Anda.
34
+
35
+ Gunakan `select` ketika penentu (discriminant) adalah string berbentuk bebas: sebuah status, paket berlangganan, platform, atau peran. Untuk penentu lainnya, Intlayer menyediakan node khusus:
36
+
37
+ | Penentu | Node |
38
+ | -------------- | ---------- |
39
+ | Kuantitas | `enu()` |
40
+ | Boolean | `cond()` |
41
+ | Gender | `gender()` |
42
+ | String lainnya | `select()` |
43
+
44
+ ## Menyiapkan Konten Berbasis Pilihan
45
+
46
+ Untuk menyiapkan konten berbasis pilihan di proyek Intlayer Anda, buat modul konten yang menyertakan definisi pilihan Anda. Di bawah ini adalah contoh dalam berbagai format.
47
+
48
+ ```typescript fileName="**/*.content.ts" contentDeclarationFormat={["typescript", "esm", "commonjs"]}
49
+ import { select, type Dictionary } from "intlayer";
50
+
51
+ const myPostContent = {
52
+ key: "my_key",
53
+ content: {
54
+ publishStatus: select({
55
+ draft: "This post is a draft",
56
+ published: "This post is live",
57
+ scheduled: "This post is scheduled",
58
+ fallback: "Unknown status", // opsional
59
+ }),
60
+ },
61
+ } satisfies Dictionary;
62
+
63
+ export default myPostContent;
64
+ ```
65
+
66
+ ```json5 fileName="**/*.content.json" contentDeclarationFormat="json"
67
+ {
68
+ "$schema": "https://intlayer.org/schema.json",
69
+ "key": "my_key",
70
+ "content": {
71
+ "publishStatus": {
72
+ "nodeType": "select",
73
+ "select": {
74
+ "draft": "This post is a draft",
75
+ "published": "This post is live",
76
+ "scheduled": "This post is scheduled",
77
+ "fallback": "Unknown status", // opsional
78
+ },
79
+ },
80
+ },
81
+ }
82
+ ```
83
+
84
+ > Jika tidak ada `fallback` yang dideklarasikan, kunci yang dideklarasikan terakhir akan dianggap sebagai fallback ketika nilai yang diberikan tidak cocok dengan kasus mana pun yang dideklarasikan: persis seperti kontrak `cond()` dan `gender()`.
85
+
86
+ ### Type Safety
87
+
88
+ Argumen yang diterima disimpulkan dari kasus yang dideklarasikan:
89
+
90
+ - Tanpa `fallback`, hanya kasus yang dideklarasikan yang diterima: salah ketik akan menghasilkan kesalahan tipe (type error).
91
+ - Dengan `fallback`, string apa pun akan diterima (karena fallback mencakup nilai yang tidak cocok) sementara kasus yang dideklarasikan tetap menyediakan pelengkapan otomatis (autocompletion).
92
+
93
+ ## Mengapa Tidak Menggunakan Objek Biasa?
94
+
95
+ Sangat menggoda untuk mendeklarasikan objek biasa dan mengindeksnya menggunakan nilai saat runtime (runtime value):
96
+
97
+ ```tsx
98
+ // ❌ Jangan lakukan ini
99
+ const { publishStatus } = useIntlayer("my_key");
100
+
101
+ return <p>{publishStatus[publishType]}</p>;
102
+ ```
103
+
104
+ Kompilator (compiler) Intlayer menganalisis kode sumber Anda untuk menghapus konten yang tidak digunakan dan memperkecil (minify) kunci yang tersisa. Akses terkomputasi dinamis (`obj[expr]`) tidak dapat dianalisis secara statis, sehingga seluruh cabang akan ditandai sebagai opak (opaque): cabang tersebut akan tetap ada di dalam bundle dan kuncinya tidak akan diperkecil.
105
+
106
+ Dengan menggunakan `select()`, resolusi kasus terjadi di dalam pemanggilan fungsi alih-alih sebagai akses properti. Kompilator melihatnya sebagai akses bidang statis tunggal, dan mengoptimalkan node secara akurat, persis seperti yang dilakukannya dengan `enu()`, `cond()`, atau `gender()`:
107
+
108
+ ```tsx
109
+ // ✅ Lakukan ini
110
+ const { publishStatus } = useIntlayer("my_key");
111
+
112
+ return <p>{publishStatus(publishType)}</p>;
113
+ ```
114
+
115
+ ## Menggunakan Konten Berbasis Pilihan
116
+
117
+ <Tabs group="framework">
118
+ <Tab label="React" value="react">
119
+
120
+ Untuk memanfaatkan konten berbasis pilihan dalam komponen React, impor dan gunakan hook `useIntlayer` dari paket `react-intlayer`. Hook ini mengambil konten untuk kunci yang ditentukan dan memungkinkan Anda meneruskan nilai untuk memilih output yang sesuai.
121
+
122
+ ```tsx fileName="**/*.tsx" codeFormat={["typescript", "esm"]}
123
+ import type { FC } from "react";
124
+ import { useIntlayer } from "react-intlayer";
125
+
126
+ const PostStatus: FC = () => {
127
+ const { publishStatus } = useIntlayer("my_key");
128
+
129
+ return (
130
+ <div>
131
+ <p>
132
+ {
133
+ /* Output: This post is a draft */
134
+ publishStatus("draft")
135
+ }
136
+ </p>
137
+ <p>
138
+ {
139
+ /* Output: This post is live */
140
+ publishStatus("published")
141
+ }
142
+ </p>
143
+ <p>
144
+ {
145
+ /* Output: Unknown status */
146
+ publishStatus("Archived")
147
+ }
148
+ </p>
149
+ </div>
150
+ );
151
+ };
152
+
153
+ export default PostStatus;
154
+ ```
155
+
156
+ </Tab>
157
+ <Tab label="Next.js" value="nextjs">
158
+
159
+ Untuk memanfaatkan konten berbasis pilihan dalam Komponen Klien (Client Components) Next.js, ambil konten tersebut melalui hook `useIntlayer`. Berikut adalah contohnya:
160
+
161
+ ```tsx fileName="**/*.tsx" codeFormat={["typescript", "esm"]}
162
+ "use client";
163
+
164
+ import type { FC } from "react";
165
+ import { useIntlayer } from "next-intlayer";
166
+
167
+ const PostStatus: FC = () => {
168
+ const { publishStatus } = useIntlayer("my_key");
169
+
170
+ return (
171
+ <div>
172
+ <p>{publishStatus("draft")}</p>
173
+ <p>{publishStatus("published")}</p>
174
+ </div>
175
+ );
176
+ };
177
+
178
+ export default PostStatus;
179
+ ```
180
+
181
+ </Tab>
182
+ <Tab label="Vue" value="vue">
183
+
184
+ Untuk memanfaatkan konten berbasis pilihan dalam komponen Vue, ambil konten tersebut melalui hook `useIntlayer`. Berikut adalah contohnya:
185
+
186
+ ```vue fileName="**/*.vue"
187
+ <script setup lang="ts">
188
+ import { useIntlayer } from "vue-intlayer";
189
+
190
+ const { publishStatus } = useIntlayer("my_key");
191
+ </script>
192
+
193
+ <template>
194
+ <div>
195
+ <p>{{ publishStatus("draft") }}</p>
196
+ <p>{{ publishStatus("published") }}</p>
197
+ </div>
198
+ </template>
199
+ ```
200
+
201
+ </Tab>
202
+ <Tab label="Svelte" value="svelte">
203
+
204
+ Untuk memanfaatkan konten berbasis pilihan dalam komponen Svelte, ambil konten tersebut melalui hook `useIntlayer`. Store diakses menggunakan `$`. Berikut adalah contohnya:
205
+
206
+ ```svelte fileName="**/*.svelte"
207
+ <script lang="ts">
208
+ import { useIntlayer } from "svelte-intlayer";
209
+
210
+ const content = useIntlayer("my_key");
211
+ </script>
212
+
213
+ <div>
214
+ <p>{$content.publishStatus("draft")}</p>
215
+ <p>{$content.publishStatus("published")}</p>
216
+ </div>
217
+ ```
218
+
219
+ </Tab>
220
+ <Tab label="Preact" value="preact">
221
+
222
+ Untuk memanfaatkan konten berbasis pilihan dalam komponen Preact, ambil konten tersebut melalui hook `useIntlayer`. Berikut adalah contohnya:
223
+
224
+ ```tsx fileName="**/*.tsx" codeFormat={["typescript", "esm"]}
225
+ import type { FC } from "preact";
226
+ import { useIntlayer } from "preact-intlayer";
227
+
228
+ const PostStatus: FC = () => {
229
+ const { publishStatus } = useIntlayer("my_key");
230
+
231
+ return (
232
+ <div>
233
+ <p>{publishStatus("draft")}</p>
234
+ <p>{publishStatus("published")}</p>
235
+ </div>
236
+ );
237
+ };
238
+
239
+ export default PostStatus;
240
+ ```
241
+
242
+ </Tab>
243
+ <Tab label="Solid" value="solid">
244
+
245
+ Untuk memanfaatkan konten berbasis pilihan dalam komponen SolidJS, ambil konten tersebut melalui hook `useIntlayer`. Berikut adalah contohnya:
246
+
247
+ ```tsx fileName="**/*.tsx" codeFormat={["typescript", "esm"]}
248
+ import type { Component } from "solid-js";
249
+ import { useIntlayer } from "solid-intlayer";
250
+
251
+ const PostStatus: Component = () => {
252
+ const { publishStatus } = useIntlayer("my_key");
253
+
254
+ return (
255
+ <div>
256
+ <p>{publishStatus("draft")}</p>
257
+ <p>{publishStatus("published")}</p>
258
+ </div>
259
+ );
260
+ };
261
+
262
+ export default PostStatus;
263
+ ```
264
+
265
+ </Tab>
266
+ <Tab label="Angular" value="angular">
267
+
268
+ Untuk memanfaatkan konten berbasis pilihan dalam komponen Angular, ambil konten tersebut melalui hook `useIntlayer`. Berikut adalah contohnya:
269
+
270
+ ```typescript fileName="app.component.ts" codeFormat="typescript"
271
+ import { Component } from "@angular/core";
272
+ import { useIntlayer } from "angular-intlayer";
273
+
274
+ @Component({
275
+ selector: "app-post-status",
276
+ template: `
277
+ <div>
278
+ <p>{{ content().publishStatus("draft") }}</p>
279
+ <p>{{ content().publishStatus("published") }}</p>
280
+ </div>
281
+ `,
282
+ })
283
+ export class PostStatusComponent {
284
+ content = useIntlayer("my_key");
285
+ }
286
+ ```
287
+
288
+ </Tab>
289
+ <Tab label="Vanilla JS" value="vanilla">
290
+
291
+ Untuk memanfaatkan konten berbasis pilihan dengan `vanilla-intlayer`, ambil konten tersebut melalui hook `useIntlayer`. Berikut adalah contohnya:
292
+
293
+ ```typescript fileName="**/*.ts" codeFormat={["typescript", "esm"]}
294
+ import { installIntlayer, useIntlayer } from "vanilla-intlayer";
295
+
296
+ installIntlayer();
297
+
298
+ const content = useIntlayer("my_key").onChange((newContent) => {
299
+ document.getElementById("status")!.textContent =
300
+ newContent.publishStatus("draft");
301
+ });
302
+
303
+ // Render awal
304
+ document.getElementById("status")!.textContent = content.publishStatus("draft");
305
+ ```
306
+
307
+ </Tab>
308
+ </Tabs>
309
+
310
+ ## Menggabungkan Select dengan Node Lain
311
+
312
+ Karena setiap kasus berisi node konten penuh, `select` dapat dikombinasikan dengan `t()`, `insert()`, `md()`, dll:
313
+
314
+ ```typescript fileName="**/*.content.ts" codeFormat="typescript"
315
+ import { insert, select, t, type Dictionary } from "intlayer";
316
+
317
+ const myPostContent = {
318
+ key: "my_key",
319
+ content: {
320
+ publishStatus: select({
321
+ draft: insert(
322
+ t({
323
+ en: "{{name}} saved a draft",
324
+ fr: "{{name}} a enregistré un brouillon",
325
+ id: "{{name}} menyimpan draf",
326
+ })
327
+ ),
328
+ published: insert(
329
+ t({
330
+ en: "{{name}} published the post",
331
+ fr: "{{name}} a publié l’article",
332
+ id: "{{name}} memublikasikan postingan",
333
+ })
334
+ ),
335
+ fallback: insert(
336
+ t({
337
+ en: "{{name}} updated the post",
338
+ fr: "{{name}} a mis à jour l’article",
339
+ id: "{{name}} memperbarui postingan",
340
+ })
341
+ ),
342
+ }),
343
+ },
344
+ } satisfies Dictionary;
345
+
346
+ export default myPostContent;
347
+ ```
348
+
349
+ ```tsx
350
+ publishStatus("draft")({ name: "Alice" }); // Output: Alice menyimpan draf
351
+ ```
352
+
353
+ ## Migrasi dari ICU `select`
354
+
355
+ Pesan yang menggunakan argumen `select` dari ICU diimpor sebagai node `select`:
356
+
357
+ ```text
358
+ {publishType, select, draft {draft} published {published} other {Unknown}}
359
+ ```
360
+
361
+ Akan menjadi:
362
+
363
+ ```typescript
364
+ select(
365
+ {
366
+ draft: "draft",
367
+ published: "published",
368
+ fallback: "Unknown",
369
+ },
370
+ "publishType"
371
+ );
372
+ ```
373
+
374
+ Kasus `other` pada ICU dinamai ulang menjadi `fallback`, nama kanonikal di Intlayer untuk semua kasus tangkapan-semua (catch-all). Argumen kedua mencatat nama variabel ICU sehingga saat diekspor, pesan tersebut berubah kembali menjadi string ICU yang sama persis.
375
+
376
+ > Sebagai catatan, pernyataan ICU `select` di mana kasusnya adalah nilai gender (`male` / `female` / `other`) akan diimpor sebagai node [`gender`](https://github.com/aymericzip/intlayer/blob/main/docs/docs/id/dictionary/gender.md).
377
+
378
+ ## Sumber Daya Tambahan
379
+
380
+ Untuk informasi lebih rinci mengenai konfigurasi dan penggunaan, lihat sumber daya berikut:
381
+
382
+ - [Dokumentasi Intlayer CLI](https://github.com/aymericzip/intlayer/blob/main/docs/docs/id/cli/index.md)
383
+ - [Dokumentasi Intlayer React](https://github.com/aymericzip/intlayer/blob/main/docs/docs/id/intlayer_with_create_react_app.md)
384
+ - [Dokumentasi Intlayer Next.js](https://github.com/aymericzip/intlayer/blob/main/docs/docs/id/intlayer_with_nextjs_15.md)
385
+
386
+ Sumber daya ini memberikan wawasan lebih lanjut tentang cara menyiapkan dan menggunakan Intlayer dalam berbagai lingkungan dan kerangka kerja.
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  createdAt: 2025-02-07
3
- updatedAt: 2026-05-12
3
+ updatedAt: 2026-07-30
4
4
  title: File di Contenuto
5
5
  description: Scopri come personalizzare le estensioni per i tuoi file di dichiarazione dei contenuti. Segui questa documentazione per implementare condizioni in modo efficiente nel tuo progetto.
6
6
  keywords:
@@ -12,6 +12,9 @@ slugs:
12
12
  - concept
13
13
  - content
14
14
  history:
15
+ - version: 9.1.0
16
+ date: 2026-07-30
17
+ changes: "Introdotto il contenuto basato su selezione"
15
18
  - version: 8.10.0
16
19
  date: 2026-05-19
17
20
  changes: "Aggiunto supporto per i formati di file YAML e Markdown"
@@ -254,6 +257,7 @@ Intlayer supporta vari tipi di contenuto tramite nodi tipizzati:
254
257
  - **Contenuto HTML**: Contenuto HTML ricco con componenti personalizzati opzionali [vedi Contenuto HTML](https://github.com/aymericzip/intlayer/blob/main/docs/docs/it/dictionary/html.md)
255
258
  - **Contenuto Annidato**: Riferimenti ad altri dizionari [vedi Contenuto Annidato](https://github.com/aymericzip/intlayer/blob/main/docs/docs/it/dictionary/nested_content.md)
256
259
  - **Contenuto di Genere**: Contenuto che varia in base al genere [vedi Contenuto di Genere](https://github.com/aymericzip/intlayer/blob/main/docs/docs/it/dictionary/gender_content.md)
260
+ - **Contenuto Basato su Selezione**: Contenuto che varia in base a un valore stringa arbitrario [vedi Contenuto Basato su Selezione](https://github.com/aymericzip/intlayer/blob/main/docs/docs/it/dictionary/select.md)
257
261
  - **Contenuto File**: Riferimenti a file esterni [vedi Contenuto File](https://github.com/aymericzip/intlayer/blob/main/docs/docs/it/dictionary/file_content.md)
258
262
 
259
263
  ## Struttura del Dizionario
@@ -743,6 +747,25 @@ genderContent: gender({
743
747
 
744
748
  > Vedere [Contenuto per Genere (`gender`) Doc](https://github.com/aymericzip/intlayer/blob/main/docs/docs/it/dictionary/gender.md) per ulteriori informazioni.
745
749
 
750
+ ### Contenuto Basato su Selezione (`select`)
751
+
752
+ Contenuto che varia in base a un valore stringa arbitrario — l'equivalente del `select` di ICU:
753
+
754
+ ```typescript
755
+ import { select } from "intlayer";
756
+
757
+ selectContent: select({
758
+ draft: "This post is a draft",
759
+ published: "This post is live",
760
+ scheduled: "This post is scheduled",
761
+ fallback: "Unknown status",
762
+ });
763
+ ```
764
+
765
+ Usa `select` quando il discriminante non è una quantità (`enu`), non è un booleano (`cond`), né un genere (`gender`). Preferiscilo all'indicizzazione di un semplice oggetto con un valore a runtime: il compilatore di Intlayer non può risolvere staticamente un accesso computato dinamico.
766
+
767
+ > Vedere [Contenuto Basato su Selezione](https://github.com/aymericzip/intlayer/blob/main/docs/docs/it/dictionary/select.md) per ulteriori informazioni.
768
+
746
769
  ### Contenuto da File (`file`)
747
770
 
748
771
  Riferimenti a file esterni: