--- createdAt: 2026-06-12 updatedAt: 2026-06-12 title: Record Dinamici description: Utilizza il campo meta nei file di contenuto di Intlayer per dichiarare record gestiti da CMS recuperati a runtime tramite un ID opaco, abilitando contenuti dinamici fortemente tipizzati senza enumerazione a tempo di compilazione. keywords: - Record Dinamici - Contenuto Dinamico - CMS - Contenuto a Runtime - Intlayer - Internazionalizzazione slugs: - doc - concept - dynamic-records history: - version: 9.0.0 date: 2026-06-12 changes: "Rilascio della funzionalità di contenuto dinamico" author: aymericzip --- # Record Dinamici Un **record dinamico** (dynamic record) è un file di contenuto la cui identità non è un indice sequenziale o una variante denominata, ma un insieme arbitrario di coppie chiave-valore dichiarate in un campo `meta`. Intlayer utilizza questi campi come selettore al momento dell'esecuzione, rendendo possibile indirizzare record di CMS, testi specifici dell'utente o qualsiasi contenuto le cui chiavi non sono note a tempo di compilazione. ## Dichiarare record dinamici ```ts fileName="product-copy.abc.content.ts" contentDeclarationFormat={["typescript", "esm", "commonjs"]} import { t, type Dictionary } from "intlayer"; const dictionary = { key: "product-copy", meta: { id: "prod_abc", userId: "user_123", }, content: { name: t({ en: "Widget Pro", fr: "Widget Pro" }), description: t({ en: "The best widget.", fr: "Le meilleur widget." }), }, } satisfies Dictionary; export default dictionary; ``` ```ts fileName="product-copy.abcd.content.ts" contentDeclarationFormat={["typescript", "esm", "commonjs"]} import { t, type Dictionary } from "intlayer"; const dictionary = { key: "product-copy", meta: { id: "prod_abcd", userId: "user_123", }, content: { name: t({ en: "Widget Lite", fr: "Widget Lite" }), description: t({ en: "A lighter option.", fr: "Une option plus légère." }), }, } satisfies Dictionary; export default dictionary; ``` ## Consumare record dinamici Tutti i campi `meta` sono **obbligatori** nel selettore. L'omissione di qualsiasi campo restituisce `null` ed è un errore di TypeScript. ```tsx fileName="ProductCopy.tsx" contentDeclarationFormat={["typescript", "esm", "commonjs"]} import { useIntlayer } from "react-intlayer"; export const ProductCopy = ({ productId, userId, }: { productId: string; userId: string; }) => { const content = useIntlayer("product-copy", { id: productId, userId }); // TypeScript garantisce che vengano forniti sia `id` che `userId`. if (!content) return null; return

{content.description}

; }; ```
```tsx fileName="ProductCopy.tsx" contentDeclarationFormat={["typescript", "esm", "commonjs"]} import { useIntlayer } from "next-intlayer"; export const ProductCopy = ({ productId, userId, }: { productId: string; userId: string; }) => { const content = useIntlayer("product-copy", { id: productId, userId }); // TypeScript garantisce che vengano forniti sia `id` che `userId`. if (!content) return null; return

{content.description}

; }; ```
```vue fileName="ProductCopy.vue" contentDeclarationFormat={["typescript", "esm", "commonjs"]} ``` ```svelte fileName="ProductCopy.svelte" contentDeclarationFormat={["typescript", "esm", "commonjs"]} {#if $content}

{$content.description}

{/if} ```
```tsx fileName="ProductCopy.tsx" contentDeclarationFormat={["typescript", "esm", "commonjs"]} import { useIntlayer } from "preact-intlayer"; export const ProductCopy = ({ productId, userId, }: { productId: string; userId: string; }) => { const content = useIntlayer("product-copy", { id: productId, userId }); // TypeScript garantisce che vengano forniti sia `id` che `userId`. if (!content) return null; return

{content.description}

; }; ```
```tsx fileName="ProductCopy.tsx" contentDeclarationFormat={["typescript", "esm", "commonjs"]} import { useIntlayer } from "solid-intlayer"; export const ProductCopy = (props: { productId: string; userId: string; }) => { const content = useIntlayer("product-copy", { id: props.productId, userId: props.userId }); // TypeScript garantisce che vengano forniti sia `id` che `userId`. return ( <> {content() &&

{content().description}

} ); }; ```
```typescript fileName="product-copy.component.ts" contentDeclarationFormat={["typescript", "esm", "commonjs"]} import { Component, Input, OnInit } from "@angular/core"; import { useIntlayer } from "angular-intlayer"; @Component({ selector: "app-product-copy", template: ` @if (content()) {

{{ content().description }}

} `, }) export class ProductCopyComponent implements OnInit { @Input() productId!: string; @Input() userId!: string; content: any; ngOnInit() { this.content = useIntlayer("product-copy", { id: this.productId, userId: this.userId }); } } ```
```javascript fileName="product-copy.js" import { useIntlayer } from "vanilla-intlayer"; const content = useIntlayer("product-copy", { id: "prod_abcd", userId: "user_123" }); if (content) { document.body.innerHTML = `

${content.description}

`; } ```
### Con locale esplicita ```tsx const content = useIntlayer("product-copy", { id: "prod_abc", userId: "user_123", locale: "it", }); ``` ### Campo meta mancante — errore in tempo di compilazione ```ts // Errore di tipo: manca `userId` const content = useIntlayer("product-copy", { id: "prod_abc" }); ``` ## Modalità di caricamento (loading mode) I record dinamici vengono solitamente caricati in modo differito (lazy loading). Imposta `importMode` sul dizionario per controllare questo comportamento: ```ts contentDeclarationFormat={["typescript", "esm", "commonjs"]} const dictionary = { key: "product-copy", importMode: "fetch", // o "dynamic" meta: { id: "prod_abc", userId: "user_123" }, content: { … }, } satisfies Dictionary; export default dictionary; ``` Vedi [ottimizzazione del bundle](https://github.com/aymericzip/intlayer/blob/main/docs/docs/it/bundle_optimization.md) per i dettagli sulle modalità `static`, `dynamic` e `fetch`. ## Casi d'uso tipici - Testi di marketing per prodotto gestiti in un CMS - Contenuti specifici dell'utente o dell'account - Qualsiasi contenuto identificato da un ID runtime opaco