2.1.0 • Published 3 years ago

next-zero-intl v2.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

Next Zero Intl

Next Zero Intl is a next.js library built on top of google-translate-apis that you can just drop in your projects, and internationalize your app/website with zero config. Checkout this demo. 👇

Demo App

Installation

npm install next-zero-intl

or, if you're using yarn.

yarn add next-zero-intl

Configuration

First, you need to configure the <TranslationProvider/> in your _app.js file.

// pages/_app.js
import { TranslationProvider } from 'next-zero-intl'

export default function MyApp({ Component, pageProps }) {
  return (
    <TranslationProvider>
      <Component {...pageProps} />
    </TranslationProvider>
  )
}

Now create a translate.js file inside next.js API directory, and add the following code.

// pages/api/translate.js
import { handleTranslation } from 'next-zero-intl/api'

export default handleTranslation

and that's it, you've successfully configured next-zero-intl in your next.js app.

Usage

We provide you two simple hooks useTranslation & and useLocale to very simply add internationalization in your app. A simple example of how you'd use the translation hook is below.

import { useTranslation } from 'next-zero-intl'

const { t } = useTranslation()

function SomeComponent() {
  render(<p>{t('Hello')}</p>)
}

We try to be as less opinionated as possible, in order to change the text in above component, you can write a simple select component that uses useLocale hook.

import { useLocale } from 'next-zero-intl'
import { useState } from 'react'

export default function ChangeLocale() {
  const [locale, setLocale] = useLocale()
  const [selected, setSelected] = useState(locale)

  const onSelectHandler = e => {
    setSelected(e.target.value)
    setLocale(e.target.value)
  }

  return (
    <select onChange={onSelectHandler} value={selected}>
      <option value="en">English</option>
      <option value="hi">Hindi</option>
    </select>
  )
}

Check out the full list of all the locales here.

Contributing

Check the contributing guidlines here.

License

Next Zero Intl is MIT licensed

2.0.3

3 years ago

2.0.2

3 years ago

2.0.5

3 years ago

2.0.4

3 years ago

2.1.0

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.2.4

4 years ago

1.2.3

4 years ago

1.2.2

4 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.0.36

4 years ago

1.0.35

4 years ago

1.0.34

4 years ago

1.0.32

4 years ago

1.0.31

4 years ago

1.0.30

4 years ago

1.0.28

4 years ago

1.0.27

4 years ago

1.0.26

4 years ago

1.0.25

4 years ago

1.0.22

4 years ago

1.0.21

4 years ago

1.0.20

4 years ago

1.0.19

4 years ago