Socket
Socket
Sign inDemoInstall

next-i18next-ext

Package Overview
Dependencies
1
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    next-i18next-ext

Next integration with i18next


Version published
Maintainers
1
Created

Readme

Source

next-i18next-ext

npm

Extended next-i18next which allows you to use translations shared between pages and load them once. SSG and SSR work great too.

Installation

npm i next-i18next-ext

Usage

  1. Configure your custom Document to provide shared translations for the App
import { createGetInitialProps } from 'next-i18next-ext/server';

export default class _Document extends Document {
  static getInitialProps = createGetInitialProps(['common']);

  render() {
    ...
  }
}

Steps above are the same as for next-i18next

  1. Configure your custom App
import { appWithTranslation } from 'next-i18next-ext';

const _App = ({ Component, pageProps }) => {
  return <Component {...pageProps} />;
};

export default appWithTranslation(_App);
  1. You also able to use page-level translations
import { serverSideTranslations } from 'next-i18next-ext/server';

export const getStaticProps = async ({ locale }) => {
  return {
    props: {
      ...(await serverSideTranslations(locale, ['main-page'])),
    },
  };
};
  1. Use translation
import { useTranslation } from 'react-i18next';

export const Footer = () => {
  const { t } = useTranslation('common');
  return (
    <footer>
      {t('description')}
    </footer>
  );
};

API

createGetInitialProps
const createGetInitialProps: (namespacesRequired?: string[], configOverride?: UserConfig | null, extraLocales?: string[] | false) => (ctx: DocumentContext, locale?: string) => DocumentInitialProps;
serverSideProps
const serverSideTranslations: (initialLocale: string, namespacesRequired?: string[] | undefined, configOverride?: UserConfig | null, extraLocales?: string[] | false) => Promise<SSRConfig>;
appWithTranslation
const appWithTranslation: (App: any, configOverride?: UserConfig | null) => (appProps: any) => JSX.Element;

Keywords

FAQs

Last updated on 27 Apr 2024

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc