gptrans 1.2.2 → 1.2.6
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/prompt/translate.md +1 -0
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
|
}
|
package/package.json
CHANGED
package/prompt/translate.md
CHANGED
|
@@ -14,6 +14,7 @@ INPUT
|
|
|
14
14
|
- **Wordplay and humor:** When it's impossible to directly translate wordplay, find a resource that recreates the playful effect.
|
|
15
15
|
- **Idioms:** Do not introduce new idioms or expressions that are not present in the original text.
|
|
16
16
|
- **Variables:** Do not translate content between curly braces {variable}. These are system variables and must remain exactly the same.
|
|
17
|
+
- **Proper names:** Do not translate proper names (people, places, brands, etc.) unless they have an officially recognized translation in the target language.
|
|
17
18
|
|
|
18
19
|
# Context
|
|
19
20
|
CONTEXT
|