1
0
Fork 0
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:
Ardani Rohman 2017-05-18 00:41:54 +07:00 committed by Tim Neutkens
parent 1703ad302c
commit 443dceaeec
5 changed files with 13 additions and 5 deletions

View file

@ -1,2 +1,2 @@
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>))

View file

@ -4,9 +4,12 @@ import startI18n from '../tools/startI18n'
import { getTranslation } from '../tools/translationHelpers'
import Title from '../components/Title'
// get language from query parameter or url path
const lang = 'id'
export default class Homepage extends Component {
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 }
}
@ -14,7 +17,7 @@ export default class Homepage extends Component {
constructor (props) {
super(props)
this.i18n = startI18n(props.translations)
this.i18n = startI18n(props.translations, lang)
}
render (props) {

View file

@ -0,0 +1,3 @@
{
"hello": "halo"
}

View file

@ -1,3 +1,4 @@
{
"hello": "e ae tche"
"hello": "e ae tche",
"morning": "manha"
}

View file

@ -1,6 +1,7 @@
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',
resources: file,
ns: ['common'],