63
loading...
This website collects cookies to deliver better user experience
npx create-next-app intl --ts
yarn dev
ready - started server on 0.0.0.0:3000, url: http://localhost:3000
yarn add next-i18next
import { useTranslation } from 'next-i18next'
const { t } = useTranslation('common')
import { serverSideTranslations } from 'next-i18next/serverSideTranslations'
export const getStaticProps = async ({ locale }) => ({
props: {
...(await serverSideTranslations(locale, ['common'])),
},
})
import '../styles/globals.css'
import type { AppProps } from 'next/app'
import { appWithTranslation } from 'next-i18next'
function MyApp({ Component, pageProps }: AppProps) {
return <Component {...pageProps} />
}
export default appWithTranslation(MyApp)
module.exports = {
i18n: {
defaultLocale: 'en',
locales: ['en', 'hn'],
},
}
next.config.js
file. If it's not created already, create it.const { i18n } = require('./next-i18next.config')
/** @type {import('next').NextConfig} */
module.exports = {
reactStrictMode: true,
i18n
}
<h1 className={styles.title}>
Welcome to <a href='https://nextjs.org'>Next.js!</a>
</h1>
<h1 className={styles.title}>{t('header')}</h1>
public/locales/en/common.json
{
"header": "Welcome to Next.js!",
}
public/locales/hn/common.json
{
"header": "Next.js में आपका स्वागत है!"
}