ai-localize-locale-engine 1.0.0 → 1.0.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/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +13 -13
- package/dist/index.mjs +3 -3
- package/package.json +2 -2
- package/src/__tests__/extractor.test.ts +1 -1
- package/src/deduplicator.ts +1 -1
- package/src/extractor.ts +2 -2
- package/src/synchronizer.ts +1 -1
- package/src/writer.ts +2 -2
package/dist/index.d.mts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -40,7 +40,7 @@ __export(index_exports, {
|
|
|
40
40
|
module.exports = __toCommonJS(index_exports);
|
|
41
41
|
|
|
42
42
|
// src/extractor.ts
|
|
43
|
-
var
|
|
43
|
+
var import_ai_localize_shared = require("ai-localize-shared");
|
|
44
44
|
var LocaleExtractor = class {
|
|
45
45
|
options;
|
|
46
46
|
constructor(options = {}) {
|
|
@@ -56,14 +56,14 @@ var LocaleExtractor = class {
|
|
|
56
56
|
for (const dt of detectedTexts) {
|
|
57
57
|
let key = dt.suggestedKey;
|
|
58
58
|
if (keyValueMap.has(key) && keyValueMap.get(key) !== dt.text) {
|
|
59
|
-
key = (0,
|
|
59
|
+
key = (0, import_ai_localize_shared.resolveKeyCollision)(key, existingKeys);
|
|
60
60
|
}
|
|
61
61
|
existingKeys.add(key);
|
|
62
62
|
keyValueMap.set(key, dt.text);
|
|
63
63
|
}
|
|
64
64
|
const namespaceMap = /* @__PURE__ */ new Map();
|
|
65
65
|
for (const [key, value] of keyValueMap) {
|
|
66
|
-
const { namespace, localKey } = this.options.namespaceSplitting ? (0,
|
|
66
|
+
const { namespace, localKey } = this.options.namespaceSplitting ? (0, import_ai_localize_shared.splitKeyNamespace)(key) : { namespace: import_ai_localize_shared.DEFAULT_NAMESPACE, localKey: key };
|
|
67
67
|
if (!namespaceMap.has(namespace)) namespaceMap.set(namespace, {});
|
|
68
68
|
namespaceMap.get(namespace)[localKey] = value;
|
|
69
69
|
}
|
|
@@ -87,7 +87,7 @@ var LocaleExtractor = class {
|
|
|
87
87
|
|
|
88
88
|
// src/writer.ts
|
|
89
89
|
var path = __toESM(require("path"));
|
|
90
|
-
var
|
|
90
|
+
var import_ai_localize_shared2 = require("ai-localize-shared");
|
|
91
91
|
var LocaleWriter = class {
|
|
92
92
|
options;
|
|
93
93
|
constructor(options) {
|
|
@@ -100,14 +100,14 @@ var LocaleWriter = class {
|
|
|
100
100
|
for (const lf of localeFiles) {
|
|
101
101
|
const filePath = this.resolveFilePath(lf);
|
|
102
102
|
lf.filePath = filePath;
|
|
103
|
-
(0,
|
|
104
|
-
const existing = (0,
|
|
103
|
+
(0, import_ai_localize_shared2.ensureDir)(path.dirname(filePath));
|
|
104
|
+
const existing = (0, import_ai_localize_shared2.readJsonSafe)(filePath);
|
|
105
105
|
if (existing && this.options.merge) {
|
|
106
106
|
const mergedEntries = this.mergeEntries(existing, lf.entries);
|
|
107
|
-
(0,
|
|
107
|
+
(0, import_ai_localize_shared2.writeJson)(filePath, this.options.sort ? this.sort(mergedEntries) : mergedEntries);
|
|
108
108
|
merged.push(filePath);
|
|
109
109
|
} else {
|
|
110
|
-
(0,
|
|
110
|
+
(0, import_ai_localize_shared2.writeJson)(filePath, this.options.sort ? this.sort(lf.entries) : lf.entries);
|
|
111
111
|
created.push(filePath);
|
|
112
112
|
}
|
|
113
113
|
written.push(filePath);
|
|
@@ -149,7 +149,7 @@ function findUnusedKeys(localeKeys, sourceKeys) {
|
|
|
149
149
|
// src/synchronizer.ts
|
|
150
150
|
var fs = __toESM(require("fs"));
|
|
151
151
|
var path2 = __toESM(require("path"));
|
|
152
|
-
var
|
|
152
|
+
var import_ai_localize_shared3 = require("ai-localize-shared");
|
|
153
153
|
var LocaleSynchronizer = class {
|
|
154
154
|
constructor(localesDir, defaultLanguage = "en") {
|
|
155
155
|
this.localesDir = localesDir;
|
|
@@ -165,12 +165,12 @@ var LocaleSynchronizer = class {
|
|
|
165
165
|
const defaultFiles = fs.readdirSync(defaultDir).filter((f) => f.endsWith(".json"));
|
|
166
166
|
const langDirs = fs.readdirSync(this.localesDir, { withFileTypes: true }).filter((e) => e.isDirectory() && e.name !== this.defaultLanguage).map((e) => e.name);
|
|
167
167
|
for (const namespace of defaultFiles) {
|
|
168
|
-
const defaultEntries = (0,
|
|
168
|
+
const defaultEntries = (0, import_ai_localize_shared3.readJsonSafe)(path2.join(defaultDir, namespace));
|
|
169
169
|
if (!defaultEntries) continue;
|
|
170
170
|
for (const lang of langDirs) {
|
|
171
171
|
const targetPath = path2.join(this.localesDir, lang, namespace);
|
|
172
|
-
(0,
|
|
173
|
-
const existing = (0,
|
|
172
|
+
(0, import_ai_localize_shared3.ensureDir)(path2.dirname(targetPath));
|
|
173
|
+
const existing = (0, import_ai_localize_shared3.readJsonSafe)(targetPath) || {};
|
|
174
174
|
let changed = false;
|
|
175
175
|
for (const key of Object.keys(defaultEntries)) {
|
|
176
176
|
if (!(key in existing)) {
|
|
@@ -180,7 +180,7 @@ var LocaleSynchronizer = class {
|
|
|
180
180
|
}
|
|
181
181
|
}
|
|
182
182
|
if (changed) {
|
|
183
|
-
(0,
|
|
183
|
+
(0, import_ai_localize_shared3.writeJson)(targetPath, existing);
|
|
184
184
|
updated.push(targetPath);
|
|
185
185
|
}
|
|
186
186
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
splitKeyNamespace,
|
|
4
4
|
resolveKeyCollision,
|
|
5
5
|
DEFAULT_NAMESPACE
|
|
6
|
-
} from "
|
|
6
|
+
} from "ai-localize-shared";
|
|
7
7
|
var LocaleExtractor = class {
|
|
8
8
|
options;
|
|
9
9
|
constructor(options = {}) {
|
|
@@ -50,7 +50,7 @@ var LocaleExtractor = class {
|
|
|
50
50
|
|
|
51
51
|
// src/writer.ts
|
|
52
52
|
import * as path from "path";
|
|
53
|
-
import { writeJson, readJsonSafe, ensureDir } from "
|
|
53
|
+
import { writeJson, readJsonSafe, ensureDir } from "ai-localize-shared";
|
|
54
54
|
var LocaleWriter = class {
|
|
55
55
|
options;
|
|
56
56
|
constructor(options) {
|
|
@@ -112,7 +112,7 @@ function findUnusedKeys(localeKeys, sourceKeys) {
|
|
|
112
112
|
// src/synchronizer.ts
|
|
113
113
|
import * as fs from "fs";
|
|
114
114
|
import * as path2 from "path";
|
|
115
|
-
import { readJsonSafe as readJsonSafe2, writeJson as writeJson2, ensureDir as ensureDir2 } from "
|
|
115
|
+
import { readJsonSafe as readJsonSafe2, writeJson as writeJson2, ensureDir as ensureDir2 } from "ai-localize-shared";
|
|
116
116
|
var LocaleSynchronizer = class {
|
|
117
117
|
constructor(localesDir, defaultLanguage = "en") {
|
|
118
118
|
this.localesDir = localesDir;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ai-localize-locale-engine",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Locale file generation, merging, deduplication and synchronization",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
}
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"ai-localize-shared": "1.0.
|
|
16
|
+
"ai-localize-shared": "1.0.1"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"tsup": "^8.0.1",
|
package/src/deduplicator.ts
CHANGED
package/src/extractor.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { DetectedText, LocaleFile } from "
|
|
1
|
+
import type { DetectedText, LocaleFile } from "ai-localize-shared";
|
|
2
2
|
import {
|
|
3
3
|
splitKeyNamespace,
|
|
4
4
|
resolveKeyCollision,
|
|
5
5
|
DEFAULT_NAMESPACE,
|
|
6
|
-
} from "
|
|
6
|
+
} from "ai-localize-shared";
|
|
7
7
|
|
|
8
8
|
export interface ExtractOptions {
|
|
9
9
|
defaultLanguage?: string;
|
package/src/synchronizer.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as fs from "fs";
|
|
2
2
|
import * as path from "path";
|
|
3
|
-
import { readJsonSafe, writeJson, ensureDir } from "
|
|
3
|
+
import { readJsonSafe, writeJson, ensureDir } from "ai-localize-shared";
|
|
4
4
|
|
|
5
5
|
export class LocaleSynchronizer {
|
|
6
6
|
constructor(private localesDir: string, private defaultLanguage = "en") {}
|
package/src/writer.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as path from "path";
|
|
2
|
-
import type { LocaleFile } from "
|
|
3
|
-
import { writeJson, readJsonSafe, ensureDir } from "
|
|
2
|
+
import type { LocaleFile } from "ai-localize-shared";
|
|
3
|
+
import { writeJson, readJsonSafe, ensureDir } from "ai-localize-shared";
|
|
4
4
|
|
|
5
5
|
export interface WriteOptions {
|
|
6
6
|
localesDir: string;
|