
Security News
Feross on TBPN: How North Korea Hijacked Axios
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.
@zsunshine/intl-generator
Advanced tools
intl-generator工具是一个用于解决开发时,国际化语言包难于维护,减少因切换目录亦影响开发进度
目前默认自动识别一下模式intl.formatMessage({id:xxxx})
默认使用id后的语言做语言包的key值
默认的识别的范围时项目下 src, 生成语言en-US.ts、zh-CN.ts,当然这些都是可配的,包括上方识别取值规则
暂时没有内置翻译,只是自动生成文件,翻译对接接口可后续根据业务进行配置
npm install @zsunshine/intl-generator
yarn add @zsunshine/intl-generator
pnpm i @zsunshine/intl-generator
在package.json 中的 scripts字段配置以下命令
{
//...
scripts: {
// 扫描项目全局,识别国际化标识,生成语言包
"intl:scan": "intl-generator",
// 监听项目文件变化自动生成,时机为保存时
"intl:watch": "intl-generator --watch",
// 清除未被项目引用的语言包中的标识
"intl:clean": "intl-generator --clean",
}
}
可通过在项目根目录中新增intlGen 配置文件,对脚本进行配置,支持一下文件类型
| 属性名 | 描述 | 类型 | 默认值 |
|---|---|---|---|
| document | 项目文件识别正则 | String | ./src/**/*.ts?(x) |
| matchPattern | 国际化识别并提取key正则,需包含子表达式,用于提取key | String | intl.formatMessage\\({[^{]*id:\\s?['"]([\\s\\S]*?)['"] |
| locales | 多语言类型数组 | String[] | ['zh-CN', 'en-US'] |
| translate | 翻译扩展接口,locale为配置的多语言类型,texts为在项目中识别出来的中文key值,最终在等量promise返回翻译。默认不做翻译 | (locale:String, texts:String[]) => Promise<String[]> | -- |
| output | 输出配置。 mode 为输出路径是绝对路径或是相对路径; path 为输出路径; filename 根据语言类型生成文件名 | {mode:String,path:String,filename:(locale:String)=>String} | {mode: 'relative',path: './src/locales',filename: (locale) => locale+'.ts'} |
以下亦是默认配置
// intlGen.ts
export default {
document: './src/**/*.ts?(x)',
matchPattern: `intl.formatMessage\\({[^{]*id:\\s?['"]([\\s\\S]*?)['"]`,
locales: ['zh-CN', 'en-US'],
translate: (locale, texts) => Promise.resolve(texts),
output: {
mode: 'relative',
path: './src/locales',
filename: (locale) => `${locale}.ts`,
},
};
FAQs
We found that @zsunshine/intl-generator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.

Security News
OpenSSF has issued a high-severity advisory warning open source developers of an active Slack-based campaign using impersonation to deliver malware.

Research
/Security News
Malicious packages published to npm, PyPI, Go Modules, crates.io, and Packagist impersonate developer tooling to fetch staged malware, steal credentials and wallets, and enable remote access.