--- createdAt: 2025-09-07 updatedAt: 2025-09-07 title: useI18n Hook Dokümantasyonu | react-intlayer description: react-intlayer paketinde useI18n hook'unun nasıl kullanılacağını öğrenin keywords: - useI18n - i18n - çeviri - sözlük - Intlayer - uluslararasılaştırma - dokümantasyon - Next.js - JavaScript - React slugs: - doc - packages - react-intlayer - useI18n history: - version: 6.0.0 date: 2025-06-29 changes: Initial writing of `useI18n` hook documentation --- # React Entegrasyonu: `useI18n` Hook Dokümantasyonu Bu bölüm, React uygulamalarında içerik yerelleştirmesini verimli bir şekilde etkinleştirmek için `useI18n` hook'unun nasıl kullanılacağına ilişkin detaylı rehberlik sağlar. ## React'te `useI18n` İçe Aktarma `useI18n` hook'u, bağlama göre içe aktararak React uygulamalarına entegre edilebilir: - **İstemci Bileşenleri:** ```typescript codeFormat="typescript" import { useI18n } from "react-intlayer"; // İstemci tarafı React bileşenlerinde kullanılır ``` ```javascript codeFormat="esm" import { useI18n } from "react-intlayer"; // İstemci tarafı React bileşenlerinde kullanılır ``` ```javascript codeFormat="commonjs" const { useI18n } = require("react-intlayer"); // İstemci tarafı React bileşenlerinde kullanılır ``` - **Sunucu Bileşenleri:** ```typescript codeFormat="commonjs" import { useI18n } from "react-intlayer/server"; // Sunucu tarafı React bileşenlerinde kullanılır ``` ```javascript codeFormat="esm" import { useI18n } from "react-intlayer/server"; // Sunucu tarafı React bileşenlerinde kullanılır ``` ```javascript codeFormat="commonjs" const { useI18n } = require("react-intlayer/server"); // Sunucu tarafı React bileşenlerinde kullanılır ``` ## Parametreler Bu hook iki parametre kabul eder: 1. **`namespace`**: Çeviri anahtarlarını kapsamak için bir sözlük ad alanı. 2. **`locale`** (isteğe bağlı): İstenen yerel ayar. Belirtilmezse, bağlamın yerel ayarına varsayılan olur. ## Sözlük Tüm sözlük anahtarları, tür güvenliğini geliştirmek ve hataları önlemek için içerik bildirim dosyalarında bildirilmelidir. [Yapılandırma talimatlarını burada](https://github.com/aymericzip/intlayer/blob/main/docs/docs/tr/dictionary/get_started.md) bulabilirsiniz. ## React'te Kullanım Örnekleri React bileşenlerinde `useI18n` hook'unun kullanımı örnekleri: ```tsx fileName="src/App.tsx" codeFormat="typescript" import type { FC } from "react"; import { ClientComponentExample, ServerComponentExample } from "@components"; import { IntlayerProvider } from "react-intlayer"; import { useI18n, IntlayerServerProvider } from "react-intlayer/server"; import { Locales } from "intlayer"; const App: FC<{ locale: Locales }> = ({ locale }) => { const t = useI18n("home-page", locale); return ( <>

{t("introduction")}

); }; ``` ```jsx fileName="src/app.jsx" codeFormat="esm" import { ClientComponentExample, ServerComponentExample } from "@components"; import { IntlayerProvider } from "react-intlayer"; import { IntlayerServerProvider, useI18n } from "react-intlayer/server"; const App = ({ locale }) => { const t = useI18n("home-page", locale); return ( <>

{t("introduction")}

); }; ``` ```jsx fileName="src/app.cjs" codeFormat="commonjs" const { IntlayerProvider } = require("react-intlayer"); const { IntlayerServerProvider, useI18n } = require("react-intlayer/server"); const App = ({ locale }) => { const t = useI18n("home-page", locale); return ( <>

{t("introduction")}

); }; ``` ```tsx fileName="src/components/ComponentExample.tsx" codeFormat="typescript" import type { FC } from "react"; import { useI18n } from "react-intlayer"; const ComponentExample: FC = () => { const t = useI18n("component-example"); return (

{t("title")}

{/* Başlığı görüntüle */}

{t("description")}

{/* Açıklamayı görüntüle */}
); }; ``` ```jsx fileName="src/components/ComponentExample.jsx" codeFormat="esm" import { useI18n } from "react-intlayer"; const ComponentExample = () => { const t = useI18n("component-example"); return (

{t("title")}

{/* Başlığı görüntüle */}

{t("description")}

{/* Açıklamayı görüntüle */}
); }; ``` ```jsx fileName="src/components/ComponentExample.cjs" codeFormat="commonjs" const { useI18n } = require("react-intlayer"); const ComponentExample = () => { const t = useI18n("component-example"); return (

{t("title")}

{/* Başlığı görüntüle */}

{t("description")}

{/* Açıklamayı görüntüle */}
); }; ``` ```tsx fileName="src/components/ServerComponentExample.tsx" codeFormat="typescript" import { useI18n } from "react-intlayer/server"; const ServerComponentExample = () => { const t = useI18n("server-component"); return (

{t("title")}

{/* Başlığı görüntüle */}

{t("description")}

{/* Açıklamayı görüntüle */}
); }; ``` ```jsx fileName="src/components/ServerComponentExample.jsx" codeFormat="esm" import { useI18n } from "react-intlayer/server"; const ServerComponentExample = () => { const t = useI18n("server-component"); return (

{t("title")}

{/* Başlığı görüntüle */}

{t("description")}

{/* Açıklamayı görüntüle */}
); }; ``` ```jsx fileName="src/components/ServerComponentExample.cjs" codeFormat="commonjs" const { useI18n } = require("react-intlayer/server"); const ServerComponentExample = () => { const t = useI18n("server-component"); return (

{t("title")}

{t("description")}

); }; ``` ## Özellik İşleme Özellikleri yerelleştirirken, çeviri değerlerine uygun şekilde erişin: ```jsx ``` ## Ek Kaynaklar - **Intlayer Görsel Düzenleyici**: Daha sezgisel içerik yönetimi için görsel düzenleyici dokümantasyonuna [burada](https://github.com/aymericzip/intlayer/blob/main/docs/docs/tr/intlayer_visual_editor.md) bakın. Bu bölüm, React uygulamalarında `useI18n` hook'unun entegrasyonuna özel olarak odaklanır, yerelleştirme sürecini basitleştirir ve farklı yerel ayarlar arasında içerik tutarlılığını sağlar. ## Dokümantasyon Geçmişi - 6.0.0 - 2025-06-29: `useI18n` hook dokümantasyonunun ilk yazımı # React Integration: `useI18n` Hook Documentation This section provides detailed guidance on how to use the `useI18n` hook within React applications, enabling efficient content localization. ## Importing `useI18n` in React The `useI18n` hook can be imported and integrated into React applications according to the context as follows: - **Client Components:** ```typescript codeFormat="typescript" import { useI18n } from "react-intlayer"; // Use in client-side React components ``` ```javascript codeFormat="esm" import { useI18n } from "react-intlayer"; // Use in client-side React components ``` ```javascript codeFormat="commonjs" const { useI18n } = require("react-intlayer"); // Use in client-side React components ``` - **Server Components:** ```typescript codeFormat="commonjs" import { useI18n } from "react-intlayer/server"; // Use in server-side React components ``` ```javascript codeFormat="esm" import { useI18n } from "react-intlayer/server"; // Use in server-side React components ``` ```javascript codeFormat="commonjs" const { useI18n } = require("react-intlayer/server"); // Use in server-side React components ``` ## Parameters This hook accepts two parameters: 1. **`namespace`**: A dictionary namespace to scope the translation keys. 2. **`locale`** (optional): The desired locale. If not specified, the context's locale will be used as default. ## Dictionary All dictionary keys must be declared within content declaration files to enhance type safety and prevent errors. [Configuration instructions can be found here](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/dictionary/content_file.md). ## Usage Examples in React Examples of using the `useI18n` hook within React components: ```tsx fileName="src/App.tsx" codeFormat="typescript" import type { FC } from "react"; import { ClientComponentExample, ServerComponentExample } from "@components"; import { IntlayerProvider } from "react-intlayer"; import { useI18n, IntlayerServerProvider } from "react-intlayer/server"; import { Locales } from "intlayer"; const App: FC<{ locale: Locales }> = ({ locale }) => { const t = useI18n("home-page", locale); return ( <>

{t("introduction")}

); }; ``` ```jsx fileName="src/app.jsx" codeFormat="esm" import { ClientComponentExample, ServerComponentExample } from "@components"; import { IntlayerProvider } from "react-intlayer"; import { IntlayerServerProvider, useI18n } from "react-intlayer/server"; const App = ({ locale }) => { const t = useI18n("home-page", locale); return ( <>

{t("introduction")}

); }; ``` ```jsx fileName="src/app.cjs" codeFormat="commonjs" const { IntlayerProvider } = require("react-intlayer"); const { IntlayerServerProvider, useI18n } = require("react-intlayer/server"); const App = ({ locale }) => { const t = useI18n("home-page", locale); return ( <>

{t("introduction")}

); }; ``` ```tsx fileName="src/components/ComponentExample.tsx" codeFormat="typescript" import type { FC } from "react"; import { useI18n } from "react-intlayer"; const ComponentExample: FC = () => { const t = useI18n("component-example"); return (

{t("title")}

{/* Display the title */}

{t("description")}

{/* Display the description */}
); }; ``` ```jsx fileName="src/components/ComponentExample.jsx" codeFormat="esm" import { useI18n } from "react-intlayer"; const ComponentExample = () => { const t = useI18n("component-example"); return (

{t("title")}

{/* Display the title */}

{t("description")}

{/* Display the description */}
); }; ``` ```jsx fileName="src/components/ComponentExample.cjs" codeFormat="commonjs" const { useI18n } = require("react-intlayer"); const ComponentExample = () => { const t = useI18n("component-example"); return (

{t("title")}

{/* Display the title */}

{t("description")}

{/* Display the description */}
); }; ``` ```tsx fileName="src/components/ServerComponentExample.tsx" codeFormat="typescript" import { useI18n } from "react-intlayer/server"; const ServerComponentExample = () => { const t = useI18n("server-component"); return (

{t("title")}

{/* Display the title */}

{t("description")}

{/* Display the description */}
); }; ``` ```jsx fileName="src/components/ServerComponentExample.jsx" codeFormat="esm" import { useI18n } from "react-intlayer/server"; const ServerComponentExample = () => { const t = useI18n("server-component"); return (

{t("title")}

{/* Display the title */}

{t("description")}

{/* Display the description */}
); }; ``` ```jsx fileName="src/components/ServerComponentExample.cjs" codeFormat="commonjs" const { useI18n } = require("react-intlayer/server"); const ServerComponentExample = () => { const t = useI18n("server-component"); return (

{t("title")}

{t("description")}

); }; ``` ## Attribute Handling When localizing attributes, access the translation values appropriately: ```jsx ``` ## Additional Resources - **Intlayer Visual Editor**: For a more intuitive content management experience, refer to the visual editor documentation [here](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/intlayer_visual_editor.md). This section specifically covers the integration of the `useI18n` hook in React applications, simplifying the localization process and ensuring content consistency across different locales.