https://github.com/marvelsq/extract-locale
extract string to formatMessage()
https://github.com/marvelsq/extract-locale
i18n internationalization localization
Last synced: over 1 year ago
JSON representation
extract string to formatMessage()
- Host: GitHub
- URL: https://github.com/marvelsq/extract-locale
- Owner: MarvelSQ
- Created: 2023-02-22T03:48:55.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-06-13T03:55:49.000Z (about 3 years ago)
- Last Synced: 2025-03-08T18:34:22.429Z (over 1 year ago)
- Topics: i18n, internationalization, localization
- Language: TypeScript
- Homepage: https://extract-locale.vercel.app
- Size: 396 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# extract-locale
使用 babel 自动收集未翻译的文案 并替换为 formatMessage
源文件
```jsx
const App = (user) => {
return (
用户名: {user.name}
地址: {user.adderss}
);
};
```
执行该命令
```bash
extract-locale ./src/**/*.{ts,tsx}
```
编译后的文件
```jsx
import { useIntl } from "xxx/IntlProvider";
const App = (user) => {
const intl = useIntl();
return (
{intl.formatMessage("@LOCALE_TEXT_0")} {user.name}
{intl.formatMessage("@LOCALE_TEXT_0")} {user.adderss}
);
};
```
对应的文案
```json
{
"@LOCALE_TEXT_0": "用户名:",
"@LOCALE_TEXT_1": "地址:"
}
```
### 参数
主要参数为 文件匹配符
| 参数 | 缩写 | 描述 |
| ----------------- | ---- | --------------------------------- |
| --locale | -l | 输入已存在的 localemap |
| --prefix | -p | 国际化文案的前缀(`@LOCALE_TEXT_`) |
| --offset | -o | 起始序号(`0`) |
| --no-auto | -A | 是否禁止自动替换(`false`) |
| --no-auto-name | | 是否禁止自动命名(`false`) |