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 +1 -1
- package/README_zh-CN.md +1 -1
- package/lib/package.json +1 -1
- package/lib/src/index.d.ts +1 -1
- package/lib/src/index.js +1 -1
- package/lib/src/translate.js +12 -4
- package/lib/src/userprompt.txt +8 -1
- package/package.json +1 -1
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
|
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
package/lib/package.json
CHANGED
package/lib/src/index.d.ts
CHANGED
@@ -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
package/lib/src/translate.js
CHANGED
@@ -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) =>
|
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(
|
139
|
-
|
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;
|
package/lib/src/userprompt.txt
CHANGED
@@ -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. **
|
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
|
|