1.1.9 • Published 2 years ago

@west.kh/i18n-next v1.1.9

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

i18n-next.

Easy way to translate your nextjs app

How to use

1) Add module to project.

npm i --save @west.kh/i18n-next

2) Wrap yor component with Translation

Example:
function MyApp(props) {
    const {Component, pageProps, router: {locale}} = props;

    return (
        <Translation messages={pageProps.messages} locale={locale}>
            <Component {...pageProps} />
        </Translation>
    )
}

3) Add hook to your component

Import:

import {useTranslation} from "@west.kh/i18n-next";

Init hook

const {t} = useTranslation('foo');

Wrap sentence

<span>{t('bar')}</span>

4) Add config translationConfig.json to project root

Config content
{
    "lang": ["uk"],
    "extensions": ["js"]
}

5) generate i18n files (path to files: src/messages/[lang]/*)

node node_modules/@west.kh/i18n-next/generateTranslation.js

6) Add i18n files to nextProps inside page

import {getMessages} from "@west.kh/i18n-next";    

export async function getStaticProps({locale}) {
    return {
        props: {
            messages: await getMessages(['foo'], locale)
        }
    }
}
1.1.9

2 years ago

1.1.8

2 years ago

1.1.7

2 years ago

1.1.6

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.0

2 years ago