gptrans 1.5.0 → 1.5.2

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.
Files changed (3) hide show
  1. package/README.md +4 -3
  2. package/index.js +13 -1
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -65,11 +65,12 @@ When creating a new instance of GPTrans, you can customize:
65
65
 
66
66
  | Option | Description | Default |
67
67
  |--------|-------------|---------|
68
- | `from` | Source language locale (BCP 47) | `es-AR` |
69
- | `target` | Target language locale (BCP 47) | `en-US` |
68
+ | `from` | Source language locale (BCP 47) | `en-US` |
69
+ | `target` | Target language locale (BCP 47) | `es` |
70
70
  | `model` | Translation model key | `claude-3-7-sonnet` |
71
- | `batchThreshold` | Maximum number of characters to accumulate before triggering batch processing | `1000` |
71
+ | `batchThreshold` | Maximum number of characters to accumulate before triggering batch processing | `1500` |
72
72
  | `debounceTimeout` | Time in milliseconds to wait before processing translations | `500` |
73
+ | `freeze` | Freeze mode to prevent translations from being queued | `false` |
73
74
 
74
75
  ### BCP 47 Language Tags
75
76
 
package/index.js CHANGED
@@ -32,7 +32,7 @@ class GPTrans {
32
32
  return isLanguageAvailable(langCode);
33
33
  }
34
34
 
35
- constructor({ from = 'en-US', target = 'es-AR', model = 'claude-3-7-sonnet-20250219', batchThreshold = 1500, debounceTimeout = 500, promptFile = null, context = '' }) {
35
+ constructor({ from = 'en-US', target = 'es', model = 'claude-3-7-sonnet-20250219', batchThreshold = 1500, debounceTimeout = 500, promptFile = null, context = '', freeze = false }) {
36
36
 
37
37
  try {
38
38
  dotenv.config();
@@ -58,6 +58,7 @@ class GPTrans {
58
58
  this.modelKey = model;
59
59
  this.promptFile = promptFile ?? new URL('./prompt/translate.md', import.meta.url).pathname;
60
60
  this.context = context;
61
+ this.freeze = freeze;
61
62
  this.modelConfig = {
62
63
  options: {
63
64
  max_tokens: batchThreshold,
@@ -96,10 +97,16 @@ class GPTrans {
96
97
  const translation = this.dbTarget.get(contextHash, key);
97
98
 
98
99
  if (!translation) {
100
+
99
101
  if (!this.dbFrom.get(this.context, key)) {
100
102
  this.dbFrom.set(this.context, key, text);
101
103
  }
102
104
 
105
+ if (this.freeze) {
106
+ console.log(`Freeze mode: [${key}] ${text}`);
107
+ return text;
108
+ }
109
+
103
110
  // Skip translation if context is empty and languages are the same
104
111
  if (!this.context && this.replaceFrom.FROM_ISO === this.replaceTarget.TARGET_ISO) {
105
112
  return text;
@@ -227,6 +234,11 @@ class GPTrans {
227
234
 
228
235
  return this;
229
236
  }
237
+
238
+ setFreeze(freeze = true) {
239
+ this.freeze = freeze;
240
+ return this;
241
+ }
230
242
  }
231
243
 
232
244
  export default GPTrans;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "gptrans",
3
3
  "type": "module",
4
- "version": "1.5.0",
4
+ "version": "1.5.2",
5
5
  "description": "🚆 GPTrans - The smarter AI-powered way to translate.",
6
6
  "keywords": [
7
7
  "translate",