<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: AJ Nasim</title>
    <description>The latest articles on DEV Community by AJ Nasim (@ajnasim).</description>
    <link>https://dev.to/ajnasim</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F606737%2Fec0b21a2-5482-4112-8098-394d83f1704b.JPG</url>
      <title>DEV Community: AJ Nasim</title>
      <link>https://dev.to/ajnasim</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ajnasim"/>
    <language>en</language>
    <item>
      <title>React Multi-language feature using i18n or internationalization</title>
      <dc:creator>AJ Nasim</dc:creator>
      <pubDate>Mon, 01 Jan 2024 14:39:43 +0000</pubDate>
      <link>https://dev.to/ajnasim/react-multi-language-feature-using-i18n-or-internationalization-3nm</link>
      <guid>https://dev.to/ajnasim/react-multi-language-feature-using-i18n-or-internationalization-3nm</guid>
      <description>&lt;p&gt;ReactJS doesn't have built-in features to finish your Multilanguage Feature on your website. But there have an amazing NPM package called react-i18next is based on i18next. So let's get started.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: install the packages
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;npm install react-i18next i18next&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Create the file structure
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2h266qqvmam7q1x868wx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2h266qqvmam7q1x868wx.png" alt="Image description" width="600" height="189"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I hope you will write text/data in the translations.js like this&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft6jurwl21rnj8rdss1wg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft6jurwl21rnj8rdss1wg.png" alt="Image description" width="352" height="118"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The config.js file contains the set up for the i18n instance. The two JSON files will hold the text that goes in the app. en for English and es for Spanish. If you are following along, create the file structure in the boilerplate.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: Configure the i18n instance
&lt;/h2&gt;

&lt;p&gt;The i18n instance will hold all of your translations, the current language, and other info and methods needed. You can configure it in the config.js file like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxzc85vpf0w8t8fm81usv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxzc85vpf0w8t8fm81usv.png" alt="Image description" width="694" height="462"&gt;&lt;/a&gt;&lt;br&gt;
At the top, import the necessary dependencies. Next, the use(initReactI18next) will bind react-i18next to the i18n instance.&lt;/p&gt;

&lt;p&gt;The first two properties of the init object parameter are a fallback language (fallbackLng) and default language (lng). I set both of these to English (en).&lt;/p&gt;

&lt;p&gt;The resources are the JSON files with the translations that you created in the last step. The namespaces (ns) and default namespace (defaultNS) are the keys from the resources object.&lt;/p&gt;

&lt;p&gt;You can split your translations into multiple files (namespaces) if you have a large app to simplify the files. In which case, you would add more than just the one file in the resources object and add it to the namespaces array. This app is small, so all the translations can go in one file.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: Add the i18n instance to your app
&lt;/h2&gt;

&lt;p&gt;In the index.js file of the boilerplate, which contains the entire app, import the i18n instance you created like this: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvte4xyqmtjb0bd4cyd84.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvte4xyqmtjb0bd4cyd84.png" alt="Image description" width="677" height="277"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5: Change language function
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgr7ebva7xj3qpu1owbmp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgr7ebva7xj3qpu1owbmp.png" alt="Image description" width="516" height="437"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Last Step : Now let's use them
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsqkz66sdsonyslzxbonp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsqkz66sdsonyslzxbonp.png" alt="Image description" width="466" height="178"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I hope everything is working&lt;br&gt;
Thank you&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>learning</category>
      <category>frontend</category>
    </item>
    <item>
      <title>First journey - AJ Nasim</title>
      <dc:creator>AJ Nasim</dc:creator>
      <pubDate>Wed, 31 Mar 2021 22:49:57 +0000</pubDate>
      <link>https://dev.to/ajnasim/first-journey-aj-nasim-51hf</link>
      <guid>https://dev.to/ajnasim/first-journey-aj-nasim-51hf</guid>
      <description>&lt;p&gt;I have just started my journey at this site&lt;/p&gt;

</description>
      <category>ajnasim</category>
      <category>developer</category>
      <category>webdeveloper</category>
    </item>
  </channel>
</rss>
