EasyUI Forum

General Category => EasyUI for React => Topic started by: yulei on January 25, 2019, 05:46:28 AM



Title: how to use i18n in easyui for react
Post by: yulei on January 25, 2019, 05:46:28 AM
in jquery version ,there is "easyui-lang-zh_CN.js", how can i do i18n  in react version ?


Title: Re: how to use i18n in easyui for react
Post by: jarry on January 25, 2019, 07:49:41 PM
Please refer to this documentation https://www.jeasyui.com/documentation5/LocaleProvider.php


Title: Re: how to use i18n in easyui for react
Post by: chrwei on July 31, 2019, 02:23:16 PM
Is there a way to bind that to i18next's language so it changes automatically when i18n.changeLanguage() is called?


Title: Re: how to use i18n in easyui for react
Post by: chrwei on September 11, 2019, 06:44:06 AM
got it.

Code:
import React, { Component } from 'react';
import { withTranslation } from 'react-i18next';
import i18n from 'i18next';

import { LocaleProvider } from 'rc-easyui';
import easyuien from 'rc-easyui/dist/locale/easyui-lang-en';
import easyuies from 'rc-easyui/dist/locale/easyui-lang-es';

const easyuilangs = {
en: easyuien,
es: easyuies
}

class App extends Component {
constructor(props) {
super(props);
this.state = {
easyuilocale: easyuien
};
}

componentDidMount() {
const self = this;
self.setLang(self, i18n.language);
i18n.on('languageChanged', function (lng) {
self.setLang(self, lng);
});
}

setLang(self, lng) {
self.setState({
easyuilocale: easyuilangs[lng.split("-")[0]]
});
}

render() {
const { easyuilocale } = this.state;

return (
<LocaleProvider local={easyuilocale}>
your content here
</LocaleProvider>
);
}
}

export default withTranslation()(App);


Title: Re: how to use i18n in easyui for react
Post by: chrwei on October 14, 2019, 11:46:49 AM
this doesn't seem to be working.  in fact, if I edit rc-easyui/dist/locale/easyui-lang-en.js, my changes do not have any effect at all, no matter what language I choose.  how can I diagnose this one?