@awsless/i18n 0.0.4 → 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 -7
- package/dist/index.d.cts +8 -2
- package/dist/index.d.ts +8 -2
- package/dist/index.js +10 -7
- 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
|
@@ -269,10 +269,8 @@ var chatgpt = (props) => {
|
|
|
269
269
|
return async (originalLocale, list) => {
|
|
270
270
|
const client = new import_openai.default(props);
|
|
271
271
|
const response = await client.chat.completions.create({
|
|
272
|
-
model: "gpt-4o-2024-08-06",
|
|
273
|
-
max_tokens: 4095,
|
|
274
|
-
n: 1,
|
|
275
|
-
temperature: 1,
|
|
272
|
+
model: props?.model ?? "gpt-4o-2024-08-06",
|
|
273
|
+
max_tokens: props?.maxTokens ?? 4095,
|
|
276
274
|
response_format: format,
|
|
277
275
|
messages: [
|
|
278
276
|
{ role: "system", content: "You are a helpful translator." },
|
|
@@ -280,15 +278,20 @@ var chatgpt = (props) => {
|
|
|
280
278
|
]
|
|
281
279
|
});
|
|
282
280
|
const json = response.choices[0]?.message.content;
|
|
283
|
-
if (
|
|
281
|
+
if (typeof json !== "string") {
|
|
284
282
|
throw new Error("Invalid chat gpt response");
|
|
285
283
|
}
|
|
286
|
-
|
|
284
|
+
let data;
|
|
285
|
+
try {
|
|
286
|
+
data = JSON.parse(json);
|
|
287
|
+
} catch (error) {
|
|
288
|
+
throw new Error(`Invalid chat gpt json response: ${json}`);
|
|
289
|
+
}
|
|
287
290
|
return data.translations;
|
|
288
291
|
};
|
|
289
292
|
};
|
|
290
293
|
var prompt = (originalLocale, list, rules) => {
|
|
291
|
-
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.
|
|
292
295
|
${rules?.join("\n") ?? ""}
|
|
293
296
|
|
|
294
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
|
@@ -231,10 +231,8 @@ var chatgpt = (props) => {
|
|
|
231
231
|
return async (originalLocale, list) => {
|
|
232
232
|
const client = new OpenAI(props);
|
|
233
233
|
const response = await client.chat.completions.create({
|
|
234
|
-
model: "gpt-4o-2024-08-06",
|
|
235
|
-
max_tokens: 4095,
|
|
236
|
-
n: 1,
|
|
237
|
-
temperature: 1,
|
|
234
|
+
model: props?.model ?? "gpt-4o-2024-08-06",
|
|
235
|
+
max_tokens: props?.maxTokens ?? 4095,
|
|
238
236
|
response_format: format,
|
|
239
237
|
messages: [
|
|
240
238
|
{ role: "system", content: "You are a helpful translator." },
|
|
@@ -242,15 +240,20 @@ var chatgpt = (props) => {
|
|
|
242
240
|
]
|
|
243
241
|
});
|
|
244
242
|
const json = response.choices[0]?.message.content;
|
|
245
|
-
if (
|
|
243
|
+
if (typeof json !== "string") {
|
|
246
244
|
throw new Error("Invalid chat gpt response");
|
|
247
245
|
}
|
|
248
|
-
|
|
246
|
+
let data;
|
|
247
|
+
try {
|
|
248
|
+
data = JSON.parse(json);
|
|
249
|
+
} catch (error) {
|
|
250
|
+
throw new Error(`Invalid chat gpt json response: ${json}`);
|
|
251
|
+
}
|
|
249
252
|
return data.translations;
|
|
250
253
|
};
|
|
251
254
|
};
|
|
252
255
|
var prompt = (originalLocale, list, rules) => {
|
|
253
|
-
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.
|
|
254
257
|
${rules?.join("\n") ?? ""}
|
|
255
258
|
|
|
256
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"
|