import en_US from 'antd/locale/en_US';
import zh_CN from 'antd/locale/zh_CN';
// 国际化
const [antdLocale, setAntdLocale] = useState(zh_CN);
<ConfigProvider locale={antdLocale}>
...其他元素
</ConfigProvider>
import { TranslationOutlined } from '@ant-design/icons';
<FloatButton icon={<TranslationOutlined />} onClick={changeLocale} />
/** 国际化按钮切换语言的方法 */
const changeLocale = () => {
if (antdLocale === zh_CN) {
setAntdLocale(en_US);
} else {
setAntdLocale(zh_CN);
}
}
locale: {
default: 'zh-CN', // 默认的语言
antd: true, // antd是否也支持国际化
title: true, // 页面标题是否支持国际化
baseNavigator: true, // 开启浏览器语言检测
},
import { getLocale, setLocale } from 'umi';
console.log(getLocale())
/** 国际化按钮切换语言的方法 */
const changeLocale = () => {
if (antdLocale === zh_CN) {
setAntdLocale(en_US);
} else {
setAntdLocale(zh_CN);
}
if (getLocale() === 'zh-CN') {
setLocale('en-US', false);
} else {
setLocale('zh-CN', false);
}
}
/** 国际化按钮切换语言的方法 */
const changeLocale = () => {
if (antdLocale === zh_CN) {
setAntdLocale(en_US);
setLocale('en-US', false);
} else {
setAntdLocale(zh_CN);
setLocale('zh-CN', false);
}
};
const resetPasswordDrawer = {
'system_resetPasswordDrawer_drawerTitle': 'Reset Password',
'system_resetPasswordDrawer_account': 'Login Account',
'system_resetPasswordDrawer_accountPlaceholder': 'Please enter your login account',
'system_resetPasswordDrawer_originalPassword': 'Original Password',
'system_resetPasswordDrawer_originalPasswordPlaceholder': 'Please enter your original password',
'system_resetPasswordDrawer_newPassword': 'New Password',
'system_resetPasswordDrawer_newPasswordPlaceholder': 'Please enter your new password',
'system_resetPasswordDrawer_passwordAgain': 'Confirm Password',
'system_resetPasswordDrawer_passwordAgainPlaceholder': 'Please enter the new password again',
// 密码规则,三个输入框都可以共用
'system_resetPasswordDrawer_passwordPattern': 'The password should be no less than 8 digits, Must contain uppercase and lowercase letters, numbers, and special characters!',
}
export default Object.assign({}, resetPasswordDrawer);
const resetPasswordDrawer = {
'system_resetPasswordDrawer_drawerTitle': '重置密码',
'system_resetPasswordDrawer_account': '登录账号',
'system_resetPasswordDrawer_accountPlaceholder': '请输入登录账号',
'system_resetPasswordDrawer_originalPassword': '原始密码',
'system_resetPasswordDrawer_originalPasswordPlaceholder': '请输入原始密码',
'system_resetPasswordDrawer_newPassword': '新密码',
'system_resetPasswordDrawer_newPasswordPlaceholder': '请输入新密码',
'system_resetPasswordDrawer_passwordAgain': '确认密码',
'system_resetPasswordDrawer_passwordAgainPlaceholder': '请再次输入新密码',
// 密码规则,三个输入框都可以共用
'system_resetPasswordDrawer_passwordPattern': '密码不少于8位, 须包含大小写字母, 数字和特殊字符',
}
export default Object.assign({}, resetPasswordDrawer);
/**
* const 模块里的组件名 = {
* '模块名_组件名_子组件名': '对应翻译',
* .......
* }
* export default Object.assign({}, 模块里的组件名, 模块里的组件名, ...);
*/
import homepage from './en-US/homepage/homepage';
import system from './en-US/system/system';
export default {
...homepage,
...system,
}
import homepage from './zh-CN/homepage/homepage';
import system from './zh-CN/system/system';
export default {
...homepage,
...system,
}
import { useIntl } from 'umi';
const intl = useIntl();
<Form.Item
id="drawer-account"
name="account"
label={intl.formatMessage({ id: 'system_resetPasswordDrawer_account' })}
rules={[
{
required: true,
message: `${intl.formatMessage({
id: 'system_resetPasswordDrawer_accountPlaceholder',
})}!`,
},
]}
>
<Input
id="drawer-account-input"
placeholder={intl.formatMessage({
id: 'system_resetPasswordDrawer_accountPlaceholder',
})}
allowClear
autoComplete="off"
/>
</Form.Item>
/** 接口获取国际化的数据 */
const getI18nData = () => {
// 这里后期要改成接口的形式
const zhCN_data = {
login_loginCard_inputAccount: '请输入用户名',
login_loginCard_inputAccountValidate: '请输入用户名!',
login_loginCard_inputPassword: '请输入密码',
login_loginCard_inputPasswordValidate: '请输入密码!',
login_loginCard_inputCode: '验证码',
login_loginCard_inputCodeValidate: '请输入验证码!',
login_loginCard_loginButtonText: '登录',
};
const enUS_data = {
login_loginCard_inputAccount: 'Enter one user name',
login_loginCard_inputAccountValidate: 'Enter one user name!',
login_loginCard_inputPassword: 'Please enter the password',
login_loginCard_inputPasswordValidate: 'Please enter the password!',
login_loginCard_inputCode: 'Verification code',
login_loginCard_inputCodeValidate: 'Please enter the verification code!',
login_loginCard_loginButtonText: 'Log On',
};
localStorage.setItem('zh-CN', JSON.stringify(zhCN_data));
localStorage.setItem('en-US', JSON.stringify(enUS_data));
addLocale('zh-CN', zhCN_data);
addLocale('en-US', enUS_data);
localStorage.setItem('currentLang', 'zh-CN');
};
此页面不支持夜间模式!
已进入夜间模式!
已进入普通模式!
搜索框不允许为空
签到成功!经验+5!芋圆币+2!
签到失败!今日已签到!
需要登录社区账号才可以进入!