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 +8 -0
- package/db/gptrans_it.json +0 -10
- package/demo/case_2.js +0 -1
- package/index.js +9 -5
- package/package.json +1 -1
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.
|
package/db/gptrans_it.json
CHANGED
|
@@ -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
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
|
-
|
|
121
|
+
try {
|
|
122
|
+
const translations = await this._translate(textsToTranslate);
|
|
123
|
+
const translatedTexts = translations.split('\n---\n');
|
|
122
124
|
|
|
123
|
-
|
|
125
|
+
batch.forEach(([key], index) => {
|
|
126
|
+
this.dbTarget.set(key, translatedTexts[index].trim());
|
|
127
|
+
});
|
|
124
128
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}
|
|
129
|
+
} catch (e) {
|
|
130
|
+
console.error(e);
|
|
131
|
+
}
|
|
128
132
|
|
|
129
133
|
this.processing = false;
|
|
130
134
|
}
|