-
-
Notifications
You must be signed in to change notification settings - Fork 8.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🐛 [BUG]antd-pro 国际化切换语言关闭页面刷新,tabs的语言不切换 #10822
Comments
解决方案问题的根源是使用了 要解决这个问题,有以下几个步骤:
<SelectLang reload={true} />
import React from 'react';
import { useIntl } from 'umi';
const TabComponent = () => {
const { formatMessage } = useIntl();
const currentLocale = localStorage.getItem('umi_locale'); // 获取当前语言
return (
<div>
<h2>{formatMessage({ id: 'tab.title', defaultMessage: 'Tab Title' })}</h2>
{/* other content */}
</div>
);
};
export default TabComponent; 在上面的代码中,使用
export default {
// other translations
'tab.title': '标签标题',
}; 在 export default {
// other translations
'tab.title': 'Tab Title',
}; 通过这样的方式,在切换语言时, 参考文档 |
是需要用6.0.0.1那个分支的代码吗,我跑起来报错 |
这个问题是由于在切换语言时,某些组件的语言没有实时切换导致的。Antd Pro中使用了context来管理语言的切换,但是某些组件可能没有优化得很好,context的修改不会重新渲染这些组件,或者这些组件上下文不存在。 为了解决这个问题,可以通过配置的方式来实现完全重新渲染页面。具体做法是在切换语言的时候,使用umi-plugin-react/locale提供的setLocale方法,并将第二个参数设置为true来强制刷新页面。例如: import { setLocale } from 'umi-plugin-react/locale';
// 设置第二个参数为 true 即可强制刷新
setLocale(key, true); 这样,在切换语言后,页面将会重新加载,从而实现完全重新渲染的效果,确保所有组件的语言都能正确切换。 如果不想这样做可以给相应的组件设置一个 key,强制这些组件刷新 |
🐛 bug 描述
打开了umi max的多tabs和keepalive,并且在切换语言时使页面不刷新。这种情况下,切换语言,tab的title的语言没有更新
📷 复现步骤 | Recurrence steps
使用demo-tabs分支的代码,在src/RightContent/index.tsx文件中的SelectLang添加reload={false},打开多个tab标签后切换语言
🏞 期望结果 | Expected results
tabs标签的title也变成切换后的语言
💻 复现代码 | Recurrence code
© 版本信息
🚑 其他信息
The text was updated successfully, but these errors were encountered: