gptrans 1.2.2 → 1.2.4

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
@@ -102,6 +102,14 @@ GPTrans stands out by combining advanced AI capabilities with efficient batching
102
102
 
103
103
  If you're looking to streamline your translation workflow and bring your applications to a global audience effortlessly, GPTrans is the perfect choice!
104
104
 
105
+ ## 🔄 Preloading Translations
106
+
107
+ You can preload translations for specific languages using the `preload` method. This is particularly useful when you want to initialize translations based on dynamically generated keys:
108
+
109
+ ```javascript
110
+ await gptrans.preload({target:'ar'});
111
+ ```
112
+
105
113
  ## Contributing
106
114
 
107
115
  Contributions are welcome! Please open an issue or submit a pull request on GitHub to contribute improvements or fixes.
@@ -1,10 +0,0 @@
1
- {
2
- "hello_name_1987p1n": "Ciao, {name}!",
3
- "topup_uzdh5y": "Ricarica",
4
- "transf_176pc1a": "Trasferimento",
5
- "deposi_wg2ec5": "Deposito",
6
- "balanc_1rv8if7": "Saldo",
7
- "transa_1wtqm5d": "Transazione",
8
- "accoun_x1y0v8": "Conto",
9
- "card_yis1ox": "Carta"
10
- }
package/demo/case_2.js CHANGED
@@ -3,7 +3,6 @@ import GPTrans from '../index.js';
3
3
  try {
4
4
  const gptrans = new GPTrans({
5
5
  target: 'it',
6
- model: 'gpt-4o-mini',
7
6
  });
8
7
 
9
8
  await gptrans.preload();
package/index.js CHANGED
@@ -118,13 +118,17 @@ class GPTrans {
118
118
  this.pendingCharCount = 0;
119
119
 
120
120
  const textsToTranslate = batch.map(([_, text]) => text).join('\n---\n');
121
- const translations = await this._translate(textsToTranslate);
121
+ try {
122
+ const translations = await this._translate(textsToTranslate);
123
+ const translatedTexts = translations.split('\n---\n');
122
124
 
123
- const translatedTexts = translations.split('\n---\n');
125
+ batch.forEach(([key], index) => {
126
+ this.dbTarget.set(key, translatedTexts[index].trim());
127
+ });
124
128
 
125
- batch.forEach(([key], index) => {
126
- this.dbTarget.set(key, translatedTexts[index].trim());
127
- });
129
+ } catch (e) {
130
+ console.error(e);
131
+ }
128
132
 
129
133
  this.processing = false;
130
134
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "gptrans",
3
3
  "type": "module",
4
- "version": "1.2.2",
4
+ "version": "1.2.4",
5
5
  "description": "🚆 GPTrans - The smarter AI-powered way to translate.",
6
6
  "keywords": [
7
7
  "translate",