alibaba / react-intl-universal

Internationalize React apps. Not only for Component but also for Vanilla JS.
1.33k stars 154 forks source link

react-intl-universal-extract not work for Chinese #165

Closed hongdeyuan closed 2 years ago

hongdeyuan commented 3 years ago
import intl from 'react-intl-universal';

export default function Custom404() {
  return <h1>{intl.get('没有找到该资源').defaultMessage('404 - 没有找到该资源')}</h1>;
}

//package.json "intl:extract": "react-intl-universal-extract --cmd extract --source-path ./ --output-path ./lang/locales/zhCN.json --verbose",

In the zhCN.json file, the content cannot be extracted:intl.get('没有找到该资源').defaultMessage('404 - 没有找到该资源')

so, I suspect react-intl-universal-extract does not support Chinese keys

hongdeyuan commented 3 years ago

const DETECT_REGEXP = /(intl|IntlUtils)\s*\.\s*(get\s*\(\s*["']([\w.-]+)["'][\s\S]*?\)\s*\.\s*(defaultMessage|d)\s*\(\s*["']([\s\S]+?)["']|getHTML*\s*\(\s*["']([\w.-]+)["'][\s\S]*?\)\s*\.\s*(defaultMessage|d)\s*\(\s*(["'<][\s\S]+?["'>]))[\s*,]*\)/gm;

Replace : src/util/constant.js for support Chinese keys

const DETECT_REGEXP = /(intl|IntlUtils)\s*\.\s*(get\s*\(\s*["']([\s\S]+?)["'][\s\S]*?\)\s*\.\s*(defaultMessage|d)\s*\(\s*["']([\s\S]+?)["']|getHTML*\s*\(\s*["']([\s\S]+?)["'][\s\S]*?\)\s*\.\s*(defaultMessage|d)\s*\(\s*(["'<][\s\S]+?["'>]))[\s*,]*\)/gm;

hongdeyuan commented 3 years ago

@cwtuan : PR: https://github.com/alibaba/react-intl-universal/pull/166

cwtuan commented 3 years ago

Yes, Chinese key isn't supported and not recommended.

hongdeyuan commented 3 years ago

Thank you for your answer, but why not recommended?

cwtuan commented 2 years ago

The json key is better to be English.