cc-translate 1.3.2 → 1.3.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 +77 -32
- package/index.d.ts +3 -3
- package/index.js +296 -132
- package/lib/cache/index.d.ts +8 -4
- package/lib/cache/index.d.ts.map +1 -1
- package/lib/cache/index.js +77 -12
- package/lib/translation-format.d.ts +5 -0
- package/lib/translation-format.d.ts.map +1 -0
- package/lib/translation-format.js +31 -0
- package/lib/translation-metadata.d.ts +4 -1
- package/lib/translation-metadata.d.ts.map +1 -1
- package/lib/translation-metadata.js +49 -22
- package/lib/translation-response.d.ts +7 -0
- package/lib/translation-response.d.ts.map +1 -1
- package/lib/translation-response.js +122 -0
- package/package.json +3 -2
- package/types/index.d.ts +20 -4
- package/types/index.d.ts.map +1 -1
- package/CHANGELOG.md +0 -78
package/README.md
CHANGED
|
@@ -73,44 +73,87 @@ const reference = new TranslationReferencePlugin({
|
|
|
73
73
|
await agent.translate(reference);
|
|
74
74
|
```
|
|
75
75
|
|
|
76
|
-
Pass
|
|
77
|
-
`await agent.translate(
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
76
|
+
Pass one reference plugin directly. To translate without a reference, call
|
|
77
|
+
`await agent.translate()`. That mode uses the source and ordinary source
|
|
78
|
+
cache and leaves existing `.references` files untouched.
|
|
79
|
+
|
|
80
|
+
When a reference matches, it determines the meaning to translate. File-level
|
|
81
|
+
`_meta.context` provides secondary guidance only where it agrees with the
|
|
82
|
+
reference.
|
|
81
83
|
|
|
82
84
|
The cache compares source text and tracked reference text for each target
|
|
83
85
|
language. Changing a reference value requeues the corresponding key even if
|
|
84
|
-
the source text is unchanged. A newly filled
|
|
85
|
-
|
|
86
|
+
the source text is unchanged. A newly filled key also requeues once the
|
|
87
|
+
reference file has tracked values for that target. Clearing or deleting a
|
|
86
88
|
reference leaves existing translations intact.
|
|
87
89
|
|
|
88
|
-
On
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
90
|
+
On first use, the current matches become the baseline for entries with a
|
|
91
|
+
non-blank target translation and a source cache hit. Missing source cache
|
|
92
|
+
files or entries still trigger translation, even if the target file already
|
|
93
|
+
contains a translation. The source and reference caches for those entries are
|
|
94
|
+
written after successful translation.
|
|
95
|
+
When a changed reference requeues a key, the model sees the new reference and
|
|
96
|
+
the required source placeholders. This request omits the original wording,
|
|
97
|
+
file context, and global `fineTune` so previous terminology cannot steer the
|
|
98
|
+
translation.
|
|
99
|
+
|
|
100
|
+
For every locale, local checks reject unsupported writing systems, verbatim
|
|
101
|
+
echoes of a different reference language, and confidently identified text in
|
|
102
|
+
another language even when it uses the same writing system. A rejected
|
|
103
|
+
reference-based response falls back to the source in the same run. This uses
|
|
104
|
+
offline, sentence-level language detection and makes no model verification
|
|
105
|
+
calls. Short labels with uncertain language remain eligible. The check
|
|
106
|
+
allows plausible translations when the detector confuses Malay with
|
|
107
|
+
Indonesian or Nepali with Hindi.
|
|
108
|
+
|
|
109
|
+
When English is the source, identifiable foreign text within an English
|
|
110
|
+
entry is preserved, along with common notation such as `Δ` and `µm`.
|
|
111
|
+
Only the English portion is translated. Completely non-English entries are
|
|
112
|
+
skipped and logged with the source filename and key. File metadata such as
|
|
113
|
+
`_meta.context` can be written in Chinese or another language.
|
|
114
|
+
|
|
115
|
+
The script preserves common React and React Native i18n syntax, including
|
|
116
|
+
i18next `{{name}}` and `{{- name}}`, JSX-style tags such as `<0>…</0>`, ICU
|
|
117
|
+
arguments and their plural or select blocks, and placeholders such as
|
|
118
|
+
`%{name}` and `%1$s`. Text between rich-text tags can still be translated.
|
|
119
|
+
Placeholder changes cause the response to be retried. For a custom literal
|
|
120
|
+
format, add the exact text to `noTranslate`.
|
|
121
|
+
|
|
122
|
+
Only matched, non-blank references are saved under
|
|
123
|
+
`<cache>/<target-language>/.references/`. After initialization, the snapshot
|
|
124
|
+
records the reference actually sent with a successful translation. Entries
|
|
125
|
+
translated from the source alone update the ordinary source cache and remove
|
|
126
|
+
the corresponding key from `.references`. After a source fallback, the
|
|
127
|
+
ordinary cache stores a digest in `_meta.rejectedReferences` so an unchanged
|
|
128
|
+
reference is skipped on the next run. Editing the reference requeues the key.
|
|
129
|
+
The digest stores no reference text. The source and reference files are
|
|
130
|
+
read-only during translation.
|
|
131
|
+
Missing or blank reference values are omitted. Legacy `null` entries are
|
|
132
|
+
migrated with their reference identities, so filling one later still
|
|
133
|
+
triggers translation even if another reference plugin ran first.
|
|
94
134
|
|
|
95
135
|
Before any model calls, the plugin reports the reference language, directory,
|
|
96
136
|
file matches, and coverage of pending keys.
|
|
97
137
|
|
|
98
138
|
- When every pending entry has a non-empty reference, translation starts automatically.
|
|
99
|
-
- Missing files or entries in
|
|
100
|
-
If you confirm,
|
|
101
|
-
|
|
102
|
-
|
|
139
|
+
- Missing files or entries in the reference directory trigger a terminal
|
|
140
|
+
prompt. If you confirm, unmatched entries are translated from the source.
|
|
141
|
+
Declining or running without an interactive terminal ends the run before
|
|
142
|
+
translation.
|
|
103
143
|
- A missing or unreadable reference directory, or an invalid matching JSON
|
|
104
144
|
file, stops the run with an error that identifies the path.
|
|
105
145
|
|
|
106
146
|
The reference locale is read-only and its language is excluded from the output
|
|
107
147
|
targets. By default, the translation request includes both the source text and
|
|
108
148
|
its matched reference. Set `checkConflicts: true` to run a separate check before
|
|
109
|
-
translation.
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
149
|
+
translation. The check defaults to off. When enabled, each matched pending
|
|
150
|
+
key and each new reference baseline is checked once before any baseline is
|
|
151
|
+
saved. Confirmed conflicts and checks that still fail after retries receive
|
|
152
|
+
distinct entries in `error.log`, once per filename and key. A confirmed
|
|
153
|
+
conflict makes all targets use the source for that key, including targets
|
|
154
|
+
whose ordinary cache already matched. The usual `_meta.context`, `fineTune`,
|
|
155
|
+
and term protection apply. A check that fails after retries leaves that key
|
|
156
|
+
pending for the next run.
|
|
114
157
|
|
|
115
158
|
## File Context and Protected Terms
|
|
116
159
|
|
|
@@ -131,7 +174,7 @@ file, such as `locales/en/bots.json`.
|
|
|
131
174
|
|
|
132
175
|
| Field | Accepted value | Behavior |
|
|
133
176
|
| --- | --- | --- |
|
|
134
|
-
| `context` | Non-blank string | Adds business context to every translation request for this file.
|
|
177
|
+
| `context` | Non-blank string | Adds business context to every translation request for this file. When a reference is available, use this context only where it agrees with the reference. |
|
|
135
178
|
| `noTranslate` | Non-empty array of non-blank strings | Preserves the listed words or phrases in this file. Entries are terms such as `MAX` or `Cozy Card`, with case-sensitive, whole-term matching. |
|
|
136
179
|
|
|
137
180
|
Both fields are optional and validated independently. For example, a valid
|
|
@@ -155,15 +198,17 @@ in this configuration, and put file-specific terms in `_meta.noTranslate`.
|
|
|
155
198
|
Both lists use the same validation and matching rules. For a long list, keep it
|
|
156
199
|
in a separate project configuration file and import it into the entry script.
|
|
157
200
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
`
|
|
201
|
+
The script matches file-level terms first, then global terms, using the
|
|
202
|
+
original source text for both. A full phrase such as `Tip Box` stays intact
|
|
203
|
+
when a shorter term such as `Tip` also matches it. Distinct phrases such as
|
|
204
|
+
`Two Tip` and `Tip Box` are each preserved. If they share the same occurrence
|
|
205
|
+
of `Tip` in `Two Tip Box`, the script protects the combined span once.
|
|
162
206
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
207
|
+
Editing either list or the context alone does not retranslate existing
|
|
208
|
+
sentences. If a value is entirely a protected term, the script repairs a
|
|
209
|
+
different target value by copying the source directly, even on a cache hit.
|
|
210
|
+
To apply a rule change to an existing sentence, clear its key from the
|
|
211
|
+
relevant target-language caches.
|
|
167
212
|
|
|
168
213
|
## Directory Layout
|
|
169
214
|
|
|
@@ -193,7 +238,7 @@ your-project/
|
|
|
193
238
|
| `outputRootPath` | `string` | No | Output directory, defaults to `fileRootPath` |
|
|
194
239
|
| `concurrency` | `number` | No | Queue length, default `8` |
|
|
195
240
|
| `fineTune` | `string[]` | No | Extra translation context lines |
|
|
196
|
-
| `noTranslate` | `readonly string[]` | No | Terms preserved across source files.
|
|
241
|
+
| `noTranslate` | `readonly string[]` | No | Terms preserved across source files. Full protected phrases include their shorter matches. |
|
|
197
242
|
| `chatCompletionCreateParams` | `Partial<ChatCompletionCreateParams>` | No | Extra chat completion params |
|
|
198
243
|
|
|
199
244
|
### Utility Exports
|
package/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ClientOptions, OpenAI } from "openai";
|
|
2
|
-
import { II18nTranslateAgentParams, IJson, IOutputLanguageFile, ISingleTranslate, ITranslateChat, ITranslateChatResponse, SupportLanguageType } from "./types/index.js";
|
|
2
|
+
import { II18nTranslateAgentParams, IJson, IOutputLanguageFile, ISingleTranslate, ITranslateChat, ITranslateChatResponse, SourceCache, SupportLanguageType } from "./types/index.js";
|
|
3
3
|
import { TranslationReferencePlugin } from "./lib/translation-reference.js";
|
|
4
4
|
import { ChatCompletionCreateParams } from "openai/resources";
|
|
5
5
|
export { generateCache, deleteBatchCache } from "./lib/cache/index.js";
|
|
@@ -43,7 +43,7 @@ export declare class I18nTranslateAgent {
|
|
|
43
43
|
/**
|
|
44
44
|
* 翻译入口文件的所有支持的语言文件夹和其中的文件
|
|
45
45
|
*/
|
|
46
|
-
translate: (
|
|
46
|
+
translate: (referencePlugin?: TranslationReferencePlugin) => Promise<void>;
|
|
47
47
|
private reviewReferences;
|
|
48
48
|
/**
|
|
49
49
|
* 翻译单个文件
|
|
@@ -66,7 +66,7 @@ export declare class I18nTranslateAgent {
|
|
|
66
66
|
* @param fileName
|
|
67
67
|
* @returns
|
|
68
68
|
*/
|
|
69
|
-
getTranslateContent: (language: SupportLanguageType, fileName: string, deferredEmptyFiles?: IOutputLanguageFile[], sourceEntries?: IJson) => Promise<IJson | undefined>;
|
|
69
|
+
getTranslateContent: (language: SupportLanguageType, fileName: string, deferredEmptyFiles?: IOutputLanguageFile[], sourceEntries?: IJson, sourceCache?: SourceCache) => Promise<IJson | undefined>;
|
|
70
70
|
/**
|
|
71
71
|
* 输出语言文件
|
|
72
72
|
* @param {Object} jsonMap
|