mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
improve example fallback translation and add new sample locale for lang id (#1983)
This commit is contained in:
parent
1703ad302c
commit
443dceaeec
|
@ -1,2 +1,2 @@
|
||||||
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>))
|
||||||
|
|
|
@ -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 {
|
||||||
constructor (props) {
|
constructor (props) {
|
||||||
super(props)
|
super(props)
|
||||||
|
|
||||||
this.i18n = startI18n(props.translations)
|
this.i18n = startI18n(props.translations, lang)
|
||||||
}
|
}
|
||||||
|
|
||||||
render (props) {
|
render (props) {
|
||||||
|
|
3
examples/with-i18next/static/locales/id/common.json
Normal file
3
examples/with-i18next/static/locales/id/common.json
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"hello": "halo"
|
||||||
|
}
|
|
@ -1,3 +1,4 @@
|
||||||
{
|
{
|
||||||
"hello": "e ae tche"
|
"hello": "e ae tche",
|
||||||
|
"morning": "manha"
|
||||||
}
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
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'],
|
||||||
|
|
Loading…
Reference in a new issue