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

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

Closed
hongdeyuan opened this issue Aug 9, 2021 · 5 comments
Closed

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

hongdeyuan opened this issue Aug 9, 2021 · 5 comments

Comments

@hongdeyuan
Copy link

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
Copy link
Author

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

@hongdeyuan
Copy link
Author

hongdeyuan commented Aug 9, 2021

@cwtuan : PR: #166

@cwtuan
Copy link
Collaborator

cwtuan commented Aug 9, 2021

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

@hongdeyuan
Copy link
Author

hongdeyuan commented Aug 9, 2021

Thank you for your answer, but why not recommended?

@cwtuan
Copy link
Collaborator

cwtuan commented Dec 29, 2021

The json key is better to be English.

@cwtuan cwtuan closed this as completed Dec 29, 2021
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