<?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: Kovacs Nicolas</title>
    <description>The latest articles on DEV Community by Kovacs Nicolas (@nicovak).</description>
    <link>https://dev.to/nicovak</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%2F80077%2F9cf82aca-cfc0-4b7d-940f-1a7792c6e852.png</url>
      <title>DEV Community: Kovacs Nicolas</title>
      <link>https://dev.to/nicovak</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nicovak"/>
    <language>en</language>
    <item>
      <title>react-native-localize and i18n-js</title>
      <dc:creator>Kovacs Nicolas</dc:creator>
      <pubDate>Wed, 30 Jan 2019 17:50:59 +0000</pubDate>
      <link>https://dev.to/nicovak/react-native-localize-and-i18n-js-25l6</link>
      <guid>https://dev.to/nicovak/react-native-localize-and-i18n-js-25l6</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F0%2AJ_HDdN0RoaW7cNg8" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F0%2AJ_HDdN0RoaW7cNg8"&gt;&lt;/a&gt;Photo by &lt;a href="https://unsplash.com/@kylejglenn?utm_source=medium&amp;amp;utm_medium=referral" rel="noopener noreferrer"&gt;Kyle Glenn&lt;/a&gt; on &lt;a href="https://unsplash.com?utm_source=medium&amp;amp;utm_medium=referral" rel="noopener noreferrer"&gt;Unsplash&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Initially posted on Medium&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Recently &lt;strong&gt;react-native-i18n&lt;/strong&gt; has been deprecated in favor of &lt;strong&gt;react-native-localize&lt;/strong&gt; , here is how you can keep the same logic as before without recode It all over again. It’s the simplest way I could found.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/react-native-community/react-native-localize" rel="noopener noreferrer"&gt;react-native-community/react-native-localize&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/fnando/i18n-js" rel="noopener noreferrer"&gt;fnando/i18n-js&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;First, install the new dependencies. You should unlink &lt;strong&gt;react-native-i18n&lt;/strong&gt; if you had It and link the new ones.&lt;/p&gt;

&lt;p&gt;yarn add react-native-localize&lt;/p&gt;

&lt;p&gt;yarn add i18n-js&lt;/p&gt;

&lt;p&gt;You should have in your &lt;strong&gt;package.json&lt;/strong&gt; something like this :&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;If you are using react-native ≥ &lt;strong&gt;0.60&lt;/strong&gt; you don’t need linking anymore and you can pass the next quoted step.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Don’t forget to link new dependencies, for more informations go to github pages linked above.&lt;/p&gt;

&lt;p&gt;react-native link&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now create a file where you will initialize &lt;strong&gt;i18n-js&lt;/strong&gt; , let’s call It &lt;strong&gt;i18n.js&lt;/strong&gt; for example in a &lt;strong&gt;src/utils&lt;/strong&gt; folder&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Now in the same folder create a new one named &lt;strong&gt;locales&lt;/strong&gt; for example and create a new file for each locale you want.&lt;/p&gt;

&lt;p&gt;Example of  &lt;strong&gt;en.js&lt;/strong&gt;&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Example of  &lt;strong&gt;fr.js&lt;/strong&gt;&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Don’t forget If you add more locales to import them in  &lt;strong&gt;i18n.js&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now in any component of your app, import the file created in the first step and initiate &lt;strong&gt;I18n&lt;/strong&gt; as before&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;If you want to get current locale you can use&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;That’s all, I hope It will help you to understand how to achieve It. Any comments or recommandations are welcome&lt;/p&gt;

&lt;p&gt;Happy coding ;)&lt;/p&gt;

</description>
      <category>reactnative</category>
      <category>javascript</category>
      <category>i18n</category>
    </item>
  </channel>
</rss>
