0.2.2 • Published 4 days ago

next-i18next-ext v0.2.2

Weekly downloads
-
License
UNLICENSED
Repository
github
Last release
4 days ago

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;
0.2.1

4 days ago

0.2.2

4 days ago

0.2.0

10 months ago

0.1.0

2 years ago

0.1.1

2 years ago

0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago