Author:
    Creation:2025-02-07Last update:2025-06-29

    नेस्टिंग / उप सामग्री संदर्भ

    नेस्टिंग कैसे काम करता है

    Intlayer में, नेस्टिंग nest फ़ंक्शन के माध्यम से प्राप्त की जाती है, जो आपको किसी अन्य शब्दकोश से सामग्री को संदर्भित करने और पुन: उपयोग करने की अनुमति देता है। सामग्री को डुप्लिकेट करने के बजाय, आप मौजूदा सामग्री मॉड्यूल को उसकी कुंजी द्वारा इंगित कर सकते हैं।

    नेस्टिंग सेटअप करना

    अपने Intlayer प्रोजेक्ट में नेस्टिंग सेटअप करने के लिए, आप पहले वह आधार सामग्री परिभाषित करते हैं जिसे आप दोबारा उपयोग करना चाहते हैं। फिर, एक अलग सामग्री मॉड्यूल में, आप उस सामग्री को import करने के लिए nest फ़ंक्शन का उपयोग करते हैं।

    Base Dictionary

    नीचे एक base dictionary का उदाहरण दिया गया है जिसे किसी दूसरे dictionary में nest किया जा सकता है:

    firstDictionary.content.ts
    import { type Dictionary } from "intlayer";
    
    const firstDictionary = {
      key: "key_of_my_first_dictionary",
      content: {
        content: "content",
        subContent: {
          contentNumber: 0,
          contentString: "string",
        },
      },
    } satisfies Dictionary;
    
    export default firstDictionary;
    

    Nest के साथ संदर्भित करना

    अब एक और content module बनाएं जो nest फ़ंक्शन का उपयोग करके उपरोक्त content को संदर्भित करे। आप संपूर्ण content या किसी विशिष्ट nested value को संदर्भित कर सकते हैं:

    secondDictionary.content.ts
    import { nest, type Dictionary } from "intlayer";
    
    const myNestingContent = {
      key: "key_of_my_second_dictionary",
      content: {
        // संपूर्ण dictionary को संदर्भित करता है:
        fullNestedContent: nest("key_of_my_first_dictionary"),
        // किसी विशिष्ट nested value को संदर्भित करता है:
        partialNestedContent: nest(
          "key_of_my_first_dictionary",
          "subContent.contentNumber"
        ),
      },
    } satisfies Dictionary;
    
    export default myNestingContent;
    

    दूसरे पैरामीटर के रूप में, आप उस content के भीतर किसी nested value का पथ निर्दिष्ट कर सकते हैं। जब कोई पथ प्रदान नहीं किया जाता है, तो संदर्भित dictionary की संपूर्ण content वापस की जाती है।

    नेस्टिंग सेट करना

    To use nested content in a React component, leverage the useIntlayer hook from the react-intlayer package. This hook retrieves the correct content based on the specified key. Here's an example of how to use it:

    **/*.tsx
    import type { FC } from "react";
    import { useIntlayer } from "react-intlayer";
    
    const NestComponent: FC = () => {
      const { fullNestedContent, partialNestedContent } = useIntlayer(
        "key_of_my_second_dictionary"
      );
    
      return (
        <div>
          <p>Full Nested Content: {JSON.stringify(fullNestedContent)}</p>
          <p>Partial Nested Value: {partialNestedContent}</p>
        </div>
      );
    };
    
    export default NestComponent;
    

    To use nested content in Next.js Client Components, retrieve it via the useIntlayer hook. Here's an example:

    **/*.tsx
    "use client";
    
    import type { FC } from "react";
    import { useIntlayer } from "next-intlayer";
    
    const NestComponent: FC = () => {
      const { fullNestedContent, partialNestedContent } = useIntlayer(
        "key_of_my_second_dictionary"
      );
    
      return (
        <div>
          <p>Full Nested Content: {JSON.stringify(fullNestedContent)}</p>
          <p>Partial Nested Value: {partialNestedContent}</p>
        </div>
      );
    };
    
    export default NestComponent;
    

    To use nested content in Vue components, retrieve it via the useIntlayer hook. Here's an example:

    **/*.vue
    <script setup lang="ts">
    import { useIntlayer } from "vue-intlayer";
    
    const { fullNestedContent, partialNestedContent } = useIntlayer(
      "key_of_my_second_dictionary"
    );
    </script>
    
    <template>
      <div>
        <p>Full Nested Content: {{ JSON.stringify(fullNestedContent) }}</p>
        <p>Partial Nested Value: {{ partialNestedContent }}</p>
      </div>
    </template>
    

    To use nested content in Svelte components, retrieve it via the useIntlayer hook. The store is accessed with $. Here's an example:

    **/*.svelte
    <script lang="ts">
    import { useIntlayer } from "svelte-intlayer";
    
    const content = useIntlayer("key_of_my_second_dictionary");
    </script>
    
    <div>
      <p>Full Nested Content: {JSON.stringify($content.fullNestedContent)}</p>
      <p>Partial Nested Value: {$content.partialNestedContent}</p>
    </div>
    

    To use nested content in Preact components, retrieve it via the useIntlayer hook. Here's an example:

    **/*.tsx
    import type { FC } from "preact";
    import { useIntlayer } from "preact-intlayer";
    
    const NestComponent: FC = () => {
      const { fullNestedContent, partialNestedContent } = useIntlayer(
        "key_of_my_second_dictionary"
      );
    
      return (
        <div>
          <p>Full Nested Content: {JSON.stringify(fullNestedContent)}</p>
          <p>Partial Nested Value: {partialNestedContent}</p>
        </div>
      );
    };
    
    export default NestComponent;
    

    To use nested content in SolidJS components, retrieve it via the useIntlayer hook. Here's an example:

    **/*.tsx
    import type { Component } from "solid-js";
    import { useIntlayer } from "solid-intlayer";
    
    const NestComponent: Component = () => {
      const { fullNestedContent, partialNestedContent } = useIntlayer(
        "key_of_my_second_dictionary"
      );
    
      return (
        <div>
          <p>Full Nested Content: {JSON.stringify(fullNestedContent)}</p>
          <p>Partial Nested Value: {partialNestedContent}</p>
        </div>
      );
    };
    
    export default NestComponent;
    

    To use nested content in Angular components, retrieve it via the useIntlayer hook. Here's an example:

    app.component.ts
    import { Component } from "@angular/core";
    import { useIntlayer } from "angular-intlayer";
    
    @Component({
      selector: "app-nest",
      template: `
        <div>
          <p>
            Full Nested Content: {{ JSON.stringify(content().fullNestedContent) }}
          </p>
          <p>Partial Nested Value: {{ content().partialNestedContent }}</p>
        </div>
      `,
    })
    export class NestComponent {
      content = useIntlayer("key_of_my_second_dictionary");
      JSON = JSON;
    }
    

    To use nested content with vanilla-intlayer, retrieve it via the useIntlayer hook. Here's an example:

    **/*.ts
    import { installIntlayer, useIntlayer } from "vanilla-intlayer";
    
    installIntlayer();
    
    const content = useIntlayer("key_of_my_second_dictionary").onChange(
      (newContent) => {
        document.getElementById("nested")!.textContent =
          newContent.partialNestedContent;
      }
    );
    
    // Initial render
    document.getElementById("nested")!.textContent = content.partialNestedContent;
    

    अतिरिक्त संसाधन

    कॉन्फ़िगरेशन और उपयोग पर अधिक विस्तृत जानकारी के लिए, निम्नलिखित संसाधनों का संदर्भ लें:

    ये संसाधन विभिन्न वातावरणों और विभिन्न फ्रेमवर्क्स के साथ Intlayer की सेटअप और उपयोग के बारे में और अधिक जानकारी प्रदान करते हैं।