Socket
Socket
Sign inDemoInstall

next-i18next

Package Overview
Dependencies
Maintainers
3
Versions
202
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

next-i18next

The easiest way to translate your NextJs apps.


Version published
Weekly downloads
380K
decreased by-9.44%
Maintainers
3
Weekly downloads
 
Created

What is next-i18next?

The next-i18next package is a powerful internationalization framework for Next.js applications. It simplifies the process of adding multilingual support to your Next.js projects by integrating with the i18next library. It provides server-side rendering, automatic language detection, and easy translation management.

What are next-i18next's main functionalities?

Basic Setup

This code demonstrates the basic setup of next-i18next. It initializes the next-i18next instance with a default language and other supported languages.

const NextI18Next = require('next-i18next').default;
const nextI18Next = new NextI18Next({
  defaultLanguage: 'en',
  otherLanguages: ['de', 'fr'],
});
module.exports = nextI18Next;

Translation in Components

This code shows how to use translations in a React component. The `withTranslation` higher-order component is used to inject the `t` function, which is then used to fetch the translated text.

import { withTranslation } from 'next-i18next';

const MyComponent = ({ t }) => (
  <div>
    <h1>{t('welcome_message')}</h1>
  </div>
);

export default withTranslation('common')(MyComponent);

Server-Side Rendering

This code demonstrates how to use next-i18next with Next.js's server-side rendering. The `serverSideTranslations` function is used to load the necessary translations for the requested locale.

import { serverSideTranslations } from 'next-i18next/serverSideTranslations';

export const getStaticProps = async ({ locale }) => ({
  props: {
    ...(await serverSideTranslations(locale, ['common'])),
  },
});

Other packages similar to next-i18next

Keywords

FAQs

Package last updated on 01 Mar 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc