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

如何处理服务端渲染情况下A用户设置语言会影响B用户的情况 #108

Open
hardfist opened this issue Jan 29, 2019 · 1 comment

Comments

@hardfist
Copy link
Contributor

如果intl.init 和intl.get不是放在一个调用栈里执行,即A用户的intl.init和intl.get之间插入了B用户的intl.init操作,会造成A用户的intl.get获取的是B用户设置的语言,如何处理这种情况

@hardfist hardfist changed the title 如何处理服务端情况下A用户设置语言会影响B用户的情况 如何处理服务端渲染情况下A用户设置语言会影响B用户的情况 Jan 29, 2019
@callmeYe
Copy link
Contributor

创建多个实例,类似于
const map: Record<string, typeof intl> = {}
export const getIntl = (componentName: string): typeof intl => {
// 有些组件没调getIntl,会出现自身的国际化文案无用的问题,需要新建个国际化对象
if (map[componentName] && componentName !== '
') return map[componentName];
if (componentName === '
') return new (_intl as any).ReactIntlUniversal();
map[componentName] = new (_intl as any).ReactIntlUniversal();
return map[componentName];
}

const defaultIntl = getIntl('_');

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

No branches or pull requests

2 participants