solid-translate 1.4.2 → 1.4.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "solid-translate",
3
- "version": "1.4.2",
3
+ "version": "1.4.4",
4
4
  "description": "AI-powered build-time translations for SolidJS. Full i18n with <T>, <Var>, <Num>, <Currency>, <Plural>, <DateTime>, locale detection, and a CLI — all BYOK.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -1,82 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- // src/translate.ts
4
- import { z } from "zod";
5
- async function loadGenerateObject() {
6
- const { generateObject } = await import("ai");
7
- return generateObject;
8
- }
9
- async function translateBatch(model, entries, targetLocale, sourceLocale, systemPrompt, contexts) {
10
- const keys = Object.keys(entries);
11
- if (keys.length === 0) return {};
12
- const defaultSystem = [
13
- `You are a professional translator specializing in software localization.`,
14
- `Translate text from "${sourceLocale}" to "${targetLocale}".`,
15
- `Rules:`,
16
- `- Preserve the original tone and meaning`,
17
- `- Keep placeholders like {{variable}}, {variable}, {0}, {1} unchanged`,
18
- `- Keep HTML tags unchanged`,
19
- `- Do not add or remove content`,
20
- `- Return natural, idiomatic translations`
21
- ].join("\n");
22
- let contextSection = "";
23
- if (contexts && Object.keys(contexts).length > 0) {
24
- const contextLines = Object.entries(contexts).filter(([key]) => key in entries).map(([key, ctx]) => ` "${key}": ${ctx}`);
25
- if (contextLines.length > 0) {
26
- contextSection = [
27
- ``,
28
- `Context hints for disambiguation:`,
29
- ...contextLines,
30
- ``
31
- ].join("\n");
32
- }
33
- }
34
- const generateObject = await loadGenerateObject();
35
- const { object } = await generateObject({
36
- model,
37
- schema: z.object({
38
- translations: z.record(z.string(), z.string())
39
- }),
40
- system: systemPrompt || defaultSystem,
41
- prompt: [
42
- `Translate each value in this JSON object from "${sourceLocale}" to "${targetLocale}".`,
43
- `Return a JSON object with the exact same keys and the translated values.`,
44
- contextSection,
45
- JSON.stringify(entries, null, 2)
46
- ].join("\n")
47
- });
48
- return object.translations;
49
- }
50
- async function translateMarkdown(model, content, targetLocale, sourceLocale, systemPrompt) {
51
- const defaultSystem = [
52
- `You are a professional translator specializing in documentation.`,
53
- `Translate Markdown/MDX content from "${sourceLocale}" to "${targetLocale}".`,
54
- `Rules:`,
55
- `- Preserve all Markdown formatting (headers, lists, bold, italic, links, etc.)`,
56
- `- Preserve code blocks and inline code unchanged`,
57
- `- Preserve frontmatter YAML keys (only translate values)`,
58
- `- Preserve MDX component syntax and JSX expressions`,
59
- `- Preserve URLs and file paths unchanged`,
60
- `- Return natural, idiomatic translations`
61
- ].join("\n");
62
- const generateObject = await loadGenerateObject();
63
- const { object } = await generateObject({
64
- model,
65
- schema: z.object({
66
- translated: z.string()
67
- }),
68
- system: systemPrompt || defaultSystem,
69
- prompt: [
70
- `Translate this Markdown/MDX content from "${sourceLocale}" to "${targetLocale}".`,
71
- `Return the complete translated document.`,
72
- ``,
73
- content
74
- ].join("\n")
75
- });
76
- return object.translated;
77
- }
78
-
79
- export {
80
- translateBatch,
81
- translateMarkdown
82
- };