Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docs about how to change the lang #47

Merged
merged 1 commit into from
Feb 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 37 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
- [7. Plurals](#7-plurals)
- [8. Use HTML inside the translation](#8-use-html-inside-the-translation)
- [9. Nested translations](#9-nested-translations)
- [10. Demos](#10-demos)
- [10. How to change the language](#10-how-to-change-the-language)
- [11. Demos](#11-demos)
- [Static site example](#static-site-example)
- [With server example](#with-server-example)

Expand Down Expand Up @@ -550,7 +551,41 @@ In order to use it, you should use "." as id separator:
t`namespace:nested-example.very-nested.nested`
```

## 10. Demos
## 10. How to change the language

In order to change the current language you don't need anything of this library, you can do it directly with the next navigation:

- https://nextjs.org/learn/basics/navigate-between-pages

The only thing to remember, is to navigate with the **/lang/** on front.

One example of a possible `ChangeLanguage` component:

```js
import React from 'react'
import useTranslation from 'next-translate/useTranslation'
import i18nConfig from '../i18n.json'

const { allLanguages } = i18nConfig

function ChangeLanguage() {
const { t, lang } = useTranslation()

return allLanguages.map(lng => {
if (lng === lang) return null

// Or you can attach the current pathame at the end
// to keep the same page
return (
<Link href={`/${lang}`} key={lng}>
{t(`layout:language-name-${lng}`)}
</Link>
)
})
}
```

## 11. Demos

### Static site example

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "next-translate",
"version": "0.6.0",
"version": "0.7.0",
"description": "Next.js utility to translate pages without the need of a server (static i18n pages generator).",
"license": "MIT",
"keywords": [
Expand Down