locale-ai 0.3.0 → 0.3.1
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/README.md +3 -4
- package/package.json +8 -3
- package/scripts/trim-onnxruntime.cjs +54 -0
package/README.md
CHANGED
|
@@ -135,6 +135,7 @@ Measured on a sample app (see `test/fixtures`):
|
|
|
135
135
|
- **Sentence splitting**: OPUS-MT drops sentences from multi-sentence inputs, so each sentence is translated separately.
|
|
136
136
|
- **Placeholder masking** with three marker styles tried in order (`{0}` / `<0>…</0>`, then numbers `900`, then `_P0_`), validating every marker; numbers survive models that mangle braces (en-zh, en-ru). A last-resort fallback translates around placeholders, and anything that needed it is listed for review.
|
|
137
137
|
- **Speed** (20-core CPU, ~1 GB RAM): sample app (43 strings) in ~3 s per language with beam search, ~2 s with `--fast`; full sentences at ~18/s (built-in, beam 4), ~12/s (tc-big, beam 4), ~33/s (tc-big, `--fast`).
|
|
138
|
+
- **Install size**: `onnxruntime-node` bundles binaries for every platform, and on linux/x64 downloads a ~260 MB CUDA provider by default — locale-ai only ever runs on CPU (`executionProviders: ["cpu"]`), so a `postinstall` script ([`scripts/trim-onnxruntime.cjs`](scripts/trim-onnxruntime.cjs)) removes the unused platforms and GPU providers after install, cutting it from ~550 MB to ~45 MB on your current platform.
|
|
138
139
|
|
|
139
140
|
## Development
|
|
140
141
|
|
|
@@ -149,7 +150,5 @@ npm run build # → dist/
|
|
|
149
150
|
|
|
150
151
|
## Next steps
|
|
151
152
|
|
|
152
|
-
1. **
|
|
153
|
-
2. **
|
|
154
|
-
3. **More languages**: ja, ko, pl have no usable OPUS-MT model yet; a different model family would be needed.
|
|
155
|
-
4. **More formats**: YAML, `.po`, ARB, Apple `.strings`.
|
|
153
|
+
1. **More languages**: ja, ko, pl have no usable OPUS-MT model yet; a different model family would be needed.
|
|
154
|
+
2. **More formats**: YAML, `.po`, ARB, Apple `.strings`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "locale-ai",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Translate your i18n locale files locally on CPU. Free, offline, no API keys.",
|
|
5
5
|
"author": "Taha KHABOUSS",
|
|
6
6
|
"repository": {
|
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
},
|
|
18
18
|
"files": [
|
|
19
19
|
"dist",
|
|
20
|
-
"scripts/convert-marian.py"
|
|
20
|
+
"scripts/convert-marian.py",
|
|
21
|
+
"scripts/trim-onnxruntime.cjs"
|
|
21
22
|
],
|
|
22
23
|
"engines": {
|
|
23
24
|
"node": ">=22.18"
|
|
@@ -28,7 +29,8 @@
|
|
|
28
29
|
"dev": "node src/cli.ts",
|
|
29
30
|
"test": "node --test test/*.test.ts",
|
|
30
31
|
"test:e2e": "LOCALE_AI_E2E=1 node --test test/e2e.test.ts",
|
|
31
|
-
"prepublishOnly": "npm run build && npm test"
|
|
32
|
+
"prepublishOnly": "npm run build && npm test",
|
|
33
|
+
"postinstall": "node scripts/trim-onnxruntime.cjs"
|
|
32
34
|
},
|
|
33
35
|
"keywords": [
|
|
34
36
|
"i18n",
|
|
@@ -48,5 +50,8 @@
|
|
|
48
50
|
"devDependencies": {
|
|
49
51
|
"@types/node": "^26.6.6",
|
|
50
52
|
"typescript": "^7.0.2"
|
|
53
|
+
},
|
|
54
|
+
"allowScripts": {
|
|
55
|
+
"onnxruntime-node@1.30.0": true
|
|
51
56
|
}
|
|
52
57
|
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
// locale-ai only ever runs onnxruntime-node with executionProviders: ["cpu"]
|
|
5
|
+
// (see src/marian.ts) and only ever runs on one platform/arch per install.
|
|
6
|
+
// onnxruntime-node still bundles binaries for every platform, and on
|
|
7
|
+
// linux/x64 its own postinstall downloads a 260 MB CUDA provider we never
|
|
8
|
+
// use (see its script/install-metadata.js). This trims all of that after
|
|
9
|
+
// onnxruntime-node has finished installing, shrinking a ~550 MB unpacked
|
|
10
|
+
// dependency down to the one binary locale-ai actually loads.
|
|
11
|
+
//
|
|
12
|
+
// Best-effort: never fails the install, even if onnxruntime-node changes
|
|
13
|
+
// its layout in a future version.
|
|
14
|
+
|
|
15
|
+
const fs = require('fs');
|
|
16
|
+
const path = require('path');
|
|
17
|
+
|
|
18
|
+
function rm(p) {
|
|
19
|
+
try {
|
|
20
|
+
fs.rmSync(p, { recursive: true, force: true });
|
|
21
|
+
} catch {
|
|
22
|
+
// ignore — best-effort cleanup only
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
try {
|
|
27
|
+
const pkgJson = require.resolve('onnxruntime-node/package.json');
|
|
28
|
+
const binRoot = path.join(path.dirname(pkgJson), 'bin', 'napi-v6');
|
|
29
|
+
if (!fs.existsSync(binRoot)) process.exit(0);
|
|
30
|
+
|
|
31
|
+
const platform = process.platform;
|
|
32
|
+
const arch = process.arch;
|
|
33
|
+
|
|
34
|
+
for (const entry of fs.readdirSync(binRoot)) {
|
|
35
|
+
const platformDir = path.join(binRoot, entry);
|
|
36
|
+
if (entry !== platform) {
|
|
37
|
+
rm(platformDir);
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
// Same platform: drop every other architecture.
|
|
41
|
+
for (const archEntry of fs.readdirSync(platformDir)) {
|
|
42
|
+
if (archEntry !== arch) rm(path.join(platformDir, archEntry));
|
|
43
|
+
}
|
|
44
|
+
// Drop GPU execution providers locale-ai never requests.
|
|
45
|
+
const archDir = path.join(platformDir, arch);
|
|
46
|
+
for (const name of fs.readdirSync(archDir)) {
|
|
47
|
+
if (/^libonnxruntime_providers_(cuda|tensorrt|rocm|dml)\./.test(name)) {
|
|
48
|
+
rm(path.join(archDir, name));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
} catch {
|
|
53
|
+
// onnxruntime-node not installed, or its layout changed — nothing to do.
|
|
54
|
+
}
|