vite-plugin-localization-ai 1.0.11 → 1.0.13

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.d.ts CHANGED
@@ -1,6 +1,11 @@
1
+ type LocalizationLocale = {
2
+ locale: string;
3
+ fileName: string;
4
+ promt: string;
5
+ };
1
6
  interface LocalizationAIOptions {
2
7
  source: string;
3
- targets: string[];
8
+ targets: LocalizationLocale[];
4
9
  outputDir?: string;
5
10
  apiKey?: string;
6
11
  extraPromt?: string;
package/dist/index.js CHANGED
@@ -11,9 +11,9 @@ export default function localizationAI(options) {
11
11
  console.log("[localization-ai] starting localization...");
12
12
  const sourceContent = parseJsonc(fs.readFileSync(source, "utf-8"));
13
13
  for (const lang of targets) {
14
- console.log(`[localization-ai] Translating to ${lang}...`);
15
- const translated = await translate(sourceContent, lang, apiKey, extraPromt, temperature, seed);
16
- const outputPath = path.join(outputDir, `${lang}.json`);
14
+ console.log(`[localization-ai] Translating to ${lang.locale}...`);
15
+ const translated = await translate(sourceContent, lang.locale, lang.promt, apiKey, extraPromt, temperature, seed);
16
+ const outputPath = path.join(outputDir, lang.fileName);
17
17
  fs.writeFileSync(outputPath, JSON.stringify(translated, null, 2), "utf-8");
18
18
  console.log(`[localization-ai] ${lang}.json saved!`);
19
19
  }
@@ -1 +1 @@
1
- export declare function translate(sourceJson: Record<string, any>, targetLang: string, apiKey?: string, extraPromt?: string, temperature?: number, seed?: number): Promise<any>;
1
+ export declare function translate(sourceJson: Record<string, any>, targetLocale: string, targetPromt: string, apiKey?: string, extraPromt?: string, temperature?: number, seed?: number): Promise<any>;
@@ -1,5 +1,5 @@
1
1
  import { GoogleGenAI } from "@google/genai";
2
- export async function translate(sourceJson, targetLang, apiKey, extraPromt, temperature, seed) {
2
+ export async function translate(sourceJson, targetLocale, targetPromt, apiKey, extraPromt, temperature, seed) {
3
3
  const client = new GoogleGenAI({
4
4
  apiKey: apiKey,
5
5
  });
@@ -7,14 +7,14 @@ export async function translate(sourceJson, targetLang, apiKey, extraPromt, temp
7
7
  const generateParams = {
8
8
  model: "gemini-2.5-flash",
9
9
  contents: `You are a professional application interface translator.
10
- Translate the JSON to culture (locale) "${targetLang}".
10
+ Translate the JSON into ${targetPromt} (ISO locale: ${targetLocale}).
11
11
  JSON:
12
12
  ${text}
13
13
 
14
14
  ${extraPromt || ""}
15
15
  `,
16
16
  config: {
17
- systemInstruction: "Translate JSON values exactly, keep keys and structure. The response must be plain text — no Markdown",
17
+ systemInstruction: "Translate according to locale codes (ISO 639/3166). Use language code and region code from locale! Translate JSON values exactly, keep keys and structure. The response must be plain text — no Markdown",
18
18
  temperature: temperature,
19
19
  seed: seed,
20
20
  responseMimeType: "application/json",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-localization-ai",
3
- "version": "1.0.11",
3
+ "version": "1.0.13",
4
4
  "description": "Vite plugin to generate localization jsons using AI",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
package/src/index.ts CHANGED
@@ -3,9 +3,15 @@ import path from "path";
3
3
  import { parse as parseJsonc } from "jsonc-parser";
4
4
  import { translate } from "./providers/gemini.js";
5
5
 
6
+ type LocalizationLocale = {
7
+ locale: string;
8
+ fileName: string;
9
+ promt: string;
10
+ };
11
+
6
12
  interface LocalizationAIOptions {
7
13
  source: string;
8
- targets: string[];
14
+ targets: LocalizationLocale[];
9
15
  outputDir?: string;
10
16
  apiKey?: string;
11
17
  extraPromt?: string;
@@ -33,17 +39,18 @@ export default function localizationAI(options: LocalizationAIOptions) {
33
39
  const sourceContent = parseJsonc(fs.readFileSync(source, "utf-8"));
34
40
 
35
41
  for (const lang of targets) {
36
- console.log(`[localization-ai] Translating to ${lang}...`);
42
+ console.log(`[localization-ai] Translating to ${lang.locale}...`);
37
43
  const translated = await translate(
38
44
  sourceContent,
39
- lang,
45
+ lang.locale,
46
+ lang.promt,
40
47
  apiKey,
41
48
  extraPromt,
42
49
  temperature,
43
50
  seed
44
51
  );
45
52
 
46
- const outputPath = path.join(outputDir, `${lang}.json`);
53
+ const outputPath = path.join(outputDir, lang.fileName);
47
54
  fs.writeFileSync(
48
55
  outputPath,
49
56
  JSON.stringify(translated, null, 2),
@@ -2,7 +2,8 @@ import { GenerateContentParameters, GoogleGenAI } from "@google/genai";
2
2
 
3
3
  export async function translate(
4
4
  sourceJson: Record<string, any>,
5
- targetLang: string,
5
+ targetLocale: string,
6
+ targetPromt: string,
6
7
  apiKey?: string,
7
8
  extraPromt?: string,
8
9
  temperature?: number,
@@ -16,7 +17,7 @@ export async function translate(
16
17
  const generateParams: GenerateContentParameters = {
17
18
  model: "gemini-2.5-flash",
18
19
  contents: `You are a professional application interface translator.
19
- Translate the JSON to culture (locale) "${targetLang}".
20
+ Translate the JSON into ${targetPromt} (ISO locale: ${targetLocale}).
20
21
  JSON:
21
22
  ${text}
22
23
 
@@ -24,7 +25,7 @@ ${extraPromt || ""}
24
25
  `,
25
26
  config: {
26
27
  systemInstruction:
27
- "Translate JSON values exactly, keep keys and structure. The response must be plain text — no Markdown",
28
+ "Translate according to locale codes (ISO 639/3166). Use language code and region code from locale! Translate JSON values exactly, keep keys and structure. The response must be plain text — no Markdown",
28
29
  temperature: temperature,
29
30
  seed: seed,
30
31
  responseMimeType: "application/json",