gpt-po 1.2.1 → 1.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -60,7 +60,7 @@ Options:
60
60
  --verbose show verbose log
61
61
  -l, --lang <lang> target language (ISO 639-1 code)
62
62
  -o, --output <file> output file path, overwirte po file by default
63
- --context context file path (provides additional context to the bot)
63
+ --context <file> context file path (provides additional context to the bot)
64
64
  -h, --help display help for command
65
65
  ```
66
66
 
package/README_zh-CN.md CHANGED
@@ -62,7 +62,7 @@ npm install gpt-po
62
62
  --verbose 显示详细日志
63
63
  -l, --lang <lang> 目标语言 (ISO 639-1 代码)
64
64
  -o, --output <file> 输出文件路径,默认覆盖 po 文件
65
- --context 上下文文件路径(为机器人提供额外的上下文)
65
+ --context <file> 上下文文件路径(为机器人提供额外的上下文)
66
66
  -h, --help 显示命令帮助
67
67
  ```
68
68
 
package/lib/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gpt-po",
3
- "version": "1.2.1",
3
+ "version": "1.2.3",
4
4
  "description": "command tool for translate po files by gpt",
5
5
  "main": "lib/src/index.js",
6
6
  "type": "module",
@@ -1,2 +1,2 @@
1
- #!/usr/bin/env node --no-warnings=ExperimentalWarning
1
+ #!/usr/bin/env -S node --no-warnings=ExperimentalWarning
2
2
  export {};
package/lib/src/index.js CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env node --no-warnings=ExperimentalWarning
1
+ #!/usr/bin/env -S node --no-warnings=ExperimentalWarning
2
2
  import { Command, Option } from "commander";
3
3
  import path from "path";
4
4
  import { fileURLToPath } from "url";
@@ -58,7 +58,10 @@ export async function translate(src, lang, model, translations, contextFile) {
58
58
  .join("\n");
59
59
  const context = contextFile ? "\n\nContext: " + fs.readFileSync(contextFile, "utf-8") : "";
60
60
  const translationsContent = translations
61
- .map((tr, idx) => `<translate index="${idx + dicts.user.length + 1}">${tr.msgid}</translate>`)
61
+ .map((tr, idx) => {
62
+ const contextAttr = tr.msgctxt ? ` context="${tr.msgctxt}"` : "";
63
+ return `<translate index="${idx + dicts.user.length + 1}"${contextAttr}>${tr.msgid}</translate>`;
64
+ })
62
65
  .join("\n");
63
66
  const res = await _openai.chat.completions.create({
64
67
  model: model,
@@ -132,11 +135,16 @@ export async function translatePo(model, po, source, lang, verbose, output, cont
132
135
  let trimed = false;
133
136
  for (const [ctx, entries] of Object.entries(potrans.translations)) {
134
137
  for (const [msgid, trans] of Object.entries(entries)) {
135
- if (msgid == "")
138
+ if (msgid === "")
136
139
  continue;
137
140
  if (!trans.msgstr[0]) {
138
- list.push(trans);
139
- continue;
141
+ list.push({
142
+ msgctxt: trans.msgctxt || ctx,
143
+ msgid,
144
+ msgid_plural: trans.msgid_plural,
145
+ msgstr: trans.msgstr,
146
+ comments: trans.comments
147
+ });
140
148
  }
141
149
  else if (trimRegx.test(trans.msgstr[0])) {
142
150
  trimed = true;
@@ -12,7 +12,14 @@ Translation guidelines are as follows:
12
12
  - Input messages will be wrapped in `<translate>` XML tags with an index attribute, e.g., `<translate index="1">`.
13
13
  - Respond with the translated message wrapped in `<translated>` XML tags, including the same index attribute, e.g., `<translated index="1">`.
14
14
 
15
- 4. **Multiple Translations**:
15
+ 4. **Context Handling**:
16
+ - Some messages will include a context attribute in the translate tag, e.g., `<translate index="1" context="Menu">`.
17
+ - Use this context to inform your translation but only return the translated text.
18
+ - Example:
19
+ Input: `<translate index="1" context="Menu">File</translate>`
20
+ Output: `<translated index="1">Fichier</translated>`
21
+
22
+ 5. **Multiple Translations**:
16
23
  - You may receive multiple translation requests in a single input, each with a unique index.
17
24
  - Ensuring the complete number of requests are translated, even if they are repeated, while maintaining the original order when possible.
18
25
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gpt-po",
3
- "version": "1.2.1",
3
+ "version": "1.2.3",
4
4
  "description": "command tool for translate po files by gpt",
5
5
  "main": "lib/src/index.js",
6
6
  "type": "module",