@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: Contenuto Basato su Selezione
5
+ description: Scopri come utilizzare il contenuto basato su selezione in Intlayer per visualizzare contenuti dinamicamente in base a un valore stringa arbitrario. Segui questa documentazione per implementare in modo efficiente contenuti simili a switch nel tuo progetto.
6
+ keywords:
7
+ - Contenuto Basato su Selezione
8
+ - Select Content
9
+ - Contenuto Switch
10
+ - ICU select
11
+ - Rendering Dinamico
12
+ - Documentazione
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: "Introdotto il contenuto basato su selezione"
26
+ author: aymericzip
27
+ ---
28
+
29
+ # Contenuto Basato su Selezione / Select in Intlayer
30
+
31
+ ## Come funziona Select
32
+
33
+ In Intlayer, il contenuto basato su selezione si ottiene tramite la funzione `select`, che mappa valori stringa arbitrari al rispettivo contenuto. È l'equivalente di un messaggio `{value, select, …}` di ICU, o di un'istruzione `switch` nel codice della tua applicazione.
34
+
35
+ Usa `select` quando il discriminante è una stringa in formato libero: uno stato, un piano, una piattaforma, un ruolo. Per gli altri discriminanti, Intlayer fornisce nodi dedicati:
36
+
37
+ | Discriminante | Nodo |
38
+ | ----------------------- | ---------- |
39
+ | Una quantità | `enu()` |
40
+ | Un booleano | `cond()` |
41
+ | Un genere | `gender()` |
42
+ | Qualsiasi altra stringa | `select()` |
43
+
44
+ ## Impostazione del Contenuto Basato su Selezione
45
+
46
+ Per impostare il contenuto basato su selezione nel tuo progetto Intlayer, crea un modulo di contenuto che includa le tue definizioni di selezione. Di seguito sono riportati esempi in vari formati.
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", // Opzionale
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", // Opzionale
78
+ },
79
+ },
80
+ },
81
+ }
82
+ ```
83
+
84
+ > Se non viene dichiarato un `fallback`, l'ultima chiave dichiarata verrà utilizzata come fallback quando il valore fornito non corrisponde ad alcun caso dichiarato: lo stesso contratto di `cond()` e `gender()`.
85
+
86
+ ### Sicurezza dei Tipi
87
+
88
+ L'argomento accettato viene dedotto dai casi dichiarati:
89
+
90
+ - Senza un `fallback`, sono accettati solo i casi dichiarati: un errore di battitura è un errore di tipo.
91
+ - Con un `fallback`, viene accettata qualsiasi stringa (il fallback copre i valori non corrispondenti), mentre i casi dichiarati offrono comunque l'autocompletamento.
92
+
93
+ ## Perché non un semplice oggetto?
94
+
95
+ È allettante dichiarare un semplice oggetto e indicizzarlo con il valore a runtime:
96
+
97
+ ```tsx
98
+ // ❌ Non fare questo
99
+ const { publishStatus } = useIntlayer("my_key");
100
+
101
+ return <p>{publishStatus[publishType]}</p>;
102
+ ```
103
+
104
+ Il compilatore di Intlayer analizza il tuo codice sorgente per eliminare il contenuto inutilizzato e minimizzare le chiavi rimanenti. Un accesso computato dinamico (`obj[expr]`) non può essere risolto staticamente, per cui l'intero ramo viene contrassegnato come opaco: viene mantenuto nel bundle e le sue chiavi restano non minimizzate.
105
+
106
+ Con `select()`, la risoluzione del caso avviene all'interno di una chiamata a funzione anziché come accesso a una proprietà. Il compilatore vede un singolo accesso di campo statico e ottimizza il nodo esattamente come `enu()`, `cond()` o `gender()`:
107
+
108
+ ```tsx
109
+ // ✅ Fai questo
110
+ const { publishStatus } = useIntlayer("my_key");
111
+
112
+ return <p>{publishStatus(publishType)}</p>;
113
+ ```
114
+
115
+ ## Utilizzo del Contenuto Basato su Selezione
116
+
117
+ <Tabs group="framework">
118
+ <Tab label="React" value="react">
119
+
120
+ Per utilizzare il contenuto basato su selezione all'interno di un componente React, importa e usa l'hook `useIntlayer` dal pacchetto `react-intlayer`. Questo hook recupera il contenuto per la chiave specificata e ti consente di passare un valore per selezionare l'output appropriato.
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
+ Per utilizzare il contenuto basato su selezione all'interno dei componenti client Next.js, recuperalo tramite l'hook `useIntlayer`. Ecco un esempio:
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
+ Per utilizzare il contenuto basato su selezione all'interno dei componenti Vue, recuperalo tramite l'hook `useIntlayer`. Ecco un esempio:
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
+ Per utilizzare il contenuto basato su selezione all'interno dei componenti Svelte, recuperalo tramite l'hook `useIntlayer`. Si accede allo store utilizzando `$`. Ecco un esempio:
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
+ Per utilizzare il contenuto basato su selezione all'interno dei componenti Preact, recuperalo tramite l'hook `useIntlayer`. Ecco un esempio:
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
+ Per utilizzare il contenuto basato su selezione all'interno dei componenti SolidJS, recuperalo tramite l'hook `useIntlayer`. Ecco un esempio:
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
+ Per utilizzare il contenuto basato su selezione all'interno dei componenti Angular, recuperalo tramite l'hook `useIntlayer`. Ecco un esempio:
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
+ Per utilizzare il contenuto basato su selezione con `vanilla-intlayer`, recuperalo tramite l'hook `useIntlayer`. Ecco un esempio:
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
+ // Rendering iniziale
304
+ document.getElementById("status")!.textContent = content.publishStatus("draft");
305
+ ```
306
+
307
+ </Tab>
308
+ </Tabs>
309
+
310
+ ## Combinare Select con altri nodi
311
+
312
+ Ciascun caso contiene un nodo di contenuto completo, pertanto `select` si combina con `t()`, `insert()`, `md()` e gli altri:
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
+ it: "{{name}} ha salvato una bozza",
326
+ })
327
+ ),
328
+ published: insert(
329
+ t({
330
+ en: "{{name}} published the post",
331
+ fr: "{{name}} a publié l’article",
332
+ it: "{{name}} ha pubblicato il post",
333
+ })
334
+ ),
335
+ fallback: insert(
336
+ t({
337
+ en: "{{name}} updated the post",
338
+ fr: "{{name}} a mis à jour l’article",
339
+ it: "{{name}} ha aggiornato il post",
340
+ })
341
+ ),
342
+ }),
343
+ },
344
+ } satisfies Dictionary;
345
+
346
+ export default myPostContent;
347
+ ```
348
+
349
+ ```tsx
350
+ publishStatus("draft")({ name: "Alice" }); // Output: Alice ha salvato una bozza
351
+ ```
352
+
353
+ ## Migrazione da ICU `select`
354
+
355
+ I messaggi che utilizzano l'argomento `select` di ICU vengono importati come nodi `select`:
356
+
357
+ ```text
358
+ {publishType, select, draft {draft} published {published} other {Unknown}}
359
+ ```
360
+
361
+ diventa
362
+
363
+ ```typescript
364
+ select(
365
+ {
366
+ draft: "draft",
367
+ published: "published",
368
+ fallback: "Unknown",
369
+ },
370
+ "publishType"
371
+ );
372
+ ```
373
+
374
+ Il caso ICU `other` viene rinominato in `fallback`, che è il nome canonico in Intlayer per il caso catch-all. Il secondo argomento registra il nome della variabile ICU affinché il messaggio ritorni esattamente alla stessa stringa ICU al momento dell'esportazione.
375
+
376
+ > Un ICU `select` i cui casi sono valori di genere (`male` / `female` / `other`) viene invece importato come nodo [`gender`](https://github.com/aymericzip/intlayer/blob/main/docs/docs/it/dictionary/gender.md).
377
+
378
+ ## Risorse Aggiuntive
379
+
380
+ Per informazioni più dettagliate sulla configurazione e l'uso, fai riferimento alle seguenti risorse:
381
+
382
+ - [Documentazione CLI di Intlayer](https://github.com/aymericzip/intlayer/blob/main/docs/docs/it/cli/index.md)
383
+ - [Documentazione React di Intlayer](https://github.com/aymericzip/intlayer/blob/main/docs/docs/it/intlayer_with_create_react_app.md)
384
+ - [Documentazione Next di Intlayer](https://github.com/aymericzip/intlayer/blob/main/docs/docs/it/intlayer_with_nextjs_15.md)
385
+
386
+ Queste risorse offrono ulteriori approfondimenti sulla configurazione e l'utilizzo di Intlayer in vari ambienti e framework.
@@ -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: コンテンツファイル
5
5
  description: コンテンツ宣言ファイルの拡張機能をカスタマイズする方法を学びます。このドキュメントに従って、プロジェクトで効率的に条件を実装しましょう。
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: "選択ベースのコンテンツを導入"
15
18
  - version: 8.10.0
16
19
  date: 2026-05-19
17
20
  changes: "YAMLおよびMarkdownファイルフォーマットのサポートを追加"
@@ -254,6 +257,7 @@ Intlayerは型付きノードを通じて様々なコンテンツタイプをサ
254
257
  - **HTML Content**: オプションのカスタムコンポーネントを使用したリッチHTMLコンテンツ [HTML Contentを参照](https://github.com/aymericzip/intlayer/blob/main/docs/docs/ja/dictionary/html.md)
255
258
  - **Nested Content**: 他の辞書への参照 [Nested Contentを参照](https://github.com/aymericzip/intlayer/blob/main/docs/docs/ja/dictionary/nested_content.md)
256
259
  - **Gender Content**: 性別に応じて変わるコンテンツ [Gender Contentを参照](https://github.com/aymericzip/intlayer/blob/main/docs/docs/ja/dictionary/gender_content.md)
260
+ - **Select Content**: 任意の文字列値に基づいて変化するコンテンツ [Select Contentを参照](https://github.com/aymericzip/intlayer/blob/main/docs/docs/ja/dictionary/select.md)
257
261
  - **File Content**: 外部ファイルへの参照 [File Contentを参照](https://github.com/aymericzip/intlayer/blob/main/docs/docs/ja/dictionary/file_content.md)
258
262
 
259
263
  ## 辞書の構造
@@ -748,6 +752,25 @@ genderContent: gender({
748
752
 
749
753
  > 詳細については、 [ジェンダーコンテンツ (`gender`) ドキュメント](https://github.com/aymericzip/intlayer/blob/main/docs/docs/ja/dictionary/gender.md) を参照してください。
750
754
 
755
+ ### 選択ベースのコンテンツ (`select`)
756
+
757
+ 任意の文字列値に基づいて変化するコンテンツ — ICUの `select` と同等のものです:
758
+
759
+ ```typescript
760
+ import { select } from "intlayer";
761
+
762
+ selectContent: select({
763
+ draft: "This post is a draft",
764
+ published: "This post is live",
765
+ scheduled: "This post is scheduled",
766
+ fallback: "Unknown status",
767
+ });
768
+ ```
769
+
770
+ 判別子が数量 (`enu`) ではなく、ブール値 (`cond`) ではなく、性別 (`gender`) でもない場合に `select` を使用します。実行時の値を使用して単純なオブジェクトをインデックス化するよりも優先してください:Intlayer コンパイラは動的に計算されたアクセスを静的に解決できません。
771
+
772
+ > 詳細については、 [選択ベースのコンテンツ](https://github.com/aymericzip/intlayer/blob/main/docs/docs/ja/dictionary/select.md) を参照してください。
773
+
751
774
  ### ファイルコンテンツ (`file`)
752
775
 
753
776
  外部ファイルへの参照: