@awsless/i18n 0.0.3 → 0.0.5
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 +2 -4
- package/dist/index.cjs +10 -8
- package/dist/index.d.cts +8 -2
- package/dist/index.d.ts +8 -2
- package/dist/index.js +10 -8
- package/package.json +9 -1
package/README.MD
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
# AI-generated internationalization made easy
|
|
2
2
|
|
|
3
|
-
The
|
|
3
|
+
The `@awsless/i18n` package is a Vite plugin that automatically translates your text in build time using AI or any other tool you prefer. The plugin will inline the translations so you don't have to worry about loading the translations at the right time.
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
7
|
- Automatic text translation
|
|
8
8
|
- Inlines translations
|
|
9
|
-
- Extremely lightweight (373 bytes uncompressed)
|
|
9
|
+
- Extremely lightweight (373 bytes uncompressed 🔥)
|
|
10
10
|
- Svelte support
|
|
11
11
|
|
|
12
|
-
_A simple wrapper can be made for any framework._
|
|
13
|
-
|
|
14
12
|
## Setup
|
|
15
13
|
|
|
16
14
|
Install with (NPM):
|
package/dist/index.cjs
CHANGED
|
@@ -221,7 +221,6 @@ var createI18nPlugin = (props) => {
|
|
|
221
221
|
transform(code) {
|
|
222
222
|
let replaced = false;
|
|
223
223
|
if (code.includes(`$t\``)) {
|
|
224
|
-
console.log(cache);
|
|
225
224
|
for (const item of cache.entries()) {
|
|
226
225
|
code = code.replaceAll(`$t\`${item.original}\``, () => {
|
|
227
226
|
replaced = true;
|
|
@@ -270,10 +269,8 @@ var chatgpt = (props) => {
|
|
|
270
269
|
return async (originalLocale, list) => {
|
|
271
270
|
const client = new import_openai.default(props);
|
|
272
271
|
const response = await client.chat.completions.create({
|
|
273
|
-
model: "gpt-4o-2024-08-06",
|
|
274
|
-
max_tokens: 4095,
|
|
275
|
-
n: 1,
|
|
276
|
-
temperature: 1,
|
|
272
|
+
model: props?.model ?? "gpt-4o-2024-08-06",
|
|
273
|
+
max_tokens: props?.maxTokens ?? 4095,
|
|
277
274
|
response_format: format,
|
|
278
275
|
messages: [
|
|
279
276
|
{ role: "system", content: "You are a helpful translator." },
|
|
@@ -281,15 +278,20 @@ var chatgpt = (props) => {
|
|
|
281
278
|
]
|
|
282
279
|
});
|
|
283
280
|
const json = response.choices[0]?.message.content;
|
|
284
|
-
if (
|
|
281
|
+
if (typeof json !== "string") {
|
|
285
282
|
throw new Error("Invalid chat gpt response");
|
|
286
283
|
}
|
|
287
|
-
|
|
284
|
+
let data;
|
|
285
|
+
try {
|
|
286
|
+
data = JSON.parse(json);
|
|
287
|
+
} catch (error) {
|
|
288
|
+
throw new Error(`Invalid chat gpt json response: ${json}`);
|
|
289
|
+
}
|
|
288
290
|
return data.translations;
|
|
289
291
|
};
|
|
290
292
|
};
|
|
291
293
|
var prompt = (originalLocale, list, rules) => {
|
|
292
|
-
return `You have to translate the text inside the JSON file below from ${originalLocale} to the provided locale.
|
|
294
|
+
return `You have to translate the text inside the JSON file below from "${originalLocale}" to the provided locale.
|
|
293
295
|
${rules?.join("\n") ?? ""}
|
|
294
296
|
|
|
295
297
|
JSON FILE:
|
package/dist/index.d.cts
CHANGED
|
@@ -23,9 +23,15 @@ type I18nPluginProps = {
|
|
|
23
23
|
};
|
|
24
24
|
declare const createI18nPlugin: (props: I18nPluginProps) => Plugin[];
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
type ChatgptProps = ClientOptions & {
|
|
27
|
+
/** The maximum number of tokens that can be generated in the chat completion. */
|
|
28
|
+
maxTokens?: number;
|
|
29
|
+
/** ID of the model to use. */
|
|
30
|
+
model?: string;
|
|
31
|
+
/** The rules that chatgpt should follow. It will be added to the prompt. */
|
|
27
32
|
rules?: string[];
|
|
28
|
-
}
|
|
33
|
+
};
|
|
34
|
+
declare const chatgpt: (props?: ChatgptProps) => Translator;
|
|
29
35
|
|
|
30
36
|
declare const mock: (translation?: string) => Translator;
|
|
31
37
|
|
package/dist/index.d.ts
CHANGED
|
@@ -23,9 +23,15 @@ type I18nPluginProps = {
|
|
|
23
23
|
};
|
|
24
24
|
declare const createI18nPlugin: (props: I18nPluginProps) => Plugin[];
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
type ChatgptProps = ClientOptions & {
|
|
27
|
+
/** The maximum number of tokens that can be generated in the chat completion. */
|
|
28
|
+
maxTokens?: number;
|
|
29
|
+
/** ID of the model to use. */
|
|
30
|
+
model?: string;
|
|
31
|
+
/** The rules that chatgpt should follow. It will be added to the prompt. */
|
|
27
32
|
rules?: string[];
|
|
28
|
-
}
|
|
33
|
+
};
|
|
34
|
+
declare const chatgpt: (props?: ChatgptProps) => Translator;
|
|
29
35
|
|
|
30
36
|
declare const mock: (translation?: string) => Translator;
|
|
31
37
|
|
package/dist/index.js
CHANGED
|
@@ -183,7 +183,6 @@ var createI18nPlugin = (props) => {
|
|
|
183
183
|
transform(code) {
|
|
184
184
|
let replaced = false;
|
|
185
185
|
if (code.includes(`$t\``)) {
|
|
186
|
-
console.log(cache);
|
|
187
186
|
for (const item of cache.entries()) {
|
|
188
187
|
code = code.replaceAll(`$t\`${item.original}\``, () => {
|
|
189
188
|
replaced = true;
|
|
@@ -232,10 +231,8 @@ var chatgpt = (props) => {
|
|
|
232
231
|
return async (originalLocale, list) => {
|
|
233
232
|
const client = new OpenAI(props);
|
|
234
233
|
const response = await client.chat.completions.create({
|
|
235
|
-
model: "gpt-4o-2024-08-06",
|
|
236
|
-
max_tokens: 4095,
|
|
237
|
-
n: 1,
|
|
238
|
-
temperature: 1,
|
|
234
|
+
model: props?.model ?? "gpt-4o-2024-08-06",
|
|
235
|
+
max_tokens: props?.maxTokens ?? 4095,
|
|
239
236
|
response_format: format,
|
|
240
237
|
messages: [
|
|
241
238
|
{ role: "system", content: "You are a helpful translator." },
|
|
@@ -243,15 +240,20 @@ var chatgpt = (props) => {
|
|
|
243
240
|
]
|
|
244
241
|
});
|
|
245
242
|
const json = response.choices[0]?.message.content;
|
|
246
|
-
if (
|
|
243
|
+
if (typeof json !== "string") {
|
|
247
244
|
throw new Error("Invalid chat gpt response");
|
|
248
245
|
}
|
|
249
|
-
|
|
246
|
+
let data;
|
|
247
|
+
try {
|
|
248
|
+
data = JSON.parse(json);
|
|
249
|
+
} catch (error) {
|
|
250
|
+
throw new Error(`Invalid chat gpt json response: ${json}`);
|
|
251
|
+
}
|
|
250
252
|
return data.translations;
|
|
251
253
|
};
|
|
252
254
|
};
|
|
253
255
|
var prompt = (originalLocale, list, rules) => {
|
|
254
|
-
return `You have to translate the text inside the JSON file below from ${originalLocale} to the provided locale.
|
|
256
|
+
return `You have to translate the text inside the JSON file below from "${originalLocale}" to the provided locale.
|
|
255
257
|
${rules?.join("\n") ?? ""}
|
|
256
258
|
|
|
257
259
|
JSON FILE:
|
package/package.json
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@awsless/i18n",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"vite",
|
|
8
|
+
"plugin",
|
|
9
|
+
"internationalization",
|
|
10
|
+
"i18n",
|
|
11
|
+
"svelte",
|
|
12
|
+
"sveltekit"
|
|
13
|
+
],
|
|
6
14
|
"repository": {
|
|
7
15
|
"type": "git",
|
|
8
16
|
"url": "https://github.com/awsless/awsless.git"
|