@ccgp/i18n-ai 0.1.1 → 0.1.2

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.
@@ -10,11 +10,23 @@ var translate = async ({ text, lang, targetLang, apiKey, model }) => {
10
10
  const openrouter = createOpenRouter({
11
11
  apiKey: token
12
12
  });
13
+ const system = `
14
+ You are a professional translator. Your main task is to translate text from "${lang}" to "${targetLang}".
15
+
16
+ IMPORTANT RULES:
17
+ 1. Return ONLY the translated text. No explanations, no quotes around the output.
18
+ 2. Do NOT translate text inside curly braces, e.g., "{name}", "{count}". These are variables and must remain exactly as they are.
19
+ 3. Maintain the original tone and context.
20
+ 4. If the text is a single word or short phrase, translate it directly.
21
+
22
+ Examples:
23
+ - Input: "Hello {name}, welcome back!" -> Output (ES): "Hola {name}, \xA1bienvenido de nuevo!"
24
+ - Input: "Contact us calling to {number}" -> Output (FR): "Contactez-nous en appelant le {number}"
25
+ `;
13
26
  const { output } = await generateText({
14
27
  model: openrouter.languageModel(model || "google/gemini-2.5-flash"),
15
- prompt: `Translate the following text from ${lang} to ${targetLang}. Return ONLY the translated text, no explanations or additional text.
16
-
17
- Text to translate: ${text}`,
28
+ system,
29
+ prompt: `Text to translate: "${text}"`,
18
30
  output: Output.object({
19
31
  schema: z.object({
20
32
  translatedText: z.string()
package/dist/cli.js CHANGED
@@ -44,11 +44,23 @@ var translate = async ({ text, lang, targetLang, apiKey, model }) => {
44
44
  const openrouter = (0, import_ai_sdk_provider.createOpenRouter)({
45
45
  apiKey: token
46
46
  });
47
+ const system = `
48
+ You are a professional translator. Your main task is to translate text from "${lang}" to "${targetLang}".
49
+
50
+ IMPORTANT RULES:
51
+ 1. Return ONLY the translated text. No explanations, no quotes around the output.
52
+ 2. Do NOT translate text inside curly braces, e.g., "{name}", "{count}". These are variables and must remain exactly as they are.
53
+ 3. Maintain the original tone and context.
54
+ 4. If the text is a single word or short phrase, translate it directly.
55
+
56
+ Examples:
57
+ - Input: "Hello {name}, welcome back!" -> Output (ES): "Hola {name}, \xA1bienvenido de nuevo!"
58
+ - Input: "Contact us calling to {number}" -> Output (FR): "Contactez-nous en appelant le {number}"
59
+ `;
47
60
  const { output } = await (0, import_ai.generateText)({
48
61
  model: openrouter.languageModel(model || "google/gemini-2.5-flash"),
49
- prompt: `Translate the following text from ${lang} to ${targetLang}. Return ONLY the translated text, no explanations or additional text.
50
-
51
- Text to translate: ${text}`,
62
+ system,
63
+ prompt: `Text to translate: "${text}"`,
52
64
  output: import_ai.Output.object({
53
65
  schema: import_zod.default.object({
54
66
  translatedText: import_zod.default.string()
package/dist/cli.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  TranslationService
4
- } from "./chunk-X4OG3I7N.mjs";
4
+ } from "./chunk-KVP2GFHU.mjs";
5
5
 
6
6
  // src/cli.ts
7
7
  import { Command } from "commander";
package/dist/index.js CHANGED
@@ -146,11 +146,23 @@ var translate = async ({ text, lang, targetLang, apiKey, model }) => {
146
146
  const openrouter = (0, import_ai_sdk_provider.createOpenRouter)({
147
147
  apiKey: token
148
148
  });
149
+ const system = `
150
+ You are a professional translator. Your main task is to translate text from "${lang}" to "${targetLang}".
151
+
152
+ IMPORTANT RULES:
153
+ 1. Return ONLY the translated text. No explanations, no quotes around the output.
154
+ 2. Do NOT translate text inside curly braces, e.g., "{name}", "{count}". These are variables and must remain exactly as they are.
155
+ 3. Maintain the original tone and context.
156
+ 4. If the text is a single word or short phrase, translate it directly.
157
+
158
+ Examples:
159
+ - Input: "Hello {name}, welcome back!" -> Output (ES): "Hola {name}, \xA1bienvenido de nuevo!"
160
+ - Input: "Contact us calling to {number}" -> Output (FR): "Contactez-nous en appelant le {number}"
161
+ `;
149
162
  const { output } = await (0, import_ai.generateText)({
150
163
  model: openrouter.languageModel(model || "google/gemini-2.5-flash"),
151
- prompt: `Translate the following text from ${lang} to ${targetLang}. Return ONLY the translated text, no explanations or additional text.
152
-
153
- Text to translate: ${text}`,
164
+ system,
165
+ prompt: `Text to translate: "${text}"`,
154
166
  output: import_ai.Output.object({
155
167
  schema: import_zod.default.object({
156
168
  translatedText: import_zod.default.string()
package/dist/index.mjs CHANGED
@@ -10,7 +10,7 @@ import {
10
10
  translate,
11
11
  unflattenObject,
12
12
  updateLockEntry
13
- } from "./chunk-X4OG3I7N.mjs";
13
+ } from "./chunk-KVP2GFHU.mjs";
14
14
  export {
15
15
  TranslationService,
16
16
  analyzeChanges,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ccgp/i18n-ai",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "AI-powered i18n translation and synchronization library",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",