--- createdAt: 2024-03-07 updatedAt: 2025-09-30 title: React ve Next.js'te bir bileşeni çok dilli (i18n kütüphanesi) yapma description: Intlayer ile çok dilli bir React veya Next.js bileşeni oluşturmak için yerelleştirilmiş içeriğin nasıl beyan edileceğini ve alınacağını öğrenin. keywords: - i18n - bileşen - react - çok dilli - next.js - intlayer slugs: - doc - component - i18n applicationTemplate: https://github.com/aymericzip/intlayer-vite-react-template youtubeVideo: https://www.youtube.com/watch?v=dS9L7uJeak4 --- # Intlayer ile bir bileşeni çok dilli (i18n) nasıl yaparsınız Bu rehber, iki yaygın kurulumda bir UI bileşenini çok dilli yapmak için gereken asgari adımları gösterir: - React (Vite/SPA) - Next.js (App Router) Öncelikle içeriğinizi beyan edecek, ardından bileşeninizde içeriği alacaksınız. ## 1) İçeriğinizi beyan edin (React ve Next.js için ortak) Bileşeninizin yakınında bir içerik beyan dosyası oluşturun. Bu, çevirileri kullanıldıkları yere yakın tutar ve tür güvenliğini sağlar. ```ts fileName="component.content.ts" import { t, type Dictionary } from "intlayer"; const componentContent = { key: "component-example", content: { title: t({ en: "Hello", fr: "Bonjour", es: "Hola", }), description: t({ en: "A multilingual React component", fr: "Un composant React multilingue", es: "Un componente React multilingüe", }), }, } satisfies Dictionary; export default componentContent; ``` Yapılandırma dosyalarını tercih ediyorsanız JSON da desteklenmektedir. ```json fileName="component.content.json" { "$schema": "https://intlayer.org/schema.json", "key": "component-example", "content": { "title": { "nodeType": "translation", "translation": { "en": "Hello", "fr": "Bonjour", "es": "Hola" } }, "description": { "nodeType": "translation", "translation": { "en": "A multilingual React component", "fr": "Un composant React multilingue", "es": "Un componente React multilingüe" } } } } ``` ## 2) İçeriğinizi alın ### Durum A — React uygulaması (Vite/SPA) Varsayılan yaklaşım: Anahtarla almak için `useIntlayer` kullanın. Bu, bileşenleri hafif ve tipli tutar. ```tsx fileName="ComponentExample.tsx" import { useIntlayer } from "react-intlayer"; export function ComponentExample() { const content = useIntlayer("component-example"); return (
{content.description}
{content.description}
> ); } ``` Alternatif: Çağrı noktasında yapıyı yan yana koymayı tercih ederseniz, `useDictionary` tüm tanımlı nesneyi okuyabilir. ```tsx fileName="ComponentWithDictionary.tsx" import { useDictionary } from "react-intlayer"; import componentContent from "./component.content"; export function ComponentWithDictionary() { const { title, description } = useDictionary(componentContent); return ({description}
{content.description}
> ); } ``` ```tsx fileName="app/[locale]/example/ClientComponent.tsx" "use client"; import { useIntlayer } from "next-intlayer"; export function ClientComponent() { const content = useIntlayer("component-example"); return ({content.description}