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
443dceae
Commit
443dceae
authored
May 17, 2017
by
Ardani Rohman
Committed by
Tim Neutkens
May 17, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improve example fallback translation and add new sample locale for lang id (#1983)
parent
1703ad30
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
13 additions
and
5 deletions
+13
-5
Title.js
examples/with-i18next/components/Title.js
+1
-1
index.js
examples/with-i18next/pages/index.js
+5
-2
common.json
examples/with-i18next/static/locales/id/common.json
+3
-0
common.json
examples/with-i18next/static/locales/pt/common.json
+2
-1
startI18n.js
examples/with-i18next/tools/startI18n.js
+2
-1
No files found.
examples/with-i18next/components/Title.js
View file @
443dceae
import
{
translate
}
from
'react-i18next'
import
{
translate
}
from
'react-i18next'
export
default
translate
([
'common'
])((
props
)
=>
(
<
h1
>
{
props
.
t
(
'hello'
)}
<
/h1>
)
)
export
default
translate
([
'common'
])((
props
)
=>
(
<
h1
>
{
props
.
t
(
'hello'
)}
,
{
props
.
t
(
'morning'
)}
<
/h1>
)
)
examples/with-i18next/pages/index.js
View file @
443dceae
...
@@ -4,9 +4,12 @@ import startI18n from '../tools/startI18n'
...
@@ -4,9 +4,12 @@ import startI18n from '../tools/startI18n'
import
{
getTranslation
}
from
'../tools/translationHelpers'
import
{
getTranslation
}
from
'../tools/translationHelpers'
import
Title
from
'../components/Title'
import
Title
from
'../components/Title'
// get language from query parameter or url path
const
lang
=
'id'
export
default
class
Homepage
extends
Component
{
export
default
class
Homepage
extends
Component
{
static
async
getInitialProps
()
{
static
async
getInitialProps
()
{
const
translations
=
await
getTranslation
(
'pt'
,
'common'
,
'http://localhost:3000/static/locales/'
)
const
translations
=
await
getTranslation
(
lang
,
'common'
,
'http://localhost:3000/static/locales/'
)
return
{
translations
}
return
{
translations
}
}
}
...
@@ -14,7 +17,7 @@ export default class Homepage extends Component {
...
@@ -14,7 +17,7 @@ export default class Homepage extends Component {
constructor
(
props
)
{
constructor
(
props
)
{
super
(
props
)
super
(
props
)
this
.
i18n
=
startI18n
(
props
.
translations
)
this
.
i18n
=
startI18n
(
props
.
translations
,
lang
)
}
}
render
(
props
)
{
render
(
props
)
{
...
...
examples/with-i18next/static/locales/id/common.json
0 → 100644
View file @
443dceae
{
"hello"
:
"halo"
}
\ No newline at end of file
examples/with-i18next/static/locales/pt/common.json
View file @
443dceae
{
{
"hello"
:
"e ae tche"
"hello"
:
"e ae tche"
,
"morning"
:
"manha"
}
}
\ No newline at end of file
examples/with-i18next/tools/startI18n.js
View file @
443dceae
import
i18n
from
'i18next'
import
i18n
from
'i18next'
const
startI18n
=
file
=>
i18n
.
init
({
const
startI18n
=
(
file
,
lang
)
=>
i18n
.
init
({
lng
:
lang
,
// active language http://i18next.com/translate/
fallbackLng
:
'pt'
,
fallbackLng
:
'pt'
,
resources
:
file
,
resources
:
file
,
ns
:
[
'common'
],
ns
:
[
'common'
],
...
...
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