vite-plugin-localization-ai 1.0.15 → 1.1.0
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/dist/index.js +4 -1
- package/dist/providers/gemini.d.ts +1 -1
- package/dist/providers/gemini.js +6 -3
- package/package.json +3 -6
- package/src/index.ts +7 -3
- package/src/providers/gemini.ts +7 -3
package/dist/index.js
CHANGED
|
@@ -12,8 +12,11 @@ export default function localizationAI(options) {
|
|
|
12
12
|
const sourceContent = parseJsonc(fs.readFileSync(source, "utf-8"));
|
|
13
13
|
for (const lang of targets) {
|
|
14
14
|
console.log(`[localization-ai] Translating to ${lang.locale}...`);
|
|
15
|
-
const translated = await translate(sourceContent, lang.locale, lang.promt, apiKey, extraPromt, temperature, seed);
|
|
16
15
|
const outputPath = path.join(outputDir, lang.fileName);
|
|
16
|
+
const targetContent = fs.existsSync(outputPath)
|
|
17
|
+
? parseJsonc(fs.readFileSync(outputPath, "utf-8"))
|
|
18
|
+
: null;
|
|
19
|
+
const translated = await translate(targetContent, sourceContent, lang.locale, lang.promt, apiKey, extraPromt, temperature, seed);
|
|
17
20
|
fs.writeFileSync(outputPath, JSON.stringify(translated, null, 2), "utf-8");
|
|
18
21
|
console.log(`[localization-ai] ${lang.fileName} saved!`);
|
|
19
22
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function translate(sourceJson: Record<string, any>, targetLocale: string, targetPromt: string, apiKey?: string, extraPromt?: string, temperature?: number, seed?: number): Promise<any>;
|
|
1
|
+
export declare function translate(targetJson: Record<string, any> | null, sourceJson: Record<string, any>, targetLocale: string, targetPromt: string, apiKey?: string, extraPromt?: string, temperature?: number, seed?: number): Promise<any>;
|
package/dist/providers/gemini.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { GoogleGenAI } from "@google/genai";
|
|
2
|
-
export async function translate(sourceJson, targetLocale, targetPromt, apiKey, extraPromt, temperature, seed) {
|
|
2
|
+
export async function translate(targetJson, sourceJson, targetLocale, targetPromt, apiKey, extraPromt, temperature, seed) {
|
|
3
3
|
const client = new GoogleGenAI({
|
|
4
4
|
apiKey: apiKey,
|
|
5
5
|
});
|
|
6
|
+
const existedLocalization = targetJson
|
|
7
|
+
? JSON.stringify(targetJson, null, 2)
|
|
8
|
+
: null;
|
|
6
9
|
const text = JSON.stringify(sourceJson, null, 2);
|
|
7
10
|
const config = {
|
|
8
11
|
thinkingConfig: {
|
|
@@ -23,11 +26,11 @@ export async function translate(sourceJson, targetLocale, targetPromt, apiKey, e
|
|
|
23
26
|
role: "user",
|
|
24
27
|
parts: [
|
|
25
28
|
{
|
|
26
|
-
text: `You are a professional application interface translator.
|
|
29
|
+
text: `You are a professional application interface translator. Do not change order of JSON and do not localize keys of JSON.
|
|
27
30
|
Translate the JSON into ${targetPromt} (ISO locale: ${targetLocale}).
|
|
28
31
|
JSON:
|
|
29
32
|
${text}
|
|
30
|
-
|
|
33
|
+
${existedLocalization ? `\nThere is already localized JSON. Be consider to use the same terms and localize only added or modified parts. Do not touch non-modified.\n Already localized JSON: ${existedLocalization}` : ""}
|
|
31
34
|
${extraPromt || ""}
|
|
32
35
|
`,
|
|
33
36
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-localization-ai",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Vite plugin to generate localization jsons using AI",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -17,13 +17,10 @@
|
|
|
17
17
|
"license": "MIT",
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@types/node": "22.14.1",
|
|
20
|
-
"@google/genai": "1.
|
|
20
|
+
"@google/genai": "1.34.0",
|
|
21
21
|
"jsonc-parser": "3.3.1",
|
|
22
22
|
"typescript": "5.9.3",
|
|
23
|
-
"vite": "7.
|
|
24
|
-
},
|
|
25
|
-
"devDependencies": {
|
|
26
|
-
"vitest": "3.2.4"
|
|
23
|
+
"vite": "7.3.0"
|
|
27
24
|
},
|
|
28
25
|
"keywords": [
|
|
29
26
|
"vite",
|
package/src/index.ts
CHANGED
|
@@ -40,21 +40,25 @@ export default function localizationAI(options: LocalizationAIOptions) {
|
|
|
40
40
|
|
|
41
41
|
for (const lang of targets) {
|
|
42
42
|
console.log(`[localization-ai] Translating to ${lang.locale}...`);
|
|
43
|
+
const outputPath = path.join(outputDir, lang.fileName);
|
|
44
|
+
const targetContent = fs.existsSync(outputPath)
|
|
45
|
+
? parseJsonc(fs.readFileSync(outputPath, "utf-8"))
|
|
46
|
+
: null;
|
|
43
47
|
const translated = await translate(
|
|
48
|
+
targetContent,
|
|
44
49
|
sourceContent,
|
|
45
50
|
lang.locale,
|
|
46
51
|
lang.promt,
|
|
47
52
|
apiKey,
|
|
48
53
|
extraPromt,
|
|
49
54
|
temperature,
|
|
50
|
-
seed
|
|
55
|
+
seed,
|
|
51
56
|
);
|
|
52
57
|
|
|
53
|
-
const outputPath = path.join(outputDir, lang.fileName);
|
|
54
58
|
fs.writeFileSync(
|
|
55
59
|
outputPath,
|
|
56
60
|
JSON.stringify(translated, null, 2),
|
|
57
|
-
"utf-8"
|
|
61
|
+
"utf-8",
|
|
58
62
|
);
|
|
59
63
|
console.log(`[localization-ai] ${lang.fileName} saved!`);
|
|
60
64
|
}
|
package/src/providers/gemini.ts
CHANGED
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
import { GoogleGenAI } from "@google/genai";
|
|
2
2
|
|
|
3
3
|
export async function translate(
|
|
4
|
+
targetJson: Record<string, any> | null,
|
|
4
5
|
sourceJson: Record<string, any>,
|
|
5
6
|
targetLocale: string,
|
|
6
7
|
targetPromt: string,
|
|
7
8
|
apiKey?: string,
|
|
8
9
|
extraPromt?: string,
|
|
9
10
|
temperature?: number,
|
|
10
|
-
seed?: number
|
|
11
|
+
seed?: number,
|
|
11
12
|
) {
|
|
12
13
|
const client = new GoogleGenAI({
|
|
13
14
|
apiKey: apiKey,
|
|
14
15
|
});
|
|
15
16
|
|
|
17
|
+
const existedLocalization = targetJson
|
|
18
|
+
? JSON.stringify(targetJson, null, 2)
|
|
19
|
+
: null;
|
|
16
20
|
const text = JSON.stringify(sourceJson, null, 2);
|
|
17
21
|
|
|
18
22
|
const config = {
|
|
@@ -34,11 +38,11 @@ export async function translate(
|
|
|
34
38
|
role: "user",
|
|
35
39
|
parts: [
|
|
36
40
|
{
|
|
37
|
-
text: `You are a professional application interface translator.
|
|
41
|
+
text: `You are a professional application interface translator. Do not change order of JSON and do not localize keys of JSON.
|
|
38
42
|
Translate the JSON into ${targetPromt} (ISO locale: ${targetLocale}).
|
|
39
43
|
JSON:
|
|
40
44
|
${text}
|
|
41
|
-
|
|
45
|
+
${existedLocalization ? `\nThere is already localized JSON. Be consider to use the same terms and localize only added or modified parts. Do not touch non-modified.\n Already localized JSON: ${existedLocalization}` : ""}
|
|
42
46
|
${extraPromt || ""}
|
|
43
47
|
`,
|
|
44
48
|
},
|