Skip to content
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

feat: multi-language support for umi-plugin-react > title #1482

Merged
merged 3 commits into from
Nov 21, 2018
Merged

feat: multi-language support for umi-plugin-react > title #1482

merged 3 commits into from
Nov 21, 2018

Conversation

leftstick
Copy link
Contributor

@leftstick leftstick commented Nov 20, 2018

Close #1487

umi-plugin-reacttitle配置,增加多语言支持,效果如下:

demo

.umirc.js中增加如下配置:

locale: {
  default: 'zh-CN',
  baseNavigator: true,
  antd: true
},
title: {
  defaultTitle: 'test-umi',
  useLocale: true  // 新增属性,开启多语言支持
},

然后,用户为路由自定义的title属性就会作为keylocales/*.js里去找对应文字来作为标题了。

现在有一个小限制,就是开发环境中,由于TitleWrapper.js被缓存在了umi/_renderRoutes里的RouteInstanceMap里,导致.umirc.js发生变更时,对TitleWrapper.js的变更无法自动生效。。。

{{/useLocale}}
}
componentWillUnmount() {
document.title = this.props.route._title_default;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

之前的 if (document.title === this.props.route._title) { 这个判断还是要的,不然可能会出现一个 bug。

#1329

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我也想了这步可能有原因,只是document.title已经被改了,无法和this.props.route._title做匹配,那我可能要再加一步了

@smithyj
Copy link
Contributor

smithyj commented Nov 20, 2018

不支持配置式路由title吗?

@leftstick
Copy link
Contributor Author

leftstick commented Nov 20, 2018

@smithyj 支持的,title不管是从约定路由组件的注释里、还是配置路由的配置里来,都会走到这里,被替换成locales/*.js的对应文字。我的示例只是演示了约定路由的场景,但配置路由也是一样的

@smithyj
Copy link
Contributor

smithyj commented Nov 20, 2018

@leftstick 好像并没有生效

@smithyj
Copy link
Contributor

smithyj commented Nov 20, 2018

好像是应该还没发布

@smithyj
Copy link
Contributor

smithyj commented Nov 20, 2018

@sorrycc @leftstick 麻烦推送下 umi-plugin-react 最新包

@sorrycc
Copy link
Member

sorrycc commented Nov 21, 2018

哪个 pr 加的?本地测应该不需要发包吧。

@yutingzhao1991
Copy link
Contributor

close #1487

@smithyj
Copy link
Contributor

smithyj commented Nov 21, 2018

@yutingzhao1991 合并没有成功

@sorrycc sorrycc merged commit a187365 into umijs:master Nov 21, 2018
@ghost
Copy link

ghost commented Jun 17, 2022

需要重新加载才生效,不支持动态切换吗?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

title 是否考虑国际化支持?
4 participants