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

umi/locale的setLocale()传参数的问题 #4520

Closed
minsion opened this issue Apr 23, 2020 · 2 comments
Closed

umi/locale的setLocale()传参数的问题 #4520

minsion opened this issue Apr 23, 2020 · 2 comments

Comments

@minsion
Copy link

minsion commented Apr 23, 2020

问题:umi/locale的setLocale(lang),只支持zh-CN这中形式,能不能支持zh-cn。只能本地手动做映射?有没有好的方案兼容性lang这个参数不一定是/^([a-z]{2})-([A-Z]{2})$/.test(lang),有可能是/^([a-z]{2})-([a-z]{2})$/.test(lang)。

原因:setLocale的方法里面有这个校验
if (lang !== undefined && !/^([a-z]{2})-([A-Z]{2})$/.test(lang)) {
// for reset when lang === undefined
throw new Error('setLocale lang format error');
}

复现:钉钉浏览器的汉语是:zh-Hans-CN,当用户在钉钉浏览器切换中文时需setLocale("zh-Hans-CN"),那么就会抛错误 throw new Error('setLocale lang format error');

@leftstick
Copy link
Contributor

好问题啊。根据intl的介绍Intl/locale,钉钉浏览器里给出的值是合法的。

那就应该是 umi 里的处理方式还不够完整了

@xiaohuoni
Copy link
Member

xiaohuoni commented May 13, 2020

后续跟近 umijs/plugins#173

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

No branches or pull requests

3 participants