提交 443dceae 编写于 作者: A Ardani Rohman 提交者: Tim Neutkens

improve example fallback translation and add new sample locale for lang id (#1983)

上级 1703ad30
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 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) {
......
{
"hello": "halo"
}
\ No newline at end of file
{
"hello": "e ae tche"
"hello": "e ae tche",
"morning": "manha"
}
\ No newline at end of file
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'],
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册