Yazar:
    Oluşturma:2025-09-07Son güncelleme:2025-09-07

    Çeviri

    Çevirileri Tanımlama

    intlayer'daki t fonksiyonu, içeriği birden fazla dilde bildirmenizi sağlar. Bu fonksiyon tür güvenliğini sağlar ve herhangi bir çeviri eksikse hata verir, bu özellikle TypeScript ortamlarında kullanışlıdır.

    İşte çevirilerle içerik bildirme örneği.

    **/*.content.ts
    import { t, type Dictionary } from "intlayer";
    
    interface Content {
      welcomeMessage: string;
    }
    
    export default {
      key: "multi_lang",
      content: {
        welcomeMessage: t({
          en: "Welcome to our application",
          fr: "Bienvenue dans notre application",
          es: "Bienvenido a nuestra aplicación",
        }),
      },
    } satisfies Dictionary<Content>;

    Yerel Ayarlar için Yapılandırma

    Uygun çeviri işlemini sağlamak için, intlayer.config.ts'de kabul edilen yerel ayarları yapılandırabilirsiniz. Bu yapılandırma, uygulamanızın desteklediği dilleri tanımlamanızı sağlar:

    intlayer.config.ts
    import { Locales, type IntlayerConfig } from "intlayer";
    
    const config: IntlayerConfig = {
      internationalization: {
        locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH],
      },
    };
    
    export default config;

    React Bileşenlerinde Çevirileri Kullanma

    With react-intlayer, you can use translations in React components. Here's an example:

    **/*.tsx
    import type { FC } from "react";
    import { useIntlayer } from "react-intlayer";
    
    const MyComponent: FC = () => {
    const content = useIntlayer("multi_lang");
    
    return (
      <div>
        <p>{content.welcomeMessage}</p>
      </div>
    );
    };
    
    export default MyComponent;

    This component fetches the corresponding translation based on the current locale set in your application.