@syedamirali/i18n-toolkit 0.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/LICENSE +21 -0
- package/README.md +191 -0
- package/data/languages.json +642 -0
- package/dist/cli.js +2195 -0
- package/package.json +69 -0
- package/prompt/translation-prompt.md +51 -0
package/package.json
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@syedamirali/i18n-toolkit",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "AST-based CLI to extract translation keys from React/Next.js code, diff them against translation files, and translate missing keys via a local Ollama instance.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "Syed Amir Ali",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/SyedAmirAli/i18n-toolkit.git"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://github.com/SyedAmirAli/i18n-toolkit#readme",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/SyedAmirAli/i18n-toolkit/issues"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"i18n",
|
|
18
|
+
"l10n",
|
|
19
|
+
"localization",
|
|
20
|
+
"internationalization",
|
|
21
|
+
"translation",
|
|
22
|
+
"react",
|
|
23
|
+
"nextjs",
|
|
24
|
+
"ast",
|
|
25
|
+
"babel",
|
|
26
|
+
"cli",
|
|
27
|
+
"ollama",
|
|
28
|
+
"llm"
|
|
29
|
+
],
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">=20"
|
|
32
|
+
},
|
|
33
|
+
"bin": {
|
|
34
|
+
"i18n-toolkit": "./dist/cli.js"
|
|
35
|
+
},
|
|
36
|
+
"files": [
|
|
37
|
+
"dist",
|
|
38
|
+
"prompt",
|
|
39
|
+
"data",
|
|
40
|
+
"README.md",
|
|
41
|
+
"LICENSE"
|
|
42
|
+
],
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"access": "public"
|
|
45
|
+
},
|
|
46
|
+
"scripts": {
|
|
47
|
+
"build": "tsup",
|
|
48
|
+
"prepublishOnly": "yarn build",
|
|
49
|
+
"extract": "tsx src/cli.ts extract",
|
|
50
|
+
"diff": "tsx src/cli.ts diff",
|
|
51
|
+
"translate": "tsx src/cli.ts translate",
|
|
52
|
+
"help": "tsx src/cli.ts help",
|
|
53
|
+
"typecheck": "tsc --noEmit"
|
|
54
|
+
},
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"@babel/parser": "^7.29.3",
|
|
57
|
+
"@babel/traverse": "^7.29.0",
|
|
58
|
+
"@babel/types": "^7.29.0",
|
|
59
|
+
"@inquirer/prompts": "^8.4.3",
|
|
60
|
+
"fast-glob": "^3.3.3"
|
|
61
|
+
},
|
|
62
|
+
"devDependencies": {
|
|
63
|
+
"@types/babel__traverse": "^7.28.0",
|
|
64
|
+
"@types/node": "^20.0.0",
|
|
65
|
+
"tsup": "^8.5.1",
|
|
66
|
+
"tsx": "^4.20.6",
|
|
67
|
+
"typescript": "^5"
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
You are an expert i18n translator working on a React/Next.js application.
|
|
2
|
+
|
|
3
|
+
I will give you a JSON object containing English translation keys and their values. Your job is to translate every value into the requested target languages and return one perfect multilingual JSON object.
|
|
4
|
+
|
|
5
|
+
# Requirements
|
|
6
|
+
|
|
7
|
+
1. **Output must be valid JSON only.** No markdown, no fences, no explanation, no extra text.
|
|
8
|
+
2. **Structure:** the top-level object has one key per language. Each language maps to an object with the same key set as the input English object.
|
|
9
|
+
3. The first language is always `"en"` — copy the input values into it verbatim (no edits).
|
|
10
|
+
4. For each requested target language, produce a translation for every input key. **Never skip a key.**
|
|
11
|
+
5. **Keep the exact same keys** in every language object. Same spelling, same casing, same dot-separated structure. Do not add, remove, or invent keys.
|
|
12
|
+
|
|
13
|
+
# Languages to produce
|
|
14
|
+
|
|
15
|
+
You MUST emit one top-level entry for each of these languages, in this order:
|
|
16
|
+
|
|
17
|
+
LANGUAGES TO PRODUCE
|
|
18
|
+
|
|
19
|
+
# Translation style
|
|
20
|
+
|
|
21
|
+
6. **UI-friendly, natural translations** — not literal robotic ones. Match the tone and brevity of a polished mobile/web product.
|
|
22
|
+
7. **Preserve placeholders exactly.** Examples (DO NOT translate or modify these):
|
|
23
|
+
- `{date}`, `{count}`, `{name}` — single-brace
|
|
24
|
+
- `{{name}}`, `{{count}}` — double-brace
|
|
25
|
+
- `%s`, `%d`, `%1$s` — printf-style
|
|
26
|
+
- `:id`, `:userId` — colon-prefixed
|
|
27
|
+
- `<strong>`, `<em>`, `<br/>` — HTML tags
|
|
28
|
+
- `${slug}`, `${question.slug}` — template-literal expressions
|
|
29
|
+
8. **Do not translate** variable names, keys, placeholders, HTML tag names, code identifiers, brand names, product names, or technical terms (e.g. "TENS device", "Acusolo", "TypeScript").
|
|
30
|
+
9. **Match capitalization conventions per language.** Title case for buttons in English doesn't mean title case in every target language — follow native conventions.
|
|
31
|
+
10. **Sentinel values pass through unchanged.** If an input English value is exactly `"__missing_default__"`, emit the same `"__missing_default__"` string in every language. (These mark keys where the source code didn't provide a default; downstream tooling needs them preserved.)
|
|
32
|
+
11. **Empty strings stay empty.** If an input value is `""`, emit `""` in every language.
|
|
33
|
+
|
|
34
|
+
# Output shape
|
|
35
|
+
|
|
36
|
+
```json
|
|
37
|
+
{
|
|
38
|
+
"en": { "<key>": "<English value, copied verbatim>", ... },
|
|
39
|
+
"<lang1>": { "<key>": "<translation in lang1>", ... },
|
|
40
|
+
"<lang2>": { "<key>": "<translation in lang2>", ... },
|
|
41
|
+
...
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Every language object MUST contain the SAME set of keys as the English input.
|
|
46
|
+
|
|
47
|
+
# Input
|
|
48
|
+
|
|
49
|
+
Below is the input JSON. Translate every value (except sentinels and placeholders as noted) into each of the languages listed under "LANGUAGES TO PRODUCE":
|
|
50
|
+
|
|
51
|
+
PASTE CONTENT HERE
|