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

{$content.description}

\n {/if}\n ```\n\n
\n \n ```tsx fileName=\"ProductCopy.tsx\" contentDeclarationFormat={[\"typescript\", \"esm\", \"commonjs\"]}\n import { useIntlayer } from \"preact-intlayer\";\n\n export const ProductCopy = ({\n productId,\n userId,\n }: {\n productId: string;\n userId: string;\n }) => {\n const content = useIntlayer(\"product-copy\", { id: productId, userId });\n // TypeScript đảm bảo rằng cả `id` và `userId` đều được cung cấp.\n\n if (!content) return null;\n\n return

{content.description}

;\n };\n ```\n\n
\n \n ```tsx fileName=\"ProductCopy.tsx\" contentDeclarationFormat={[\"typescript\", \"esm\", \"commonjs\"]}\n import { useIntlayer } from \"solid-intlayer\";\n\n export const ProductCopy = (props: {\n productId: string;\n userId: string;\n }) => {\n const content = useIntlayer(\"product-copy\", { id: props.productId, userId: props.userId });\n // TypeScript đảm bảo rằng cả `id` và `userId` đều được cung cấp.\n\n return (\n <>\n {content() &&

{content().description}

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

{{ content().description }}

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

${content.description}

`;\n }\n ```\n\n
\n\n\n### Với ngôn ngữ rõ ràng\n\n```tsx\nconst content = useIntlayer(\"product-copy\", {\n id: \"prod_abc\",\n userId: \"user_123\",\n locale: \"vi\",\n});\n```\n\n### Thiếu trường meta — lỗi compile-time\n\n```ts\n// Lỗi kiểu dữ liệu: thiếu `userId`\nconst content = useIntlayer(\"product-copy\", { id: \"prod_abc\" });\n```\n\n## Chế độ tải (loading mode)\n\nCác bản ghi động thường được tải lười (lazy loaded). Hãy thiết lập `importMode` trên từ điển để kiểm soát điều này:\n\n```ts contentDeclarationFormat={[\"typescript\", \"esm\", \"commonjs\"]}\nconst dictionary = {\n key: \"product-copy\",\n importMode: \"fetch\", // hoặc \"dynamic\"\n meta: { id: \"prod_abc\", userId: \"user_123\" },\n content: { … },\n} satisfies Dictionary;\n\nexport default dictionary;\n```\n\nXem [tối ưu hóa gói bundle](/vi/doc/concept/bundle-optimization) để biết thêm chi tiết về chế độ `static`, `dynamic` và `fetch`.\n\n## Các trường hợp sử dụng điển hình\n\n- Nội dung tiếp thị trên mỗi sản phẩm được quản lý trong CMS\n- Nội dung dành riêng cho người dùng hoặc tài khoản cụ thể\n- Bất kỳ nội dung nào được xác định bằng một ID runtime ẩn\n","description":"Sử dụng trường meta trong các tệp nội dung Intlayer để khai báo các bản ghi do CMS quản lý được truy xuất tại runtime bằng ID ẩn, cho phép nội dung động có kiểu dữ liệu mạnh mẽ (strongly-typed) mà không cần đếm tại thời điểm build.","url":"https://intlayer.org/vi/doc/concept/dynamic-records","datePublished":"2026-06-12","dateModified":"2026-06-12","version":"9.0.0","keywords":"Bản Ghi Động, Nội Dung Động, CMS, Nội Dung Runtime, Intlayer, Quốc tế hóa","license":"https://raw.githubusercontent.com/aymericzip/intlayer/refs/heads/main/LICENSE","audience":{"@type":"Audience","audienceType":"Nhà phát triển (Developers), Quản trị nội dung (Content Managers)"}}
    Tác giả:
    Ngày tạo:2026-06-12Cập nhật lần cuối:2026-06-12

    Bản Ghi Động

    Một bản ghi động (dynamic record) là một tệp nội dung có danh tính không phải là một chỉ mục tuần tự hoặc một biến thể có tên, mà là một tập hợp tùy ý gồm các cặp khóa-giá trị được khai báo trong trường meta. Intlayer sử dụng các trường đó làm bộ chọn tại runtime, giúp có thể định địa chỉ các bản ghi CMS, nội dung dành riêng cho người dùng hoặc bất kỳ nội dung nào có khóa không được biết tại thời điểm build.

    Khai báo các bản ghi động

    product-copy.abc.content.ts
    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;
    product-copy.abcd.content.ts
    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;

    Sử dụng bản ghi động

    Tất cả các trường meta đều bắt buộc trong bộ chọn. Việc bỏ qua bất kỳ trường nào sẽ trả về null và gây ra lỗi TypeScript.

    ProductCopy.tsx
    import { useIntlayer } from "react-intlayer";
    
    export const ProductCopy = ({
      productId,
      userId,
    }: {
      productId: string;
      userId: string;
    }) => {
      const content = useIntlayer("product-copy", { id: productId, userId });
      // TypeScript đảm bảo rằng cả `id` và `userId` đều được cung cấp.
    
      if (!content) return null;
    
      return <p>{content.description}</p>;
    };

    Với ngôn ngữ rõ ràng

    tsx
    const content = useIntlayer("product-copy", {  id: "prod_abc",  userId: "user_123",  locale: "vi",});

    Thiếu trường meta — lỗi compile-time

    ts
    // Lỗi kiểu dữ liệu: thiếu `userId`const content = useIntlayer("product-copy", { id: "prod_abc" });

    Chế độ tải (loading mode)

    Các bản ghi động thường được tải lười (lazy loaded). Hãy thiết lập importMode trên từ điển để kiểm soát điều này:

    ts
    const dictionary = {
      key: "product-copy",
      importMode: "fetch", // hoặc "dynamic"
      meta: { id: "prod_abc", userId: "user_123" },
      content: { … },
    } satisfies Dictionary;
    
    export default dictionary;

    Xem tối ưu hóa gói bundle để biết thêm chi tiết về chế độ static, dynamicfetch.

    Các trường hợp sử dụng điển hình

    • Nội dung tiếp thị trên mỗi sản phẩm được quản lý trong CMS
    • Nội dung dành riêng cho người dùng hoặc tài khoản cụ thể
    • Bất kỳ nội dung nào được xác định bằng một ID runtime ẩn