gpt-po 1.0.9 → 1.0.10

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -29,20 +29,21 @@ Set `OPENAI_API_KEY` before using this tool.
29
29
  - `gpt-po systemprompt --reset` Reset system prompts
30
30
 
31
31
  ```
32
- Usage: gpt-po [command] [options]
32
+ Usage: gpt-po [options] [command]
33
33
 
34
34
  command tool for translate po files by gpt
35
35
 
36
36
  Options:
37
- -V, --version output the version number
38
- -h, --help display help for command
37
+ -V, --version output the version number
38
+ -h, --help display help for command
39
39
 
40
40
  Commands:
41
- translate [options] translate po file (default command)
42
- sync [options] update po from pot file
43
- systemprompt open/edit system prompt
44
- userdict open/edit user dictionary
45
- help [command] display help for command
41
+ translate [options] translate po file (default command)
42
+ sync [options] update po from pot file
43
+ systemprompt [options] open/edit system prompt
44
+ userdict [options] open/edit user dictionary
45
+ remove [options] remove po entries by options
46
+ help [command] display help for command
46
47
  ```
47
48
 
48
49
  ```
@@ -63,3 +64,20 @@ Options:
63
64
  -o, --output <file> output file path, overwirte po file by default
64
65
  -h, --help display help for command
65
66
  ```
67
+
68
+ ```
69
+ Usage: gpt-po remove [options]
70
+
71
+ remove po entries by options
72
+
73
+ Options:
74
+ --po <file> po file path
75
+ --fuzzy remove fuzzy entries
76
+ -obs, --obsolete remove obsolete entries
77
+ -ut, --untranslated remove untranslated entries
78
+ -t, --translated remove translated entries
79
+ -tnf, --translated-not-fuzzy remove translated not fuzzy entries
80
+ -ft, --fuzzy-translated remove fuzzy translated entries
81
+ -rc, --reference-contains <text> remove entries whose reference contains text, text can be a regular expression like /text/ig
82
+ -h, --help display help for command
83
+ ```
package/README_zh-CN.md CHANGED
@@ -29,20 +29,21 @@ npm install gpt-po
29
29
  - `gpt-po systemprompt --reset` 重置系统提示词
30
30
 
31
31
  ```
32
- Usage: gpt-po [command] [options]
32
+ Usage: gpt-po [options] [command]
33
33
 
34
34
  command tool for translate po files by gpt
35
35
 
36
36
  Options:
37
- -V, --version output the version number
38
- -h, --help display help for command
37
+ -V, --version output the version number
38
+ -h, --help display help for command
39
39
 
40
40
  Commands:
41
- translate [options] translate po file (default command)
42
- sync [options] update po from pot file
43
- systemprompt open/edit system prompt
44
- userdict open/edit user dictionary
45
- help [command] display help for command
41
+ translate [options] translate po file (default command)
42
+ sync [options] update po from pot file
43
+ systemprompt [options] open/edit system prompt
44
+ userdict [options] open/edit user dictionary
45
+ remove [options] remove po entries by options
46
+ help [command] display help for command
46
47
  ```
47
48
 
48
49
  ```
@@ -56,10 +57,27 @@ Options:
56
57
  --model <model> openai model (choices: "gpt-4", "gpt-4-0314", "gpt-4-32k", "gpt-4-32k-0314", "gpt-3.5-turbo", "gpt-3.5-turbo-0301",
57
58
  default: "gpt-3.5-turbo")
58
59
  --po <file> po file path
59
- --dir <dir> po files directory
60
+ --dir <dir> po file directory
60
61
  -src, --source <lang> source language (default: "english")
61
62
  --verbose show verbose log
62
63
  -l, --lang <lang> target language (default: "simplified chinese")
63
64
  -o, --output <file> output file path, overwirte po file by default
64
65
  -h, --help display help for command
65
66
  ```
67
+
68
+ ```
69
+ Usage: gpt-po remove [options]
70
+
71
+ remove po entries by options
72
+
73
+ Options:
74
+ --po <file> po file path
75
+ --fuzzy remove fuzzy entries
76
+ -obs, --obsolete remove obsolete entries
77
+ -ut, --untranslated remove untranslated entries
78
+ -t, --translated remove translated entries
79
+ -tnf, --translated-not-fuzzy remove translated not fuzzy entries
80
+ -ft, --fuzzy-translated remove fuzzy translated entries
81
+ -rc, --reference-contains <text> remove entries whose reference contains text, text can be a regular expression like /text/ig
82
+ -h, --help display help for command
83
+ ```
package/lib/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gpt-po",
3
- "version": "1.0.9",
3
+ "version": "1.0.10",
4
4
  "description": "command tool for translate po files by gpt",
5
5
  "main": "lib/src/index.js",
6
6
  "bin": {
package/lib/src/index.js CHANGED
@@ -15,6 +15,7 @@ const pkg = require("../package.json");
15
15
  const sync_1 = require("./sync");
16
16
  const translate_1 = require("./translate");
17
17
  const utils_1 = require("./utils");
18
+ const manipulate_1 = require("./manipulate");
18
19
  const program = new commander_1.Command();
19
20
  program.name(pkg.name).version(pkg.version).description(pkg.description);
20
21
  program
@@ -106,5 +107,33 @@ program
106
107
  (0, utils_1.copyFileIfNotExists)(dictFile, copyFile);
107
108
  (0, utils_1.openFileByDefault)(dictFile);
108
109
  });
110
+ // program command `remove` with help text `remove po entries by options`
111
+ program
112
+ .command("remove")
113
+ .description("remove po entries by options")
114
+ .requiredOption("--po <file>", "po file path")
115
+ .option("--fuzzy", "remove fuzzy entries")
116
+ .option("-obs, --obsolete", "remove obsolete entries")
117
+ .option("-ut, --untranslated", "remove untranslated entries")
118
+ .option("-t, --translated", "remove translated entries")
119
+ .option("-tnf, --translated-not-fuzzy", "remove translated not fuzzy entries")
120
+ .option("-ft, --fuzzy-translated", "remove fuzzy translated entries")
121
+ .option("-rc, --reference-contains <text>", "remove entries whose reference contains text, text can be a regular expression like /text/ig")
122
+ .action((args) => __awaiter(void 0, void 0, void 0, function* () {
123
+ const { po, fuzzy, obsolete, untranslated, translated, translatedNotFuzzy, fuzzyTranslated, referenceContains } = args;
124
+ const options = {
125
+ fuzzy,
126
+ obsolete,
127
+ untranslated,
128
+ translated,
129
+ translatedNotFuzzy,
130
+ fuzzyTranslated,
131
+ referenceContains,
132
+ };
133
+ const output = args.output || po;
134
+ const translations = yield (0, utils_1.parsePo)(po);
135
+ yield (0, utils_1.compilePo)((0, manipulate_1.removeByOptions)(translations, options), output);
136
+ console.log("done");
137
+ }));
109
138
  program.parse(process.argv);
110
139
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,14 @@
1
+ import { GetTextTranslations } from "gettext-parser";
2
+ export interface RemoveByOptions {
3
+ fuzzy?: boolean;
4
+ obsolete?: boolean;
5
+ untranslated?: boolean;
6
+ translated?: boolean;
7
+ translatedNotFuzzy?: boolean;
8
+ fuzzyTranslated?: boolean;
9
+ referenceContains?: string;
10
+ }
11
+ /**
12
+ * remove entity by options
13
+ */
14
+ export declare function removeByOptions(potrans: GetTextTranslations, options: RemoveByOptions | undefined): GetTextTranslations;
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.removeByOptions = void 0;
4
+ /**
5
+ * remove entity by options
6
+ */
7
+ function removeByOptions(potrans, options) {
8
+ var _a, _b, _c, _d, _e, _f, _g, _h;
9
+ const fuzzyRegx = /\bfuzzy\b/;
10
+ const obsoleteRegx = /\bobsolete\b/;
11
+ const refRegMatch = (options === null || options === void 0 ? void 0 : options.referenceContains)
12
+ ? /^\/([^\/]+)\/([igmsuy]*)/.exec(options === null || options === void 0 ? void 0 : options.referenceContains)
13
+ : null;
14
+ const refRegx = refRegMatch ? new RegExp(refRegMatch[1], refRegMatch[2]) : null;
15
+ for (const [ctx, entries] of Object.entries(potrans.translations)) {
16
+ for (const [msgid, entry] of Object.entries(entries)) {
17
+ const msgstr = entry.msgstr.join("\n");
18
+ // remove fuzzy
19
+ if ((options === null || options === void 0 ? void 0 : options.fuzzy) && fuzzyRegx.test(((_a = entry.comments) === null || _a === void 0 ? void 0 : _a.flag) || "")) {
20
+ delete potrans.translations[ctx][msgid];
21
+ }
22
+ // remove obsolete
23
+ if ((options === null || options === void 0 ? void 0 : options.obsolete) && obsoleteRegx.test(((_b = entry.comments) === null || _b === void 0 ? void 0 : _b.flag) || "")) {
24
+ delete potrans.translations[ctx][msgid];
25
+ }
26
+ // remove untranslated
27
+ if ((options === null || options === void 0 ? void 0 : options.untranslated) && msgstr.length === 0) {
28
+ delete potrans.translations[ctx][msgid];
29
+ }
30
+ // remove translated
31
+ if ((options === null || options === void 0 ? void 0 : options.translated) && msgstr.length > 0) {
32
+ delete potrans.translations[ctx][msgid];
33
+ }
34
+ // remove translated not fuzzy
35
+ if ((options === null || options === void 0 ? void 0 : options.translatedNotFuzzy) && msgstr.length > 0 && !fuzzyRegx.test(((_c = entry.comments) === null || _c === void 0 ? void 0 : _c.flag) || "")) {
36
+ delete potrans.translations[ctx][msgid];
37
+ }
38
+ // remove fuzzy translated
39
+ if ((options === null || options === void 0 ? void 0 : options.fuzzyTranslated) && msgstr.length > 0 && fuzzyRegx.test(((_d = entry.comments) === null || _d === void 0 ? void 0 : _d.flag) || "")) {
40
+ delete potrans.translations[ctx][msgid];
41
+ }
42
+ // remove reference contains
43
+ if (options === null || options === void 0 ? void 0 : options.referenceContains) {
44
+ if (refRegx) {
45
+ if (((_e = entry.comments) === null || _e === void 0 ? void 0 : _e.reference) && refRegx.test((_f = entry.comments) === null || _f === void 0 ? void 0 : _f.reference)) {
46
+ delete potrans.translations[ctx][msgid];
47
+ }
48
+ }
49
+ else if ((_h = (_g = entry.comments) === null || _g === void 0 ? void 0 : _g.reference) === null || _h === void 0 ? void 0 : _h.includes(options === null || options === void 0 ? void 0 : options.referenceContains)) {
50
+ delete potrans.translations[ctx][msgid];
51
+ }
52
+ }
53
+ }
54
+ }
55
+ return potrans;
56
+ }
57
+ exports.removeByOptions = removeByOptions;
58
+ //# sourceMappingURL=manipulate.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gpt-po",
3
- "version": "1.0.9",
3
+ "version": "1.0.10",
4
4
  "description": "command tool for translate po files by gpt",
5
5
  "main": "lib/src/index.js",
6
6
  "bin": {