Author:
    Creation:2024-08-11Last update:2025-06-29

    अनुवाद

    अनुवाद परिभाषित करना

    intlayer में t फ़ंक्शन आपको कई भाषाओं में सामग्री घोषित करने की अनुमति देता है। यह फ़ंक्शन टाइप सुरक्षा सुनिश्चित करता है, यदि कोई अनुवाद गायब हो तो त्रुटि उत्पन्न करता है, जो विशेष रूप से TypeScript वातावरण में उपयोगी होता है।

    यहाँ अनुवादों के साथ सामग्री घोषित करने का एक उदाहरण दिया गया है।

    **/*.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>;

    स्थानीय सेटिंग्स के लिए कॉन्फ़िगरेशन

    सही अनुवाद प्रबंधन सुनिश्चित करने के लिए, आप intlayer.config.ts में स्वीकार किए गए स्थानीय सेटिंग्स को कॉन्फ़िगर कर सकते हैं। यह कॉन्फ़िगरेशन आपको उन भाषाओं को परिभाषित करने की अनुमति देता है जिन्हें आपका एप्लिकेशन सपोर्ट करता है:

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

    React कंपोनेंट्स में अनुवाद का उपयोग करना

    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.

    कस्टम कंटेंट ऑब्जेक्ट्स

    intlayer अनुवाद के लिए कस्टम कंटेंट ऑब्जेक्ट्स का समर्थन करता है, जिससे आप अधिक जटिल संरचनाओं को परिभाषित कर सकते हैं और टाइप सुरक्षा सुनिश्चित कर सकते हैं। यहाँ एक कस्टम ऑब्जेक्ट के साथ उदाहरण दिया गया है:

    **/*.content.ts
    import { t, type Dictionary } from "intlayer";
    
    interface ICustomContent {
      title: string;
      content: string;
    }
    
    const customContent = {
      key: "custom_content",
      content: {
        profileText: t<ICustomContent>({
          en: {
            title: "Page Title",
            content: "Page Content",
          },
          fr: {
            title: "Titre de la Page",
            content: "Contenu de la Page",
          },
          es: {
            title: "Título de la Página",
            content: "Contenido de la Página",
          },
        }),
      },
    } satisfies Dictionary;
    
    export default customContent;