translate-kit 0.4.1 → 0.4.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.
- package/dist/cli.js +3015 -3221
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +80 -77
package/dist/index.d.ts
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/config.ts","../src/scanner/filters.ts"],"sourcesContent":["import { loadConfig } from \"c12\";\nimport { z } from \"zod\";\nimport
|
|
1
|
+
{"version":3,"sources":["../src/config.ts","../src/scanner/filters.ts"],"sourcesContent":["import { loadConfig } from \"c12\";\nimport { z } from \"zod\";\nimport { DEFAULT_TRANSLATABLE_PROPS } from \"./scanner/filters.js\";\nimport type { TranslateKitConfig } from \"./types.js\";\n\nconst configSchema = z\n\t.object({\n\t\tmodel: z.custom<TranslateKitConfig[\"model\"]>(\n\t\t\t(val) => val != null && typeof val === \"object\",\n\t\t\t{ message: \"model must be an AI SDK LanguageModel instance\" },\n\t\t),\n\t\tmode: z.enum([\"keys\", \"inline\"]).default(\"keys\"),\n\t\tsourceLocale: z.string().min(1),\n\t\ttargetLocales: z.array(z.string().min(1)).min(1),\n\t\tmessagesDir: z.string().min(1),\n\t\tsplitByNamespace: z.boolean().default(false).optional(),\n\t\ttypeSafe: z.boolean().default(false).optional(),\n\t\ttranslation: z\n\t\t\t.object({\n\t\t\t\tbatchSize: z.number().int().positive().default(50),\n\t\t\t\tcontext: z.string().optional(),\n\t\t\t\tglossary: z.record(z.string(), z.string()).optional(),\n\t\t\t\ttone: z.string().optional(),\n\t\t\t\tretries: z.number().int().min(0).default(2),\n\t\t\t\tconcurrency: z.number().int().positive().default(3),\n\t\t\t\tvalidatePlaceholders: z.boolean().default(true).optional(),\n\t\t\t})\n\t\t\t.optional(),\n\t\tscan: z\n\t\t\t.object({\n\t\t\t\tinclude: z.array(z.string()),\n\t\t\t\texclude: z.array(z.string()).optional(),\n\t\t\t\ttranslatableProps: z\n\t\t\t\t\t.array(z.string())\n\t\t\t\t\t.default([...DEFAULT_TRANSLATABLE_PROPS]),\n\t\t\t\ti18nImport: z.string().default(\"next-intl\"),\n\t\t\t})\n\t\t\t.optional(),\n\t\tinline: z\n\t\t\t.object({\n\t\t\t\tcomponentPath: z.string().min(1),\n\t\t\t})\n\t\t\t.optional(),\n\t})\n\t.refine((data) => data.mode !== \"inline\" || data.inline != null, {\n\t\tmessage: \"inline options are required when mode is 'inline'\",\n\t\tpath: [\"inline\"],\n\t});\n\nexport function defineConfig(config: TranslateKitConfig) {\n\treturn config as TranslateKitConfig;\n}\n\nexport async function loadTranslateKitConfig(): Promise<TranslateKitConfig> {\n\tconst { config } = await loadConfig({\n\t\tname: \"translate-kit\",\n\t});\n\n\tif (!config || Object.keys(config).length === 0) {\n\t\tthrow new Error(\n\t\t\t\"No config found. Create a translate-kit.config.ts file or run `translate-kit init`.\",\n\t\t);\n\t}\n\n\tconst result = configSchema.safeParse(config);\n\tif (!result.success) {\n\t\tconst errors = result.error.issues\n\t\t\t.map((i) => ` - ${i.path.join(\".\")}: ${i.message}`)\n\t\t\t.join(\"\\n\");\n\t\tthrow new Error(`Invalid config:\\n${errors}`);\n\t}\n\n\treturn result.data as TranslateKitConfig;\n}\n","export const DEFAULT_TRANSLATABLE_PROPS = [\n\t\"placeholder\",\n\t\"title\",\n\t\"alt\",\n\t\"aria-label\",\n\t\"aria-description\",\n\t\"aria-placeholder\",\n\t\"label\",\n];\n\nconst NEVER_TRANSLATE_PROPS = [\n\t\"className\",\n\t\"class\",\n\t\"id\",\n\t\"key\",\n\t\"ref\",\n\t\"href\",\n\t\"src\",\n\t\"type\",\n\t\"name\",\n\t\"value\",\n\t\"htmlFor\",\n\t\"for\",\n\t\"role\",\n\t\"style\",\n\t\"data-testid\",\n\t\"data-cy\",\n\t\"onClick\",\n\t\"onChange\",\n\t\"onSubmit\",\n\t\"onFocus\",\n\t\"onBlur\",\n];\n\nconst IGNORE_TAGS = [\n\t\"script\",\n\t\"style\",\n\t\"code\",\n\t\"pre\",\n\t\"svg\",\n\t\"path\",\n\t\"circle\",\n\t\"rect\",\n\t\"line\",\n\t\"polyline\",\n\t\"polygon\",\n];\n\nconst IGNORE_PATTERNS = [\n\t/^\\s*$/, // Whitespace only\n\t/^https?:\\/\\//, // URLs\n\t/^[\\d.,%$€£¥]+$/, // Numbers, currency\n\t/^[^\\p{L}]*$/u, // No letters at all (Unicode-aware)\n];\n\nfunction isLikelyKebabIdentifier(text: string): boolean {\n\t// Keep this conservative to avoid skipping real UI copy like \"sign-in\".\n\tif (!/^[a-z0-9]+(?:-[a-z0-9]+)+$/.test(text)) return false;\n\treturn text.split(\"-\").length >= 3;\n}\n\nfunction isLikelyConstantIdentifier(text: string): boolean {\n\t// Ignore env/constant-like tokens, but keep plain ALLCAPS words (API, OK).\n\treturn /^(?=.*[_\\d])[A-Z0-9_]+$/.test(text);\n}\n\nconst CONTENT_PROPERTY_NAMES = [\n\t\"title\",\n\t\"description\",\n\t\"label\",\n\t\"text\",\n\t\"content\",\n\t\"heading\",\n\t\"subtitle\",\n\t\"caption\",\n\t\"summary\",\n\t\"message\",\n\t\"placeholder\",\n\t\"alt\",\n];\n\nexport function isContentProperty(propName: string): boolean {\n\treturn CONTENT_PROPERTY_NAMES.includes(propName);\n}\n\nexport function isTranslatableProp(\n\tpropName: string,\n\tcustomProps?: string[],\n): boolean {\n\tif (NEVER_TRANSLATE_PROPS.includes(propName)) return false;\n\tconst allowed = customProps ?? DEFAULT_TRANSLATABLE_PROPS;\n\treturn allowed.includes(propName);\n}\n\nexport function isIgnoredTag(tagName: string): boolean {\n\treturn IGNORE_TAGS.includes(tagName.toLowerCase());\n}\n\nexport function shouldIgnore(text: string): boolean {\n\tconst trimmed = text.trim();\n\tif (trimmed.length === 0) return true;\n\tif (isLikelyKebabIdentifier(trimmed)) return true;\n\tif (isLikelyConstantIdentifier(trimmed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
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
2
|
+
"name": "translate-kit",
|
|
3
|
+
"version": "0.4.2",
|
|
4
|
+
"description": "AI-powered i18n pipeline for build time. Scan, transform, and translate JSX/TSX with any AI model. Zero runtime cost. Compatible with next-intl.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "guillermolg00",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/guillermolg00/translate-kit.git"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://translate-kit.com",
|
|
13
|
+
"bugs": "https://github.com/guillermolg00/translate-kit/issues",
|
|
14
|
+
"keywords": [
|
|
15
|
+
"translate",
|
|
16
|
+
"i18n",
|
|
17
|
+
"internationalization",
|
|
18
|
+
"next-intl",
|
|
19
|
+
"ai",
|
|
20
|
+
"translation",
|
|
21
|
+
"build-time",
|
|
22
|
+
"vercel-ai-sdk",
|
|
23
|
+
"localization",
|
|
24
|
+
"nextjs",
|
|
25
|
+
"ai-translation",
|
|
26
|
+
"codegen",
|
|
27
|
+
"ast",
|
|
28
|
+
"jsx"
|
|
29
|
+
],
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">=18"
|
|
32
|
+
},
|
|
33
|
+
"bin": {
|
|
34
|
+
"translate-kit": "./dist/cli.js"
|
|
35
|
+
},
|
|
36
|
+
"exports": {
|
|
37
|
+
".": {
|
|
38
|
+
"import": "./dist/index.js",
|
|
39
|
+
"types": "./dist/index.d.ts"
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"files": [
|
|
43
|
+
"dist"
|
|
44
|
+
],
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "tsup",
|
|
47
|
+
"dev": "tsup --watch",
|
|
48
|
+
"test": "vitest run",
|
|
49
|
+
"test:watch": "vitest",
|
|
50
|
+
"lint": "biome check",
|
|
51
|
+
"lint:fix": "biome check --write",
|
|
52
|
+
"typecheck": "tsc --noEmit",
|
|
53
|
+
"prepublishOnly": "bun run build"
|
|
54
|
+
},
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"@babel/generator": "^7.29.1",
|
|
57
|
+
"@babel/parser": "^7.29.0",
|
|
58
|
+
"@babel/traverse": "^7.29.0",
|
|
59
|
+
"@babel/types": "^7.29.0",
|
|
60
|
+
"@clack/prompts": "^1.0.0",
|
|
61
|
+
"c12": "^4.0.0-beta.2",
|
|
62
|
+
"citty": "^0.2.0",
|
|
63
|
+
"dotenv": "^17.2.4",
|
|
64
|
+
"p-limit": "^7.3.0",
|
|
65
|
+
"picocolors": "^1.1.1",
|
|
66
|
+
"tinyglobby": "^0.2.15",
|
|
67
|
+
"tokenlens": "^1.3.1",
|
|
68
|
+
"zod": "^4.3.6"
|
|
69
|
+
},
|
|
70
|
+
"devDependencies": {
|
|
71
|
+
"@biomejs/biome": "2.3.15",
|
|
72
|
+
"@types/babel__generator": "^7.27.0",
|
|
73
|
+
"@types/babel__traverse": "^7.28.0",
|
|
74
|
+
"@types/node": "^25.2.3",
|
|
75
|
+
"tsup": "^8.5.1",
|
|
76
|
+
"typescript": "^5.9.3",
|
|
77
|
+
"vitest": "^4.0.18"
|
|
78
|
+
},
|
|
79
|
+
"peerDependencies": {
|
|
80
|
+
"ai": ">=4.0.0"
|
|
81
|
+
}
|
|
79
82
|
}
|