Umi: [国际化] 控制台提示 Warning: The current popular language does not exist, please check the locales folder! 警告信息

Created on 2 Apr 2020  ·  21Comments  ·  Source: umijs/umi

What happens?

访问任何路由页面,控制台都出现如下警告信息:

Warning: The current popular language does not exist, please check the locales folder!

我在 app.ts 里做了如下日志输出:

export async function getInitialState() {
  console.log('getInitialState ...');
}

export function onRouteChange({ location, routes, action }: any) {
  console.log('onRouteChange ...', location, routes, action);
}

export function patchRoutes({ routes }: any) {
  console.log('patchRoutes ...', routes);
}

export function render(oldRender: any) {
  console.log('render ...');
  oldRender();
}

错误提示的顺序保持如下:
image

最小可复现仓库

暂无

复现步骤,错误日志以及相关配置

错误日志

相关环境信息

  • Umi 版本
"dependencies": {
    "@ant-design/icons": "^4.0.5",
    "@ant-design/pro-layout": "^5.0.8",
    "@ant-design/pro-table": "^2.1.11",
    "@antv/data-set": "^0.11.1",
    "@antv/l7": "^2.1.9",
    "@antv/l7-maps": "^2.1.9",
    "@types/js-cookie": "^2.2.5",
    "@types/lodash.debounce": "^4.0.6",
    "@types/lodash.isequal": "^4.5.5",
    "@types/numeral": "0.0.26",
    "@types/qrcode.react": "^1.0.0",
    "@types/react-router": "^5.1.5",
    "@typescript-eslint/parser": "^2.26.0",
    "@umijs/hooks": "^1.8.1",
    "antd": "^4.1.0",
    "bizcharts": "^3.5.8",
    "bizcharts-plugin-slider": "^2.1.1-beta.1",
    "classnames": "^2.2.6",
    "dayjs": "^1.8.23",
    "gg-editor": "^2.0.2",
    "js-cookie": "^2.2.1",
    "lodash": "^4.17.11",
    "lodash-decorators": "^6.0.0",
    "lodash.debounce": "^4.0.8",
    "lodash.isequal": "^4.5.0",
    "moment": "^2.24.0",
    "numeral": "^2.0.6",
    "nzh": "^1.0.3",
    "omit.js": "^1.0.2",
    "path-to-regexp": "2.4.0",
    "prop-types": "^15.5.10",
    "qrcode.react": "^1.0.0",
    "qs": "^6.9.3",
    "rc-field-form": "^1.1.0",
    "react": "^16.13.1",
    "react-copy-to-clipboard": "^5.0.1",
    "react-dom": "^16.13.1",
    "react-fittext": "^1.0.0",
    "react-helmet": "^5.2.1",
    "react-helmet-async": "^1.0.4",
    "react-router": "^4.3.1",
    "redux": "^4.0.1",
    "ts-md5": "^1.2.7",
    "umi": "^3.0.16",
    "umi-request": "^1.0.8",
    "use-merge-value": "^1.0.1",
    "webpack-chain": "^6.4.0"
  },
  "devDependencies": {
    "@ant-design/pro-cli": "^1.0.20",
    "@types/classnames": "^2.2.10",
    "@types/express": "^4.17.4",
    "@types/history": "^4.7.2",
    "@types/jest": "^25.1.4",
    "@types/lodash": "^4.14.144",
    "@types/qs": "^6.5.3",
    "@types/react": "^16.9.31",
    "@types/react-dom": "^16.9.6",
    "@types/react-helmet": "^5.0.13",
    "@umijs/fabric": "^2.0.7",
    "@umijs/plugin-block-devtool": "^1.2.1",
    "@umijs/preset-react": "^1.4.8",
    "@umijs/preset-ui": "^2.1.7",
    "chalk": "^3.0.0",
    "cross-env": "^7.0.0",
    "cross-port-killer": "^1.1.1",
    "enzyme": "^3.11.0",
    "eslint": "^6.8.0",
    "eslint-plugin-react-hooks": "^2.5.1",
    "express": "^4.17.1",
    "gh-pages": "^2.0.1",
    "husky": "^4.0.7",
    "jest-puppeteer": "^4.2.0",
    "jsdom-global": "^3.0.2",
    "lint-staged": "^10.1.1",
    "mockjs": "^1.0.1-beta3",
    "node-fetch": "^2.6.0",
    "prettier": "^2.0.2",
    "pro-download": "1.0.1",
    "redbox-react": "^1.6.0",
    "stylelint": "^13.0.0",
    "umi-plugin-antd-icon-config": "^2.0.0"
  },
  "optionalDependencies": {
    "puppeteer": "^2.0.0"
  },
  • Node 版本
    v13.12.0

  • 操作系统
    macOS 10.15.4 (19E266)

Need Reproduce

Most helpful comment

我这边将locales里面的属性baseNavigator设置为false解决了

locale: {
    default: 'ja-JP',
    antd: true,
    baseNavigator: false,
    title: false
  },

All 21 comments

删掉config文件中的locale配置即可

@loocor 配置写啥?能给个demo嘛?

具体看git issue发送的,复制粘贴到自己tsconfig文件,保存后重启项目

------------------ 原始邮件 ------------------
发件人: "陈小聪"<[email protected]>;
发送时间: 2020年4月8日(星期三) 中午12:09
收件人: "umijs/umi"<[email protected]>;
抄送: "思语随云"<[email protected]>; "Comment"<[email protected]>;
主题: Re: [umijs/umi] [国际化] 控制台提示 Warning: The current popular language does not exist, please check the locales folder! 警告信息 (#4363)

@loocor 配置写啥?能给个demo嘛?


You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.

如果只想 开启 antd, 不想使用其他语言怎么办?locale: { antd: true, },

不使用国际化的情况下,很多地方文案会是英文,比如Modal.confirm的两个按钮,pro-table里面的分页,但是直接使用Modal作为dom的时候按钮又是中文-_-

@loocor 配置写啥?能给个demo嘛?

package.json

{
  "name": "ant-design-pro",
  "version": "1.0.0",
  "private": true,
  "description": "A Progressive Real Estate Information Management System",
  "scripts": {
    "analyze": "cross-env ANALYZE=1 umi build",
    "build": "umi build",
    "deploy": "npm run site && npm run gh-pages",
    "docker-hub:build": "docker build  -f Dockerfile.hub -t  ant-design-pro ./",
    "docker-prod:build": "docker-compose -f ./docker/docker-compose.yml build",
    "docker-prod:dev": "docker-compose -f ./docker/docker-compose.yml up",
    "docker:build": "docker-compose -f ./docker/docker-compose.dev.yml build",
    "docker:dev": "docker-compose -f ./docker/docker-compose.dev.yml up",
    "docker:push": "npm run docker-hub:build && npm run docker:tag && docker push antdesign/ant-design-pro",
    "docker:tag": "docker tag ant-design-pro antdesign/ant-design-pro",
    "fetch:blocks": "pro fetch-blocks && npm run prettier",
    "gh-pages": "cp CNAME ./dist/ && gh-pages -d dist",
    "i18n-remove": "pro i18n-remove --locale=zh-CN --write",
    "lint": "npm run lint:js && npm run lint:style && npm run lint:prettier",
    "lint:prettier": "prettier --check \"**/*\" --end-of-line auto",
    "lint-staged": "lint-staged",
    "lint-staged:js": "eslint --ext .js,.jsx,.ts,.tsx ",
    "lint:fix": "eslint --fix --cache --ext .js,.jsx,.ts,.tsx --format=pretty ./src && npm run lint:style",
    "lint:js": "eslint --cache --ext .js,.jsx,.ts,.tsx --format=pretty ./src",
    "lint:style": "stylelint --fix \"src/**/*.less\" --syntax less",
    "prettier": "prettier -c --write \"**/*\"",
    "site": "npm run fetch:blocks && npm run build",
    "start": "umi dev",
    "dev": "npm run start:dev",
    "start:dev": "cross-env REACT_APP_ENV=dev MOCK=none umi dev",
    "start:no-mock": "cross-env MOCK=none umi dev",
    "start:no-ui": "cross-env UMI_UI=none umi dev",
    "start:pre": "cross-env REACT_APP_ENV=pre umi dev",
    "start:test": "cross-env REACT_APP_ENV=test MOCK=none umi dev",
    "test": "umi test",
    "test:all": "node ./tests/run-tests.js",
    "test:component": "umi test ./src/components",
    "tsc": "tsc"
  },
  "husky": {
    "hooks": {
      "pre-commit": "npm run lint-staged"
    }
  },
  "lint-staged": {
    "**/*.less": "stylelint --syntax less",
    "**/*.{js,jsx,ts,tsx}": "npm run lint-staged:js",
    "**/*.{js,jsx,tsx,ts,less,md,json}": [
      "prettier --write"
    ]
  },
  "browserslist": [
    "> 1%",
    "last 2 versions",
    "not ie <= 10"
  ],
  "dependencies": {
    "@ant-design/icons": "^4.0.6",
    "@ant-design/pro-layout": "^5.0.9",
    "@ant-design/pro-table": "^2.2.1",
    "@antv/data-set": "^0.11.1",
    "@antv/l7": "^2.1.15",
    "@antv/l7-maps": "^2.1.15",
    "@types/js-cookie": "^2.2.6",
    "@types/lodash.debounce": "^4.0.6",
    "@types/lodash.isequal": "^4.5.5",
    "@types/numeral": "0.0.26",
    "@types/qrcode.react": "^1.0.0",
    "@types/react-router": "^5.1.5",
    "@typescript-eslint/parser": "^2.28.0",
    "@umijs/hooks": "^1.9.1",
    "antd": "^4.1.3",
    "bizcharts": "^3.5.8",
    "bizcharts-plugin-slider": "^2.1.1-beta.1",
    "classnames": "^2.2.6",
    "dayjs": "^1.8.24",
    "gg-editor": "^2.0.2",
    "js-cookie": "^2.2.1",
    "lodash": "^4.17.11",
    "lodash-decorators": "^6.0.0",
    "lodash.debounce": "^4.0.8",
    "lodash.isequal": "^4.5.0",
    "moment": "^2.24.0",
    "numeral": "^2.0.6",
    "nzh": "^1.0.3",
    "omit.js": "^1.0.2",
    "path-to-regexp": "2.4.0",
    "prop-types": "^15.5.10",
    "qrcode.react": "^1.0.0",
    "qs": "^6.9.3",
    "rc-field-form": "^1.1.2",
    "react": "^16.13.1",
    "react-copy-to-clipboard": "^5.0.1",
    "react-dom": "^16.13.1",
    "react-fittext": "^1.0.0",
    "react-helmet": "^5.2.1",
    "react-helmet-async": "^1.0.5",
    "react-router": "^4.3.1",
    "redux": "^4.0.1",
    "ts-md5": "^1.2.7",
    "umi": "^3.1.1",
    "umi-request": "^1.0.8",
    "use-merge-value": "^1.0.1",
    "webpack-chain": "^6.4.0"
  },
  "devDependencies": {
    "@ant-design/pro-cli": "^1.0.20",
    "@types/classnames": "^2.2.10",
    "@types/express": "^4.17.6",
    "@types/history": "^4.7.2",
    "@types/jest": "^25.2.1",
    "@types/lodash": "^4.14.144",
    "@types/qs": "^6.5.3",
    "@types/react": "^16.9.34",
    "@types/react-dom": "^16.9.6",
    "@types/react-helmet": "^5.0.13",
    "@umijs/fabric": "^2.0.7",
    "@umijs/plugin-block-devtool": "1.2.1",
    "@umijs/preset-react": "^1.4.15",
    "@umijs/preset-ui": "^2.1.11",
    "chalk": "^3.0.0",
    "cross-env": "^7.0.0",
    "cross-port-killer": "^1.1.1",
    "enzyme": "^3.11.0",
    "eslint": "^6.8.0",
    "eslint-plugin-react-hooks": "^2.5.1",
    "express": "^4.17.1",
    "gh-pages": "^2.0.1",
    "husky": "^4.2.5",
    "jest-puppeteer": "^4.2.0",
    "jsdom-global": "^3.0.2",
    "lint-staged": "^10.1.1",
    "mockjs": "^1.0.1-beta3",
    "node-fetch": "^2.6.0",
    "prettier": "^2.0.4",
    "pro-download": "1.0.1",
    "redbox-react": "^1.6.0",
    "stylelint": "^13.3.2",
    "umi-plugin-antd-icon-config": "^2.0.1"
  },
  "optionalDependencies": {
    "puppeteer": "^2.0.0"
  },
  "engines": {
    "node": ">=10.0.0"
  },
  "checkFiles": [
    "src/**/*.js*",
    "src/**/*.ts*",
    "src/**/*.less",
    "config/**/*.js*",
    "scripts/**/*.js"
  ],
  "create-umi": {
    "ignoreScript": [
      "docker*",
      "functions*",
      "site",
      "generateMock"
    ],
    "ignoreDependencies": [
      "netlify*",
      "serverless"
    ],
    "ignore": [
      ".dockerignore",
      ".git",
      ".github",
      ".gitpod.yml",
      "CODE_OF_CONDUCT.md",
      "Dockerfile",
      "Dockerfile.*",
      "lambda",
      "LICENSE",
      "netlify.toml",
      "README.*.md",
      "azure-pipelines.yml",
      "docker",
      "CNAME",
      "create-umi"
    ]
  }
}

tsconfig.json

{
  "compilerOptions": {
    "outDir": "build/dist",
    "module": "esnext",
    "target": "esnext",
    "lib": ["esnext", "dom"],
    "sourceMap": true,
    "baseUrl": ".",
    "jsx": "react",
    "allowSyntheticDefaultImports": true,
    "moduleResolution": "node",
    "forceConsistentCasingInFileNames": true,
    "noImplicitReturns": true,
    "suppressImplicitAnyIndexErrors": true,
    "noUnusedLocals": true,
    "allowJs": true,
    "skipLibCheck": true,
    "experimentalDecorators": true,
    "strict": true,
    "paths": {
      "@/*": ["./src/*"],
      "@@/*": ["src/.umi/*"]
    }
  },
  "exclude": [
    "node_modules",
    "build",
    "dist",
    "scripts",
    "acceptance-tests",
    "webpack",
    "jest",
    "src/setupTests.ts",
    "tslint:latest",
    "tslint-config-prettier"
  ]
}

config.ts

import { defineConfig, utils } from 'umi';
import defaultSettings from './defaultSettings';
import routes from './routes.config';
import proxy from './proxy';
import webpackPlugin from './plugin.config';

const {winPath} = utils;
const {REACT_APP_ENV} = process.env;

export default defineConfig({
  analytics: {ga: '', baidu: ''},
  antd: {dark: defaultSettings.pureDark},
  crossorigin: false,
  devServer: {port: 8000, host: '0.0.0.0'},
  dva: {hmr: true},
  dynamicImport: {loading: '@/components/PageLoading/index'},
  hash: true,
  history: {type: 'browser'},
  lessLoader: {javascriptEnabled: true},
  manifest: {basePath: '/'},
  metas: [],
  routes: [routes],
  targets: {ie: 11},
  theme: {'primary-color': defaultSettings.primaryColor},
  title: 'app.title',
  locale: {
    default: 'zh-CN',
    antd: true,
    baseNavigator: true,
    baseSeparator: '-',
    title: true,
  },
  define: {
    REACT_APP_ENV: REACT_APP_ENV || false,
  },
  cssLoader: {
    modules: {
      getLocalIdent: (
        context: {
          resourcePath: string;
        },
        _: string,
        localName: string,
      ) => {
        if (
          context.resourcePath.includes('node_modules') ||
          context.resourcePath.includes('ant.design.pro.less') ||
          context.resourcePath.includes('global.less')
        ) {
          return localName;
        }
        const match = context.resourcePath.match(/src(.*)/);
        if (match && match[1]) {
          const antdProPath = match[1].replace('.less', '');
          const arr = winPath(antdProPath)
            .split('/')
            .map((a: string) => a.replace(/([A-Z])/g, '-$1'))
            .map((a: string) => a.toLowerCase());
          return `antd-pro${ arr.join('-') }-${ localName }`.replace(/--/g, '-');
        }
        return localName;
      },
    },
  },
  proxy: proxy[REACT_APP_ENV || 'dev'],
  chainWebpack: webpackPlugin,
});

Ant Design Pro 的 Issue 6360 中提供的方法:在 umi.ts 中配置 title: false 解决了上述问题。关闭 Issue,等 umijs 统一解决。

Ant Design Pro 的 Issue 6360 中提供的方法:在 umi.ts 中配置 title: false 解决了上述问题。关闭 Issue,等 umijs 统一解决。

可是,我在config中配置title=false,控制台仍会出现该警告。

Ant Design Pro 的 Issue 6360 中提供的方法:在 umi.ts 中配置 title: false 解决了上述问题。关闭 Issue,等 umijs 统一解决。

可是,我在config中配置title=false,控制台仍会出现该警告。
我也是,请问你现在解决这个问题了吗?

Ant Design Pro 的 Issue 6360 中提供的方法:在 umi.ts 中配置 title: false 解决了上述问题。关闭 Issue,等 umijs 统一解决。

可是,我在config中配置title=false,控制台仍会出现该警告。
我也是,请问你现在解决这个问题了吗?

没有的,不过有一种笨拙的方法可以解决:因为开启了国际化,所以可以尝试新增locales文件夹,只对中文进行配置(可能后面会提醒关于菜单的国际化配置的waring,所以,只配置菜单的中文应该就可以。之前一个项目有尝试过这种方法,是可以的,你可以试一试)

Ant Design Pro 的 Issue 6360 中提供的方法:在 umi.ts 中配置 title: false 解决了上述问题。关闭 Issue,等 umijs 统一解决。

可是,我在config中配置title=false,控制台仍会出现该警告。
我也是,请问你现在解决这个问题了吗?

没有的,不过有一种笨拙的方法可以解决:因为开启了国际化,所以可以尝试新增locales文件夹,只对中文进行配置(可能后面会提醒关于菜单的国际化配置的waring,所以,只配置菜单的中文应该就可以。之前一个项目有尝试过这种方法,是可以的,你可以试一试)

非常感谢,我用这种办法解决了。不过还是希望官方能解决一下,总感觉咱们这种是治标不治本

我这边引用atnd组件库时,默认是英文。使用.umirc.ts中配置
locale: { default: 'zh-CN', antd: true, title: false, },
也是始终在控制台提示devScripts.js:5836 Warning: The current popular language does not exist, please check the locales folder!,但是antd的语言可以调整为中文。在src目录下新建src/locales/zh-CN.ts文件,export default{},还是会在控制台提示错误信息,并且antd的语言被重置为英文

清除一下 localStorage 即可。

在src下新增locales\zh-CN.ts,我也是醉了

我这边将locales里面的属性baseNavigator设置为false解决了

locale: {
    default: 'ja-JP',
    antd: true,
    baseNavigator: false,
    title: false
  },

我这边将locales里面的属性baseNavigator设置为false解决了

locale: {
    default: 'ja-JP',
    antd: true,
    baseNavigator: false,
    title: false
  },

Due to your answer, I've fixed it. Thank you.

在src下新增locales\zh-CN.ts,我也是醉了

我也是这么解决的,容错性有待处理

Ant Design Pro 的 Issue 6360 中提供的方法:在 umi.ts 中配置 title: false 解决了上述问题。关闭 Issue,等 umijs 统一解决。

可是,我在config中配置title=false,控制台仍会出现该警告。
我也是,请问你现在解决这个问题了吗?

如果项目配置了 singular: true ,locales 要改成 locale

这个问题好像还是没有解决吧

这个都关闭这么久了,官方不会理会的,提新的吧

我这边将locales里面的属性baseNavigator设置为false解决了

locale: {
    default: 'ja-JP',
    antd: true,
    baseNavigator: false,
    title: false
  },

works

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nguyenhuutinh picture nguyenhuutinh  ·  3Comments

y2891663091 picture y2891663091  ·  4Comments

tauruswang picture tauruswang  ·  3Comments

afc163 picture afc163  ·  3Comments

kitebear picture kitebear  ·  3Comments