ai-localize-codemods 2.0.5 → 2.0.7
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/CHANGELOG.md +15 -0
- package/LICENSE +21 -0
- package/README.md +78 -0
- package/package.json +14 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# ai-localize-codemods
|
|
2
2
|
|
|
3
|
+
## 2.0.7
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Added `repository`, `homepage`, `bugs`, `author` fields to `package.json` for npm registry display.
|
|
8
|
+
- Added `sideEffects: false` to enable tree-shaking in bundlers.
|
|
9
|
+
- Added `prepublishOnly` script to ensure the package is built before publishing.
|
|
10
|
+
|
|
11
|
+
## 2.0.6
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- Add per-package README.md files so each package displays documentation on npmjs.com
|
|
16
|
+
- Update README version badge to 2.0.6
|
|
17
|
+
|
|
3
18
|
## 2.0.3
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-2026 ai-localize-core contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# ai-localize-codemods
|
|
2
|
+
|
|
3
|
+
> Automatic i18n codemod injection for React, Vue, and Angular — part of the [ai-localize-core](https://github.com/ai-localize/ai-localize-core) platform.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/ai-localize-codemods)
|
|
6
|
+
[](LICENSE)
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## What it does
|
|
11
|
+
|
|
12
|
+
Transforms source files using Babel AST + Recast to:
|
|
13
|
+
|
|
14
|
+
1. Add the appropriate import (`useTranslation`, `useI18n`, `TranslateService`, …)
|
|
15
|
+
2. Initialise the hook in each component
|
|
16
|
+
3. Wrap every hardcoded string with the translation call: `t('key')`
|
|
17
|
+
4. Preserve original code formatting (Recast format-preserving transforms)
|
|
18
|
+
|
|
19
|
+
Supports **CDN URL replacement** in source files using an asset manifest.
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install ai-localize-codemods
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
import { CodemodRunner } from 'ai-localize-codemods';
|
|
31
|
+
|
|
32
|
+
const runner = new CodemodRunner(config, process.cwd());
|
|
33
|
+
const result = await runner.run(detectedTexts, { dryRun: false });
|
|
34
|
+
// result.totalReplacements — number of string replacements
|
|
35
|
+
// result.changedFiles — number of files modified
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Codemod configuration
|
|
39
|
+
|
|
40
|
+
Control what code is injected via the `codemods` block in `ai-localize.config.json`:
|
|
41
|
+
|
|
42
|
+
```json
|
|
43
|
+
{
|
|
44
|
+
"codemods": {
|
|
45
|
+
"importPackage": "react-i18next",
|
|
46
|
+
"hookName": "useTranslation",
|
|
47
|
+
"translationFunction": "t",
|
|
48
|
+
"namespace": "common",
|
|
49
|
+
"accessorStyle": "function"
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
| Field | Default | Description |
|
|
55
|
+
|---|---|---|
|
|
56
|
+
| `importPackage` | `"react-i18next"` | npm package **or** project-relative path (e.g. `"src/hooks/useTranslation"`) |
|
|
57
|
+
| `hookName` | `"useTranslation"` | Hook/function to import |
|
|
58
|
+
| `translationFunction` | `"t"` | Accessor variable name |
|
|
59
|
+
| `namespace` | — | Namespace arg: `useTranslation("common")` |
|
|
60
|
+
| `accessorStyle` | `"function"` | `"function"` → `t('key')` · `"bracket"` → `t['key']` |
|
|
61
|
+
|
|
62
|
+
### Local hook path resolution
|
|
63
|
+
|
|
64
|
+
When `importPackage` is a project-relative path, the codemod computes the correct
|
|
65
|
+
relative import for every transformed file:
|
|
66
|
+
|
|
67
|
+
```
|
|
68
|
+
src/components/Button.tsx → import { useTranslation } from '../../hooks/useTranslation'
|
|
69
|
+
src/pages/Home.tsx → import { useTranslation } from '../hooks/useTranslation'
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## Part of ai-localize-core
|
|
75
|
+
|
|
76
|
+
Install the CLI for the complete toolset: `npm install -g ai-localize-cli`
|
|
77
|
+
|
|
78
|
+
MIT © ai-localize-core contributors
|
package/package.json
CHANGED
|
@@ -1,10 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ai-localize-codemods",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.7",
|
|
4
4
|
"description": "AST-based codemods to inject i18n wrappers into frontend source code",
|
|
5
|
+
"author": "ai-localize-core contributors",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/ai-localize/ai-localize-core.git",
|
|
10
|
+
"directory": "packages/codemods"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://github.com/ai-localize/ai-localize-core/tree/main/packages/codemods#readme",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/ai-localize/ai-localize-core/issues"
|
|
15
|
+
},
|
|
5
16
|
"main": "./dist/index.js",
|
|
6
17
|
"module": "./dist/index.mjs",
|
|
7
18
|
"types": "./dist/index.d.ts",
|
|
19
|
+
"sideEffects": false,
|
|
8
20
|
"files": [
|
|
9
21
|
"dist",
|
|
10
22
|
"README.md",
|
|
@@ -41,7 +53,7 @@
|
|
|
41
53
|
"@babel/generator": "^7.23.9",
|
|
42
54
|
"recast": "^0.23.4",
|
|
43
55
|
"jscodeshift": "^0.15.2",
|
|
44
|
-
"ai-localize-shared": "2.0.
|
|
56
|
+
"ai-localize-shared": "2.0.7"
|
|
45
57
|
},
|
|
46
58
|
"devDependencies": {
|
|
47
59
|
"@types/babel__generator": "^7.6.8",
|
|
@@ -51,7 +63,6 @@
|
|
|
51
63
|
"typescript": "^5.3.3",
|
|
52
64
|
"vitest": "^1.2.1"
|
|
53
65
|
},
|
|
54
|
-
"license": "MIT",
|
|
55
66
|
"publishConfig": {
|
|
56
67
|
"access": "public"
|
|
57
68
|
},
|