--- createdAt: 2026-06-12 updatedAt: 2026-06-12 title: Koleksi description: Gunakan bidang metadata item di file konten Intlayer untuk membangun koleksi terurut dari item yang dilokalkan yang dapat dipilih berdasarkan indeks saat runtime. keywords: - Koleksi - Daftar Konten - Konten Dinamis - Intlayer - Internasionalisasi slugs: - doc - concept - collections history: - version: 9.0.0 date: 2026-06-12 changes: "Rilis fitur kamus koleksi" author: aymericzip --- # Koleksi Sebuah **koleksi** (collection) adalah sekumpulan file konten yang memiliki kunci kamus (`key`) yang sama tetapi masing-masing mendeklarasikan indeks item (`item`) yang berbeda. Intlayer menggabungkannya menjadi satu daftar terurut pada waktu build. ## Mendeklarasikan item koleksi Setiap file mewakili satu item. Bidang `item` adalah posisinya dalam daftar (dimulai dari 1). ```ts fileName="faq.1.content.ts" contentDeclarationFormat={["typescript", "esm", "commonjs"]} import { t, type Dictionary } from "intlayer"; const dictionary = { key: "faq", item: 1, content: { question: t({ en: "What is Intlayer?", fr: "Qu'est-ce qu'Intlayer ?" }), answer: t({ en: "An i18n toolkit.", fr: "Une boîte à outils i18n." }), }, } satisfies Dictionary; export default dictionary; ``` ```ts fileName="faq.2.content.ts" contentDeclarationFormat={["typescript", "esm", "commonjs"]} import { t, type Dictionary } from "intlayer"; const dictionary = { key: "faq", item: 2, content: { question: t({ en: "Is it free?", fr: "Est-ce gratuit ?" }), answer: t({ en: "Yes, open-source.", fr: "Oui, open-source." }), }, } satisfies Dictionary; export default dictionary; ``` ## Mengonsumsi koleksi ### Semua item ```tsx fileName="FAQ.tsx" import { useIntlayer } from "react-intlayer"; export const FAQ = () => { const items = useIntlayer("faq"); // { question: string; answer: string }[] return ( ); }; ``` ```tsx fileName="FAQ.tsx" import { useIntlayer } from "next-intlayer"; export const FAQ = () => { const items = useIntlayer("faq"); // { question: string; answer: string }[] return ( ); }; ``` ```vue fileName="FAQ.vue" ``` ```svelte fileName="FAQ.svelte" ``` ```tsx fileName="FAQ.tsx" import { useIntlayer } from "preact-intlayer"; export const FAQ = () => { const items = useIntlayer("faq"); // { question: string; answer: string }[] return ( ); }; ``` ```tsx fileName="FAQ.tsx" import { useIntlayer } from "solid-intlayer"; import { For } from "solid-js"; export const FAQ = () => { const items = useIntlayer("faq"); // { question: string; answer: string }[] return ( ); }; ``` ```typescript fileName="faq.component.ts" import { Component } from "@angular/core"; import { useIntlayer } from "angular-intlayer"; @Component({ selector: "app-faq", template: ` `, }) export class FAQComponent { items = useIntlayer("faq"); } ``` ```javascript fileName="faq.js" import { useIntlayer } from "vanilla-intlayer"; const faq = useIntlayer("faq"); faq.forEach((item) => { console.log(item.question); console.log(item.answer); }); ``` ### Item tunggal berdasarkan indeks ```tsx const faq2 = useIntlayer("faq", { item: 2 }); // → { question: string; answer: string } ``` ### Item tunggal dengan lokalitas eksplisit ```tsx const faq2Id = useIntlayer("faq", { item: 2, locale: "id" }); ``` ## Kasus penggunaan umum - Daftar FAQ (Pertanyaan Umum) - Tingkatan harga / paket harga - Slide karousel / slider - Petunjuk langkah demi langkah