EasyUI Forum
March 28, 2024, 08:36:42 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: how to use i18n in easyui for react  (Read 8263 times)
yulei
Newbie
*
Posts: 9


View Profile Email
« 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 ?
Logged
jarry
Administrator
Hero Member
*****
Posts: 2260


View Profile Email
« Reply #1 on: January 25, 2019, 07:49:41 PM »

Please refer to this documentation https://www.jeasyui.com/documentation5/LocaleProvider.php
Logged
chrwei
Full Member
***
Posts: 219


View Profile Email
« Reply #2 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?
Logged
chrwei
Full Member
***
Posts: 219


View Profile Email
« Reply #3 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);
Logged
chrwei
Full Member
***
Posts: 219


View Profile Email
« Reply #4 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?
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!