<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Kaushal Basnet on Medium]]></title>
        <description><![CDATA[Stories by Kaushal Basnet on Medium]]></description>
        <link>https://medium.com/@kaushal.basnet?source=rss-c51b60331d32------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*aW_Qa41q1hNdgZ1crMPlXw.jpeg</url>
            <title>Stories by Kaushal Basnet on Medium</title>
            <link>https://medium.com/@kaushal.basnet?source=rss-c51b60331d32------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 18:00:44 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kaushal.basnet/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Internationalize the Next.js application using next-i18next]]></title>
            <link>https://articles.wesionary.team/internationalize-the-next-js-application-using-next-i18next-4fa3d4e6a2b0?source=rss-c51b60331d32------2</link>
            <guid isPermaLink="false">https://medium.com/p/4fa3d4e6a2b0</guid>
            <category><![CDATA[text-translation]]></category>
            <category><![CDATA[react-i18next]]></category>
            <category><![CDATA[i18n]]></category>
            <category><![CDATA[i18next]]></category>
            <category><![CDATA[i18n-js]]></category>
            <dc:creator><![CDATA[Kaushal Basnet]]></dc:creator>
            <pubDate>Mon, 25 Jul 2022 04:33:15 GMT</pubDate>
            <atom:updated>2022-08-16T07:09:32.810Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xjH6kGi71QzgS4ImTCQZrA.jpeg" /></figure><h4>Translating web applications into multiple languages is a common requirement. Internationalization is an important feature that is used to overcome the language barrier among people who use a particular software application.</h4><h3>Why is i18next better than other libraries?</h3><p>I18next is flexible enough to adapt to the needs of the developers. It provides a complete method for localizing the product as well as the other standard i18n features. The other important feature is the scalability that allows us to separate translations into multiple files and load them on demand.<br>In this tutorial, we’ll walk you through Internationalizing the Next.js application using i18next, covering everything from library installation and setup to the ins and outs of real-world internationalization.</p><p>You can check out the demo <a href="https://github.com/kazi21220/i18next-practice"><strong>here.</strong></a></p><h3>Getting started with next-i18next</h3><p>First, we need to create the Next.js application with TypeScript. Enter the following into the terminal.</p><pre>If you want to start with a TypeScript project you can use the --typescript flag:</pre><pre>npx create-next-app@latest --typescript<br># or<br>yarn create next-app --typescript<br># or<br>pnpm create next-app --typescript</pre><h3>Adding i18n</h3><p><strong>Installation and setting up next-i18next</strong></p><pre>#npm<br>npm i next-i18next </pre><pre>#yarn<br>yarn add next-i18next</pre><blockquote>In the <strong><em>next-i18next.config.js</em></strong><em> </em>file, We are going to have two languages for our demo: default English (en), and another language Japanese (ja).</blockquote><pre>// next-i18next.config.js</pre><pre>module.exports = {</pre><pre>i18n: {</pre><pre>defaultLocale: &quot;en&quot;,</pre><pre>locales: [&quot;en&quot;, &quot;ja&quot;],</pre><pre>},<br>};</pre><p>In this code block, locales are all the languages we want to support and defaultLocale is the default language.</p><p><em>Add next-i18next.config.js file in next.config.js as I18n:</em></p><pre>//next.config.js</pre><pre>/** @type {import(&#39;next&#39;).NextConfig} */</pre><pre>const nextConfig = {</pre><pre>I18n,</pre><pre>reactStrictMode: true,</pre><pre>swcMinify: true,</pre><pre>}<br>module.exports = nextConfig;</pre><blockquote>The next-i18next library uses the same i18n config structure that Next requires. So instead of having to manage the same settings in two places, we simply import the next-i18next config into next.config.js</blockquote><blockquote>Wrap the main page i.e, <strong><em>Myapp</em></strong> while export <strong><em>appWithTranslation</em></strong><em>:</em></blockquote><pre>// _app.tsx</pre><pre>import type { AppProps } from “next/app”;<br>import “../styles/globals.css”;<br>import { appWithTranslation } from “next-i18next”;</pre><pre>function MyApp({ Component, pageProps }: AppProps) {<br>return &lt;Component {…pageProps} /&gt;;<br>}<br>export default appWithTranslation(MyApp);</pre><blockquote>Now for use, you should add<strong><em> getStaticProps() </em></strong><em>in the pages:</em></blockquote><pre>//pages file</pre><pre>import type { NextPage } from “next”;<br>import Translation from “../components/Translation”;<br>import { serverSideTranslations } from“next-i18next/serverSideTranslations”;<br>const Home: NextPage = () =&gt; {<br>return&lt;Translation /&gt;<br>};<br>export default Home;<br>export async function getStaticProps({ locale }: any) {<br>return {<br>props: { …(await serverSideTranslations(locale, [“common”])),<br>// Will be passed to the page component as props<br>},};}</pre><p>The severSideTranslations function accepts a locale as the first argument and the namespaces required for this page as the second argument. This ensures that our app only has to load the namespaces needed for the page. The locale is passed down from getStaticProps by Next.</p><p><em>For use in</em> <strong>components </strong><em>you should add</em> <strong>useTranslation():</strong></p><p>Lastly, let’s import the useTranslation hook from next-i18next.</p><pre>//components/Translation/index.tsx</pre><pre>import React from “react”;<br>import { useTranslation } from “next-i18next”;<br>const Translation = () =&gt; {<br>const { t } = useTranslation();<br>return (<br>&lt;div className=”container”&gt;<br>&lt;h1&gt;{t(“Hello”)}&lt;/h1&gt;<br>&lt;p&gt;{t(“Welcome to”)} Wesionary {t(“Team”)}&lt;/p&gt;<br>&lt;/div&gt;<br>);};<br>export default Translation;</pre><p>Now for the translation, you should make a <strong>locales </strong>folder inside the <strong>public </strong>and make two folders one for the default language(en) and the other for translating i.e, Japanese(ja). The first folder inside locales is <strong>en </strong>and inside this, we should create a .json file i.e, common.json, and same as the second folder ja. The common.json file contains the translation word which should be an exact word as a component file.</p><pre>// public/locales/ja/common.json</pre><pre>{<br>“Hello”: “こんにちは”,<br>“Welcome to”: “ようこそ”,<br>“Team”: “チーム”<br>}</pre><pre>#note: You have to start the server after adding the translations</pre><p><strong>Conclusion</strong></p><p>In this article, I have shown the basic step to translating and internationalizing a Next.js application using next-i18next. Additionally, we created a simple Next application and used internationalization techniques in it as well.</p><p>For sure there’s a lot we are not covering here and you might need to improve this solution to accomplish more ambitious tasks. But, for simple applications and websites, this basic approach can work just fine. I hope you can find this article useful.<br>You can also check out the demo <a href="https://github.com/kazi21220/i18next-practice"><strong>here</strong>.</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4fa3d4e6a2b0" width="1" height="1" alt=""><hr><p><a href="https://articles.wesionary.team/internationalize-the-next-js-application-using-next-i18next-4fa3d4e6a2b0">Internationalize the Next.js application using next-i18next</a> was originally published in <a href="https://articles.wesionary.team/">wesionaryTEAM</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>