umijs / umi

A framework in react community ✨
https://umijs.org
MIT License
15.28k stars 2.65k forks source link

umi的plugin-locate,无法使用SelectLang将 moment的语言切换到英文(en_US) #10981

Open MicroOps-cn opened 1 year ago

MicroOps-cn commented 1 year ago

What happens?

umi的plugin-locate,无法使用SelectLang/setLocate将 moment的语言切换到英文(en_US)

umi的plugin-locate在生成语言文件(src/.umi/plugin-locale/localeExports.ts)的时候,生成的en_US的momentLocate的值为空,会导致moment的全局语言切换失败。

https://github.com/umijs/umi/blob/master/packages/plugins/src/utils/localeUtils.ts#L19-L50

image image

Mini Showcase Repository(REQUIRED)

Context

相关代码: https://github.com/umijs/umi/blob/ac1ea67379aae4844655e3b8dca52502407a695a/packages/plugins/src/utils/localeUtils.ts#L19-L50

fz6m commented 1 year ago

umi 3 不维护了,建议升级到 umi 4

MicroOps-cn commented 1 year ago

umi 3 不维护了,建议升级到 umi 4

看起来umi4的getMomentLocale函数和umi3的是一样的,umi4应该也存在同样的问题

MicroOps-cn commented 1 year ago

我在global.tsx中增加了这样的代码,将en-US的momentLocale覆盖掉,就临时解决了该问题,

if (!localeInfo['en-US']?.momentLocale) {
  addLocale(
    'en-US',
    {},
    {
      momentLocale: 'en-US',
      antd: { ...(localeInfo['en-US']?.antd ?? {}) },
    },
  );
}
xXAvoraXx commented 1 year ago

我在global.tsx中增加了这样的代码,将en-US的momentLocale覆盖掉,就临时解决了该问题,

if (!localeInfo['en-US']?.momentLocale) {
  addLocale(
    'en-US',
    {},
    {
      momentLocale: 'en-US',
      antd: { ...(localeInfo['en-US']?.antd ?? {}) },
    },
  );
}
#13 74.84 Error: /app/src/pages/Welcome/components/ExamsProList/index.tsx:
#13 74.84 > 1 | import { localeInfo } from '@/.umi/plugin-locale/localeExports';
#13 74.84     | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @/.umi/plugin-locale/localeExports includes /.umi/, /.umi-test/ or /.umi-production/. It's not allowed to import. Please import from @umijs/max or the corresponding plugin.
#13 74.84   2 | import { getStudentExamsRequest, setParticipateToExamRequest } from '@/services/prep/preparation';
#13 74.84   3 | import { ProList } from '@ant-design/pro-components';
#13 74.84   4 | import {
LOMO19 commented 1 month ago

getMomentLocale

我也遇到了同样的问题,无法从对应的 plugin 获取 localeInfo

企业微信截图_8eb1c251-c7ea-4cbb-98ae-069ec03a5bdf