\n\n \n ```\n\n \n \n ```svelte fileName=\"Hero.svelte\" contentDeclarationFormat={[\"typescript\", \"esm\", \"commonjs\"]}\n \n\n
\n

{$content.headline}

\n {$content.cta}\n
\n ```\n\n
\n \n ```tsx fileName=\"Hero.tsx\" contentDeclarationFormat={[\"typescript\", \"esm\", \"commonjs\"]}\n import { useIntlayer } from \"preact-intlayer\";\n\n export const Hero = () => {\n const { headline, cta } = useIntlayer(\"hero-banner\");\n // → biến thể mặc định\n\n return (\n
\n

{headline}

\n {cta}\n
\n );\n };\n ```\n\n
\n \n ```tsx fileName=\"Hero.tsx\" contentDeclarationFormat={[\"typescript\", \"esm\", \"commonjs\"]}\n import { useIntlayer } from \"solid-intlayer\";\n\n export const Hero = () => {\n const content = useIntlayer(\"hero-banner\");\n // → biến thể mặc định\n\n return (\n
\n

{content().headline}

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

{{ content().headline }}

\n {{ content().cta }}\n
\n `,\n })\n export class HeroComponent {\n content = useIntlayer(\"hero-banner\");\n }\n ```\n\n
\n \n ```javascript fileName=\"hero.js\"\n import { useIntlayer } from \"vanilla-intlayer\";\n\n const { headline, cta } = useIntlayer(\"hero-banner\");\n\n document.body.innerHTML = `\n
\n

${headline}

\n ${cta}\n
\n `;\n ```\n\n
\n\n\n### Biến thể có tên\n\n```tsx\nconst { headline, cta } = useIntlayer(\"hero-banner\", {\n variant: \"black_friday\",\n});\n```\n\n### Biến thể có tên với ngôn ngữ cụ thể\n\n```tsx\nconst content = useIntlayer(\"hero-banner\", {\n variant: \"black_friday\",\n locale: \"vi\",\n});\n```\n\n## Các trường hợp sử dụng điển hình\n\n- Các thử nghiệm A/B nội dung được điều hướng bởi một khóa thử nghiệm\n- Biểu ngữ theo mùa hoặc biểu ngữ quảng cáo\n- Thông điệp được gắn cờ tính năng (feature flag)\n- Các chiến dịch tiếp thị cụ thể theo từng vùng địa lý\n","description":"Sử dụng trường siêu dữ liệu variant trong các tệp nội dung Intlayer để khai báo các lựa chọn nội dung thay thế được đặt tên (thử nghiệm A/B, biểu ngữ theo mùa, văn bản gắn cờ tính năng) và chuyển đổi giữa chúng tại runtime mà không cần thay đổi mã.","url":"https://intlayer.org/vi/doc/concept/variants","datePublished":"2026-06-12","dateModified":"2026-06-12","version":"9.0.0","keywords":"Biến Thể, Thử nghiệm A/B, Cờ Tính Năng, Nội Dung Động, 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

    Biến Thể

    Một biến thể (variant) là một tập hợp các tệp nội dung chia sẻ cùng một khóa từ điển (key) nhưng mỗi tệp mang một tên variant khác nhau. Intlayer phục vụ tệp phù hợp dựa trên bộ chọn được truyền vào useIntlayer.

    Khai báo các biến thể

    Mỗi tệp đại diện cho một lựa chọn thay thế có tên. Việc bỏ qua variant (hoặc đặt thành "default") sẽ đánh dấu tệp đó làm phương án mặc định (fallback).

    hero-banner.content.ts
    import { t, type Dictionary } from "intlayer";
    
    const dictionary = {
      key: "hero-banner",
      variant: "default",
      content: {
        headline: t({
          en: "Build faster with Intlayer",
          fr: "Développez plus vite avec Intlayer",
        }),
        cta: t({ en: "Get started", fr: "Commencer" }),
      },
    } satisfies Dictionary;
    
    export default dictionary;
    hero-banner.black-friday.content.ts
    import { t, type Dictionary } from "intlayer";
    
    const dictionary = {
      key: "hero-banner",
      variant: "black_friday",
      content: {
        headline: t({
          en: "50 % off — today only",
          fr: "−50 % — aujourd'hui seulement",
        }),
        cta: t({ en: "Shop now", fr: "Acheter maintenant" }),
      },
    } satisfies Dictionary;
    
    export default dictionary;

    Sử dụng biến thể

    Biến thể mặc định

    Hero.tsx
    import { useIntlayer } from "react-intlayer";
    
    export const Hero = () => {
      const { headline, cta } = useIntlayer("hero-banner");
      // → biến thể mặc định
    
      return (
        <section>
          <h1>{headline}</h1>
          <a>{cta}</a>
        </section>
      );
    };

    Biến thể có tên

    tsx
    const { headline, cta } = useIntlayer("hero-banner", {  variant: "black_friday",});

    Biến thể có tên với ngôn ngữ cụ thể

    tsx
    const content = useIntlayer("hero-banner", {  variant: "black_friday",  locale: "vi",});

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

    • Các thử nghiệm A/B nội dung được điều hướng bởi một khóa thử nghiệm
    • Biểu ngữ theo mùa hoặc biểu ngữ quảng cáo
    • Thông điệp được gắn cờ tính năng (feature flag)
    • Các chiến dịch tiếp thị cụ thể theo từng vùng địa lý