Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
5c9c7b87
Commit
5c9c7b87
authored
Sep 27, 2018
by
Arek Mytych
Committed by
Tim Neutkens
Sep 27, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add language switch to with-react-i18next example (#5306)
parent
397daece
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
8 deletions
+32
-8
LanguageSwitch.js
examples/with-react-i18next/components/LanguageSwitch.js
+22
-0
package.json
examples/with-react-i18next/package.json
+8
-8
_app.js
examples/with-react-i18next/pages/_app.js
+2
-0
No files found.
examples/with-react-i18next/components/LanguageSwitch.js
0 → 100644
View file @
5c9c7b87
import
React
from
'react'
import
Link
from
'next/link'
import
{
withRouter
}
from
'next/router'
import
i18n
from
'../i18n'
const
LanguageSwitch
=
({
router
})
=>
(
<
ul
>
<
li
>
<
Link
href
=
{
`
${
router
.
pathname
}
`
}
>
<
a
onClick
=
{()
=>
i18n
.
changeLanguage
(
'en'
)}
>
en
<
/a
>
<
/Link
>
<
/li
>
<
li
>
<
Link
href
=
{
`
${
router
.
pathname
}
?lng=de`
}
>
<
a
onClick
=
{()
=>
i18n
.
changeLanguage
(
'de'
)}
>
de
<
/a
>
<
/Link
>
<
/li
>
<
/ul
>
)
export
default
withRouter
(
LanguageSwitch
)
examples/with-react-i18next/package.json
View file @
5c9c7b87
...
...
@@ -12,14 +12,14 @@
"license"
:
"MIT"
,
"dependencies"
:
{
"express"
:
"4.16.3"
,
"i18next"
:
"11.
3.6
"
,
"i18next-browser-languagedetector"
:
"2.2.
0
"
,
"i18next-express-middleware"
:
"1.
2
.0"
,
"i18next-node-fs-backend"
:
"
1.2.1
"
,
"i18next"
:
"11.
9.0
"
,
"i18next-browser-languagedetector"
:
"2.2.
3
"
,
"i18next-express-middleware"
:
"1.
4
.0"
,
"i18next-node-fs-backend"
:
"
2.1.0
"
,
"i18next-xhr-backend"
:
"1.5.1"
,
"next"
:
"
^6.1.1
"
,
"react"
:
"^16.
4.1
"
,
"react-dom"
:
"^16.
4.1
"
,
"react-i18next"
:
"7.
8.1
"
"next"
:
"
latest
"
,
"react"
:
"^16.
5.2
"
,
"react-dom"
:
"^16.
5.2
"
,
"react-i18next"
:
"7.
13.0
"
}
}
examples/with-react-i18next/pages/_app.js
View file @
5c9c7b87
...
...
@@ -2,6 +2,7 @@ import React from 'react'
import
App
,
{
Container
}
from
'next/app'
import
{
I18n
as
I18nR
,
I18nextProvider
}
from
'react-i18next'
import
initialI18nInstance
from
'../i18n'
import
LanguageSwitch
from
'../components/LanguageSwitch'
export
default
class
MyApp
extends
App
{
render
()
{
...
...
@@ -19,6 +20,7 @@ export default class MyApp extends App {
<
I18nR
ns
=
'common'
wait
>
{
t
=>
<
h1
>
{
t
(
'common:integrates_react-i18next'
)}
<
/h1>
}
<
/I18nR
>
<
LanguageSwitch
/>
<
Component
{...
pageProps
}
/
>
<
/React.Fragment
>
<
/I18nextProvider
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment