
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
chinese-code-processor
Advanced tools
这是一个用与提取和分析替换代码中的中文常量的工具,以方便对现有的代码进行国际化(i18n):
目前支持的语言有:
$ npm install -g chinese-code-processor
cn-processor.js <cmd> [args]
Commands:
cn-processor.js extract [pattern] begin extracting
cn-processor.js inject [pattern] begin injecting
Options:
--version Show version number [boolean]
--output, -o [default: "output.json"]
--input, -i [default: "input.json"]
--variable, -v [default: "t"]
--help Show help [boolean]
使用 extract 命令来提取中文,使用 inject 命令来植入 key
示例:
❯ cn-processor extract 'src/**/*.js'
使用 input/output 参数来指定输入输出文件, variable 参数来指定植入的变量名,默认为 t
提取数据 examples:
[
...
{
"path": "./tests/ESExtractor/examples/1/input.js",
"location": {
"line": 6,
"column": 15
},
"content": "共享",
"nodeType": "StringLiteral",
"startOffset": 108,
"endOffset": 112,
"isInJSXAttribute": false
},
...
]
则可以把代码中文提取出来,包含了中文应有的信息,透过这些信息,则可以对现有的代码进行替换。 我们只需要在数据中加入一个 "uniqueKey" 字段,则可以透过下述的 inject 方法,把代码重新替换成 t 函数的形式
把代码中的中文提取出来之后,可以把中文对应的 uniqueKey 填上,然后使用 Injector 可以把代码中相应的中文替换成 t('some_key')
suggestions 数据 examples:
[
...
{
"path": "./tests/ESExtractor/examples/2/input.js",
"location": {
"line": 2,
"column": 15
},
"content": "共享",
"nodeType": "StringLiteral",
"startOffset": 53,
"endOffset": 57,
"isInJSXAttribute": false,
"uniqueKey": "share"
},
...
]
Input:
const VISITOR_PERMISSION_SETTINGS = {
SHAREABLE: '共享',
EDITABLE: '编辑',
COMMENTABLE: '评论',
READABLE: '阅读',
};
Output:
const VISITOR_PERMISSION_SETTINGS = {
SHAREABLE: t('share'),
EDITABLE: t('edit'),
COMMENTABLE: t('comment'),
READABLE: t('read'),
};
除了可以透过 cli 使用此工具,还可以通过编程的的方式使用,具体用法可以参考 /tests/ 和 /bin/
import { ESExtractor } from 'chinese-code-processor'
import * as fs from 'fs'
const path = "./index.js";
const code = fs.readFileSync(path, "utf8");
const extractor = new ESExtractor("./index.js");
console.log(extractor.analyze(code));
则返回提取的数据格式:
export interface ESInformation {
path: string;
content: string;
startOffset: number;
endOffset: number;
nodeType: string;
location: Location;
isInJSXAttribute: boolean;
}
举起参考 /tests/ESInjector 下面的用法:
const injector = new ESInjector();
const injected = injector.inject(code, suggestions);
其中 suggestions 的格式为:
export interface InjectSuggestion {
content: string;
uniqueKey: string;
startOffset: number;
endOffset: number;
nodeType: string;
isInJSXAttribute: boolean;
}
以完成国际化
FAQs
[![npm][npm]][npm-url]
The npm package chinese-code-processor receives a total of 0 weekly downloads. As such, chinese-code-processor popularity was classified as not popular.
We found that chinese-code-processor demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

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.