@intlayer/docs 9.1.1 → 9.1.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.
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  createdAt: 2026-06-12
3
- updatedAt: 2026-06-26
3
+ updatedAt: 2026-08-04
4
4
  title: वैरिएंट
5
5
  description: नामित या संरचित सामग्री विकल्प — A/B परीक्षण, मौसमी बैनर, फ़ीचर-फ़्लैग टेक्स्ट, CMS रिकॉर्ड, उपयोगकर्ता-विशिष्ट सामग्री — घोषित करने और कोड बदले बिना रनटाइम पर उनके बीच स्विच करने के लिए Intlayer सामग्री फ़ाइलों में variant मेटाडेटा फ़ील्ड का उपयोग करें।
6
6
  keywords:
@@ -26,6 +26,9 @@ history:
26
26
  - version: 9.1.1
27
27
  date: 2026-07-31
28
28
  changes: "वेरिएंट केवल उन्हीं कुंजियों को घोषित करता है जिन्हें वह ओवरराइड करता है; अघोषित वेरिएंट डिफ़ॉल्ट प्रविष्टि पर वापस आ जाते हैं"
29
+ - version: 9.1.2
30
+ date: 2026-08-04
31
+ changes: "प्रोवाइडर एक परिवेशी `variant` प्रॉप स्वीकार करते हैं; सेलेक्टर एक क्रमित वरीयता शृंखला स्वीकार करते हैं"
29
32
  author: aymericzip
30
33
  ---
31
34
 
@@ -498,6 +501,176 @@ const content = useIntlayer("product", {
498
501
  const content = useIntlayer("product", { variant: { id: "prod_abc" } });
499
502
  ```
500
503
 
504
+ ## परिवेशी वैरिएंट
505
+
506
+ कुछ वैरिएंट आयाम पूरे सत्र के लिए स्थिर रहते हैं — टेनेंट, विद्यालय का प्रकार, प्लान स्तर। ये एक ही बार हल होते हैं, और किसी भी कॉम्पोनेंट को इन्हें हाथ से पास नहीं करना चाहिए।
507
+
508
+ > इन्हें इंजेक्ट करने के लिए `useIntlayer` को अपने हुक में न लपेटें। बिल्ड-टाइम अनुकूलन केवल फ्रेमवर्क पैकेज से आयातित शाब्दिक `useIntlayer("key")` कॉल को ही पुनर्लिखित करता है, इसलिए किसी रैपर के पीछे कुछ भी बंडल नहीं होता।
509
+
510
+ इसके बजाय वैरिएंट को प्रोवाइडर पर एक ही बार घोषित करें, ठीक `locale` की तरह:
511
+
512
+ <Tabs group="framework">
513
+ <Tab label="React" value="react">
514
+ ```tsx fileName="App.tsx" contentDeclarationFormat={["typescript", "esm", "commonjs"]}
515
+ import { IntlayerProvider } from "react-intlayer";
516
+
517
+ export const App = ({ locale, schoolType }) => (
518
+ <IntlayerProvider locale={locale} variant={schoolType}>
519
+ <Hero />
520
+ </IntlayerProvider>
521
+ );
522
+ ```
523
+
524
+ </Tab>
525
+ <Tab label="Next.js" value="nextjs">
526
+ ```tsx fileName="layout.tsx" contentDeclarationFormat={["typescript", "esm", "commonjs"]}
527
+ import { IntlayerServerProvider } from "next-intlayer/server";
528
+ import { IntlayerClientProvider } from "next-intlayer";
529
+
530
+ export default async function Layout({ children, params }) {
531
+ const { locale } = await params;
532
+ const schoolType = await getSchoolType();
533
+
534
+ return (
535
+ <IntlayerServerProvider locale={locale} variant={schoolType}>
536
+ <IntlayerClientProvider locale={locale} variant={schoolType}>
537
+ {children}
538
+ </IntlayerClientProvider>
539
+ </IntlayerServerProvider>
540
+ );
541
+ }
542
+ ```
543
+
544
+ </Tab>
545
+ <Tab label="Vue" value="vue">
546
+ ```ts fileName="main.ts" contentDeclarationFormat={["typescript", "esm", "commonjs"]}
547
+ import { createApp } from "vue";
548
+ import { installIntlayer } from "vue-intlayer";
549
+ import App from "./App.vue";
550
+
551
+ const app = createApp(App);
552
+
553
+ installIntlayer(app, { locale: "en", variant: schoolType });
554
+
555
+ app.mount("#app");
556
+ ```
557
+
558
+ </Tab>
559
+ <Tab label="Svelte" value="svelte">
560
+ ```svelte fileName="+layout.svelte" contentDeclarationFormat={["typescript", "esm", "commonjs"]}
561
+ <script lang="ts">
562
+ import { setupIntlayer } from "svelte-intlayer";
563
+
564
+ export let schoolType: string;
565
+
566
+ setupIntlayer("en", schoolType);
567
+ </script>
568
+
569
+ <slot />
570
+ ```
571
+
572
+ </Tab>
573
+ <Tab label="Preact" value="preact">
574
+ ```tsx fileName="App.tsx" contentDeclarationFormat={["typescript", "esm", "commonjs"]}
575
+ import { IntlayerProvider } from "preact-intlayer";
576
+
577
+ export const App = ({ locale, schoolType }) => (
578
+ <IntlayerProvider locale={locale} variant={schoolType}>
579
+ <Hero />
580
+ </IntlayerProvider>
581
+ );
582
+ ```
583
+
584
+ </Tab>
585
+ <Tab label="Solid" value="solid">
586
+ ```tsx fileName="App.tsx" contentDeclarationFormat={["typescript", "esm", "commonjs"]}
587
+ import { IntlayerProvider } from "solid-intlayer";
588
+
589
+ export const App = (props) => (
590
+ <IntlayerProvider locale={props.locale} variant={props.schoolType}>
591
+ <Hero />
592
+ </IntlayerProvider>
593
+ );
594
+ ```
595
+
596
+ </Tab>
597
+ <Tab label="Angular" value="angular">
598
+ ```typescript fileName="app.config.ts" contentDeclarationFormat={["typescript", "esm", "commonjs"]}
599
+ import { ApplicationConfig } from "@angular/core";
600
+ import { provideIntlayer } from "angular-intlayer";
601
+
602
+ export const appConfig: ApplicationConfig = {
603
+ providers: [provideIntlayer("en", true, schoolType)],
604
+ };
605
+ ```
606
+
607
+ </Tab>
608
+ <Tab label="Vanilla JS" value="vanilla">
609
+ ```javascript fileName="main.js"
610
+ import { installIntlayer } from "vanilla-intlayer";
611
+
612
+ installIntlayer({ locale: "en", variant: schoolType });
613
+ ```
614
+
615
+ </Tab>
616
+ </Tabs>
617
+
618
+ अब प्रोवाइडर के नीचे प्रत्येक डिक्शनरी पठन उसी वैरिएंट के सापेक्ष हल होता है, और कॉल-स्थल का सेलेक्टर हमेशा जीतता है:
619
+
620
+ ```tsx
621
+ useIntlayer("hero-banner");
622
+ // → प्रोवाइडर का वैरिएंट
623
+
624
+ useIntlayer("hero-banner", { variant: "summer" });
625
+ // → "summer" — प्रोवाइडर वैरिएंट को प्रतिस्थापित करता है, उसका विस्तार नहीं करता
626
+ ```
627
+
628
+ ### रूप
629
+
630
+ `variant` प्रॉप तीन रूप स्वीकार करता है:
631
+
632
+ | रूप | अर्थ |
633
+ | --------------------------------------------------------- | -------------------------------- |
634
+ | `variant="school1"` | हर कुंजी के लिए एक नामित वैरिएंट |
635
+ | `variant={["school1", "default"]}` | एक क्रमित वरीयता शृंखला |
636
+ | `variant={{ "hero-banner": "school1", default: "base" }}` | प्रति डिक्शनरी कुंजी एक वैरिएंट |
637
+
638
+ #### वरीयता शृंखला
639
+
640
+ शृंखला को प्रत्येक कुंजी द्वारा घोषित प्रविष्टियों के सापेक्ष बाएँ से दाएँ आज़माया जाता है, और पहली घोषित प्रविष्टि जीतती है। जब कोई भी घोषित न हो, तो निहित डिफ़ॉल्ट प्रविष्टि का उपयोग होता है — ठीक वैसे ही जैसे एकल मान के लिए।
641
+
642
+ ```tsx
643
+ <IntlayerProvider variant={["school1", "school2"]} />
644
+ // `hero-banner` कोई `school1` प्रविष्टि घोषित नहीं करता, पर `school2` घोषित करता है → "school2"
645
+ // वह कुंजी जो दोनों में से कोई घोषित नहीं करती → डिफ़ॉल्ट प्रविष्टि
646
+ ```
647
+
648
+ अतः `["black_friday", "summer"]` का अर्थ है «यदि इस कुंजी के पास black friday है तो वही, अन्यथा summer, अन्यथा डिफ़ॉल्ट»। शृंखलाएँ कॉल-स्थल पर भी स्वीकार्य हैं:
649
+
650
+ ```tsx
651
+ useIntlayer("hero-banner", { variant: ["black_friday", "summer"] });
652
+ ```
653
+
654
+ > ध्यान दें कि यह कंटेंट फ़ाइल के `variant` **फ़ील्ड** द्वारा स्वीकार किए जाने वाले ऐरे का दर्पण प्रतिबिंब है: वहाँ एक ऐरे प्रति तत्व एक प्रविष्टि _घोषित_ करता है, यहाँ वह उन्हें प्राथमिकता क्रम में _उपभोग_ करता है।
655
+
656
+ #### प्रति-कुंजी मैप
657
+
658
+ प्रत्येक डिक्शनरी कुंजी को अलग-अलग संबोधित करें। आरक्षित `default` प्रविष्टि उन सभी कुंजियों को कवर करती है जो सूचीबद्ध नहीं हैं:
659
+
660
+ ```tsx
661
+ <IntlayerProvider
662
+ variant={{
663
+ "hero-banner": "school1",
664
+ product: ["school1", "default"],
665
+ default: "base",
666
+ }}
667
+ />
668
+ ```
669
+
670
+ > प्रोवाइडर पर एक सामान्य ऑब्जेक्ट **हमेशा** प्रति-कुंजी मैप के रूप में पढ़ा जाता है, कभी ऑब्जेक्ट वैरिएंट के रूप में नहीं — दोनों संरचनात्मक रूप से समान हैं। किसी ऑब्जेक्ट वैरिएंट को वैश्विक रूप से तय करने के लिए उसे किसी प्रविष्टि के नीचे नेस्ट करें: `variant={{ default: { id: "prod_abc" } }}`।
671
+
672
+ चूँकि मैप की कुंजियाँ आपकी घोषित डिक्शनरी कुंजियों के विरुद्ध जाँची जाती हैं, कोई टाइपो — या सीधे लिखा गया ऑब्जेक्ट वैरिएंट, जैसे `variant={{ id: "prod_abc" }}` — संकलन-समय त्रुटि है।
673
+
501
674
  ## लोडिंग मोड
502
675
 
503
676
  ऑब्जेक्ट वैरिएंट अक्सर आलसी रूप से लोड किए जाते हैं। इसे नियंत्रित करने के लिए डिक्शनरी पर `importMode` सेट करें:
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  createdAt: 2026-06-12
3
- updatedAt: 2026-06-26
3
+ updatedAt: 2026-08-04
4
4
  title: Varian
5
5
  description: Gunakan field metadata variant di file konten Intlayer untuk mendeklarasikan alternatif konten bernama atau terstruktur — pengujian A/B, banner musiman, teks ber-feature flag, record CMS, konten khusus pengguna — dan beralih di antaranya saat runtime tanpa perubahan kode.
6
6
  keywords:
@@ -26,6 +26,9 @@ history:
26
26
  - version: 9.1.1
27
27
  date: 2026-07-31
28
28
  changes: "Varian hanya mendeklarasikan kunci yang ditimpanya; varian yang tidak dideklarasikan akan kembali ke entri default"
29
+ - version: 9.1.2
30
+ date: 2026-08-04
31
+ changes: "Provider menerima prop `variant` ambien; selektor menerima rantai preferensi terurut"
29
32
  author: aymericzip
30
33
  ---
31
34
 
@@ -498,6 +501,176 @@ const content = useIntlayer("product", {
498
501
  const content = useIntlayer("product", { variant: { id: "prod_abc" } });
499
502
  ```
500
503
 
504
+ ## Varian ambien
505
+
506
+ Beberapa dimensi varian tetap sepanjang satu sesi — tenant, jenis sekolah, tingkat paket. Semuanya diselesaikan sekali, dan tidak ada komponen yang perlu meneruskannya secara manual.
507
+
508
+ > Jangan membungkus `useIntlayer` dalam hook Anda sendiri untuk menyuntikkannya. Optimasi saat build hanya menulis ulang pemanggilan literal `useIntlayer("key")` yang diimpor dari paket framework, sehingga apa pun di balik pembungkus tidak akan ikut dibundel.
509
+
510
+ Sebagai gantinya, deklarasikan varian sekali pada provider, persis seperti `locale`:
511
+
512
+ <Tabs group="framework">
513
+ <Tab label="React" value="react">
514
+ ```tsx fileName="App.tsx" contentDeclarationFormat={["typescript", "esm", "commonjs"]}
515
+ import { IntlayerProvider } from "react-intlayer";
516
+
517
+ export const App = ({ locale, schoolType }) => (
518
+ <IntlayerProvider locale={locale} variant={schoolType}>
519
+ <Hero />
520
+ </IntlayerProvider>
521
+ );
522
+ ```
523
+
524
+ </Tab>
525
+ <Tab label="Next.js" value="nextjs">
526
+ ```tsx fileName="layout.tsx" contentDeclarationFormat={["typescript", "esm", "commonjs"]}
527
+ import { IntlayerServerProvider } from "next-intlayer/server";
528
+ import { IntlayerClientProvider } from "next-intlayer";
529
+
530
+ export default async function Layout({ children, params }) {
531
+ const { locale } = await params;
532
+ const schoolType = await getSchoolType();
533
+
534
+ return (
535
+ <IntlayerServerProvider locale={locale} variant={schoolType}>
536
+ <IntlayerClientProvider locale={locale} variant={schoolType}>
537
+ {children}
538
+ </IntlayerClientProvider>
539
+ </IntlayerServerProvider>
540
+ );
541
+ }
542
+ ```
543
+
544
+ </Tab>
545
+ <Tab label="Vue" value="vue">
546
+ ```ts fileName="main.ts" contentDeclarationFormat={["typescript", "esm", "commonjs"]}
547
+ import { createApp } from "vue";
548
+ import { installIntlayer } from "vue-intlayer";
549
+ import App from "./App.vue";
550
+
551
+ const app = createApp(App);
552
+
553
+ installIntlayer(app, { locale: "en", variant: schoolType });
554
+
555
+ app.mount("#app");
556
+ ```
557
+
558
+ </Tab>
559
+ <Tab label="Svelte" value="svelte">
560
+ ```svelte fileName="+layout.svelte" contentDeclarationFormat={["typescript", "esm", "commonjs"]}
561
+ <script lang="ts">
562
+ import { setupIntlayer } from "svelte-intlayer";
563
+
564
+ export let schoolType: string;
565
+
566
+ setupIntlayer("en", schoolType);
567
+ </script>
568
+
569
+ <slot />
570
+ ```
571
+
572
+ </Tab>
573
+ <Tab label="Preact" value="preact">
574
+ ```tsx fileName="App.tsx" contentDeclarationFormat={["typescript", "esm", "commonjs"]}
575
+ import { IntlayerProvider } from "preact-intlayer";
576
+
577
+ export const App = ({ locale, schoolType }) => (
578
+ <IntlayerProvider locale={locale} variant={schoolType}>
579
+ <Hero />
580
+ </IntlayerProvider>
581
+ );
582
+ ```
583
+
584
+ </Tab>
585
+ <Tab label="Solid" value="solid">
586
+ ```tsx fileName="App.tsx" contentDeclarationFormat={["typescript", "esm", "commonjs"]}
587
+ import { IntlayerProvider } from "solid-intlayer";
588
+
589
+ export const App = (props) => (
590
+ <IntlayerProvider locale={props.locale} variant={props.schoolType}>
591
+ <Hero />
592
+ </IntlayerProvider>
593
+ );
594
+ ```
595
+
596
+ </Tab>
597
+ <Tab label="Angular" value="angular">
598
+ ```typescript fileName="app.config.ts" contentDeclarationFormat={["typescript", "esm", "commonjs"]}
599
+ import { ApplicationConfig } from "@angular/core";
600
+ import { provideIntlayer } from "angular-intlayer";
601
+
602
+ export const appConfig: ApplicationConfig = {
603
+ providers: [provideIntlayer("en", true, schoolType)],
604
+ };
605
+ ```
606
+
607
+ </Tab>
608
+ <Tab label="Vanilla JS" value="vanilla">
609
+ ```javascript fileName="main.js"
610
+ import { installIntlayer } from "vanilla-intlayer";
611
+
612
+ installIntlayer({ locale: "en", variant: schoolType });
613
+ ```
614
+
615
+ </Tab>
616
+ </Tabs>
617
+
618
+ Setiap pembacaan kamus di bawah provider kini diselesaikan terhadap varian tersebut, dan selektor di titik pemanggilan selalu menang:
619
+
620
+ ```tsx
621
+ useIntlayer("hero-banner");
622
+ // → varian dari provider
623
+
624
+ useIntlayer("hero-banner", { variant: "summer" });
625
+ // → "summer" — menggantikan varian provider, bukan memperluasnya
626
+ ```
627
+
628
+ ### Bentuk
629
+
630
+ Prop `variant` menerima tiga bentuk:
631
+
632
+ | Bentuk | Arti |
633
+ | --------------------------------------------------------- | -------------------------------------- |
634
+ | `variant="school1"` | satu varian bernama untuk setiap kunci |
635
+ | `variant={["school1", "default"]}` | rantai preferensi terurut |
636
+ | `variant={{ "hero-banner": "school1", default: "base" }}` | satu varian per kunci kamus |
637
+
638
+ #### Rantai preferensi
639
+
640
+ Rantai dicoba dari kiri ke kanan terhadap entri yang dideklarasikan setiap kunci, dan yang pertama dideklarasikan menang. Bila tidak ada yang dideklarasikan, entri default implisit digunakan — persis seperti untuk nilai tunggal.
641
+
642
+ ```tsx
643
+ <IntlayerProvider variant={["school1", "school2"]} />
644
+ // `hero-banner` tidak mendeklarasikan entri `school1` tetapi mendeklarasikan `school2` → "school2"
645
+ // kunci yang tidak mendeklarasikan keduanya → entri default
646
+ ```
647
+
648
+ Jadi `["black_friday", "summer"]` dibaca sebagai «black friday jika kunci ini memilikinya, jika tidak summer, jika tidak default». Rantai juga diterima di titik pemanggilan:
649
+
650
+ ```tsx
651
+ useIntlayer("hero-banner", { variant: ["black_friday", "summer"] });
652
+ ```
653
+
654
+ > Perhatikan bahwa ini adalah kebalikan dari array yang diterima oleh **field** `variant` pada berkas konten: di sana array _mendeklarasikan_ satu entri per elemen, di sini ia _mengonsumsi_ entri tersebut sesuai urutan prioritas.
655
+
656
+ #### Peta per kunci
657
+
658
+ Alamatkan setiap kunci kamus secara terpisah. Entri `default` yang dicadangkan mencakup semua kunci yang tidak terdaftar:
659
+
660
+ ```tsx
661
+ <IntlayerProvider
662
+ variant={{
663
+ "hero-banner": "school1",
664
+ product: ["school1", "default"],
665
+ default: "base",
666
+ }}
667
+ />
668
+ ```
669
+
670
+ > Pada provider, objek biasa **selalu** dibaca sebagai peta per kunci, bukan sebagai varian objek — keduanya identik secara struktural. Untuk menetapkan varian objek secara global, sarangkan di bawah sebuah entri: `variant={{ default: { id: "prod_abc" } }}`.
671
+
672
+ Karena kunci pada peta diperiksa terhadap kunci kamus yang Anda deklarasikan, salah ketik — atau varian objek yang ditulis langsung, seperti `variant={{ id: "prod_abc" }}` — adalah galat saat kompilasi.
673
+
501
674
  ## Mode pemuatan
502
675
 
503
676
  Varian objek sering dimuat secara malas. Atur `importMode` pada kamus untuk mengendalikannya:
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  createdAt: 2026-06-12
3
- updatedAt: 2026-06-26
3
+ updatedAt: 2026-08-04
4
4
  title: Varianti
5
5
  description: Usa il campo di metadati variant nei file di contenuto Intlayer per dichiarare alternative di contenuto con nome o strutturate — test A/B, banner stagionali, testo con feature flag, record di CMS, contenuti specifici per utente — e passare dall'una all'altra a runtime senza modifiche al codice.
6
6
  keywords:
@@ -26,6 +26,9 @@ history:
26
26
  - version: 9.1.1
27
27
  date: 2026-07-31
28
28
  changes: "Una variante dichiara solo le chiavi che sovrascrive; le varianti non dichiarate ricadono sulla voce predefinita"
29
+ - version: 9.1.2
30
+ date: 2026-08-04
31
+ changes: "I provider accettano una prop `variant` ambientale; i selettori accettano una catena di preferenza ordinata"
29
32
  author: aymericzip
30
33
  ---
31
34
 
@@ -498,6 +501,176 @@ const content = useIntlayer("product", {
498
501
  const content = useIntlayer("product", { variant: { id: "prod_abc" } });
499
502
  ```
500
503
 
504
+ ## Variante ambientale
505
+
506
+ Alcune dimensioni di variante sono fisse per un'intera sessione: il tenant, il tipo di istituto, il livello di piano. Vengono risolte una sola volta e nessun componente dovrebbe doverle passare a mano.
507
+
508
+ > Non incapsulare `useIntlayer` in un hook personalizzato per iniettarle. L'ottimizzazione in fase di build riscrive solo una chiamata letterale `useIntlayer("key")` importata dal pacchetto del framework, quindi nulla dietro un wrapper finisce nel bundle.
509
+
510
+ Dichiara invece la variante una sola volta sul provider, esattamente come `locale`:
511
+
512
+ <Tabs group="framework">
513
+ <Tab label="React" value="react">
514
+ ```tsx fileName="App.tsx" contentDeclarationFormat={["typescript", "esm", "commonjs"]}
515
+ import { IntlayerProvider } from "react-intlayer";
516
+
517
+ export const App = ({ locale, schoolType }) => (
518
+ <IntlayerProvider locale={locale} variant={schoolType}>
519
+ <Hero />
520
+ </IntlayerProvider>
521
+ );
522
+ ```
523
+
524
+ </Tab>
525
+ <Tab label="Next.js" value="nextjs">
526
+ ```tsx fileName="layout.tsx" contentDeclarationFormat={["typescript", "esm", "commonjs"]}
527
+ import { IntlayerServerProvider } from "next-intlayer/server";
528
+ import { IntlayerClientProvider } from "next-intlayer";
529
+
530
+ export default async function Layout({ children, params }) {
531
+ const { locale } = await params;
532
+ const schoolType = await getSchoolType();
533
+
534
+ return (
535
+ <IntlayerServerProvider locale={locale} variant={schoolType}>
536
+ <IntlayerClientProvider locale={locale} variant={schoolType}>
537
+ {children}
538
+ </IntlayerClientProvider>
539
+ </IntlayerServerProvider>
540
+ );
541
+ }
542
+ ```
543
+
544
+ </Tab>
545
+ <Tab label="Vue" value="vue">
546
+ ```ts fileName="main.ts" contentDeclarationFormat={["typescript", "esm", "commonjs"]}
547
+ import { createApp } from "vue";
548
+ import { installIntlayer } from "vue-intlayer";
549
+ import App from "./App.vue";
550
+
551
+ const app = createApp(App);
552
+
553
+ installIntlayer(app, { locale: "en", variant: schoolType });
554
+
555
+ app.mount("#app");
556
+ ```
557
+
558
+ </Tab>
559
+ <Tab label="Svelte" value="svelte">
560
+ ```svelte fileName="+layout.svelte" contentDeclarationFormat={["typescript", "esm", "commonjs"]}
561
+ <script lang="ts">
562
+ import { setupIntlayer } from "svelte-intlayer";
563
+
564
+ export let schoolType: string;
565
+
566
+ setupIntlayer("en", schoolType);
567
+ </script>
568
+
569
+ <slot />
570
+ ```
571
+
572
+ </Tab>
573
+ <Tab label="Preact" value="preact">
574
+ ```tsx fileName="App.tsx" contentDeclarationFormat={["typescript", "esm", "commonjs"]}
575
+ import { IntlayerProvider } from "preact-intlayer";
576
+
577
+ export const App = ({ locale, schoolType }) => (
578
+ <IntlayerProvider locale={locale} variant={schoolType}>
579
+ <Hero />
580
+ </IntlayerProvider>
581
+ );
582
+ ```
583
+
584
+ </Tab>
585
+ <Tab label="Solid" value="solid">
586
+ ```tsx fileName="App.tsx" contentDeclarationFormat={["typescript", "esm", "commonjs"]}
587
+ import { IntlayerProvider } from "solid-intlayer";
588
+
589
+ export const App = (props) => (
590
+ <IntlayerProvider locale={props.locale} variant={props.schoolType}>
591
+ <Hero />
592
+ </IntlayerProvider>
593
+ );
594
+ ```
595
+
596
+ </Tab>
597
+ <Tab label="Angular" value="angular">
598
+ ```typescript fileName="app.config.ts" contentDeclarationFormat={["typescript", "esm", "commonjs"]}
599
+ import { ApplicationConfig } from "@angular/core";
600
+ import { provideIntlayer } from "angular-intlayer";
601
+
602
+ export const appConfig: ApplicationConfig = {
603
+ providers: [provideIntlayer("en", true, schoolType)],
604
+ };
605
+ ```
606
+
607
+ </Tab>
608
+ <Tab label="Vanilla JS" value="vanilla">
609
+ ```javascript fileName="main.js"
610
+ import { installIntlayer } from "vanilla-intlayer";
611
+
612
+ installIntlayer({ locale: "en", variant: schoolType });
613
+ ```
614
+
615
+ </Tab>
616
+ </Tabs>
617
+
618
+ Ogni lettura di dizionario sotto il provider si risolve ora con quella variante, e un selettore nel punto di chiamata vince sempre:
619
+
620
+ ```tsx
621
+ useIntlayer("hero-banner");
622
+ // → la variante del provider
623
+
624
+ useIntlayer("hero-banner", { variant: "summer" });
625
+ // → "summer" — sostituisce la variante del provider, non la estende
626
+ ```
627
+
628
+ ### Forme
629
+
630
+ La prop `variant` accetta tre forme:
631
+
632
+ | Forma | Significato |
633
+ | --------------------------------------------------------- | --------------------------------------- |
634
+ | `variant="school1"` | una variante denominata per ogni chiave |
635
+ | `variant={["school1", "default"]}` | una catena di preferenza ordinata |
636
+ | `variant={{ "hero-banner": "school1", default: "base" }}` | una variante per chiave di dizionario |
637
+
638
+ #### Catena di preferenza
639
+
640
+ Una catena viene percorsa da sinistra a destra tra le voci dichiarate da ciascuna chiave e vince la prima dichiarata. Quando nessuna è dichiarata, si usa la voce predefinita implicita, esattamente come per un valore singolo.
641
+
642
+ ```tsx
643
+ <IntlayerProvider variant={["school1", "school2"]} />
644
+ // `hero-banner` non dichiara una voce `school1` ma dichiara `school2` → "school2"
645
+ // una chiave che non dichiara nessuna delle due → la voce predefinita
646
+ ```
647
+
648
+ Quindi `["black_friday", "summer"]` si legge come «black friday se questa chiave ne ha una, altrimenti summer, altrimenti predefinita». Le catene sono accettate anche nel punto di chiamata:
649
+
650
+ ```tsx
651
+ useIntlayer("hero-banner", { variant: ["black_friday", "summer"] });
652
+ ```
653
+
654
+ > Nota che questa è l'immagine speculare dell'array accettato dal **campo** `variant` di un file di contenuto: lì un array _dichiara_ una voce per elemento, qui le _consuma_ in ordine di priorità.
655
+
656
+ #### Mappa per chiave
657
+
658
+ Indirizza ogni chiave di dizionario separatamente. La voce riservata `default` copre tutte le chiavi non elencate:
659
+
660
+ ```tsx
661
+ <IntlayerProvider
662
+ variant={{
663
+ "hero-banner": "school1",
664
+ product: ["school1", "default"],
665
+ default: "base",
666
+ }}
667
+ />
668
+ ```
669
+
670
+ > Su un provider un oggetto semplice è **sempre** letto come mappa per chiave, mai come variante oggetto: le due sono strutturalmente identiche. Per fissare una variante oggetto a livello globale, annidala sotto una voce: `variant={{ default: { id: "prod_abc" } }}`.
671
+
672
+ Poiché le chiavi della mappa sono verificate rispetto alle chiavi di dizionario dichiarate, un refuso — o una variante oggetto scritta direttamente, come `variant={{ id: "prod_abc" }}` — è un errore di compilazione.
673
+
501
674
  ## Modalità di caricamento
502
675
 
503
676
  Le varianti oggetto sono spesso caricate in modo differito. Imposta `importMode` sul dizionario per controllarlo: