wuchale 0.22.4 → 0.22.6
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/ai/index.js +4 -3
- package/dist/handler/files.js +1 -1
- package/dist/handler/index.js +2 -2
- package/dist/hub.js +10 -11
- package/dist/pofile.js +4 -2
- package/dist/storage.d.ts +2 -0
- package/package.json +2 -2
package/dist/ai/index.js
CHANGED
|
@@ -67,11 +67,12 @@ export default class AIQueue {
|
|
|
67
67
|
const logStart = this.#requestName(batch.id, batch.targetLocales);
|
|
68
68
|
let translated = [];
|
|
69
69
|
try {
|
|
70
|
-
const
|
|
71
|
-
id: item.
|
|
70
|
+
const inputItems = batch.messages.map(item => ({
|
|
71
|
+
id: item.translations.get(this.sourceLocale),
|
|
72
72
|
context: item.context,
|
|
73
73
|
references: item.references,
|
|
74
|
-
}))
|
|
74
|
+
}));
|
|
75
|
+
const translatedstr = await this.ai.translate(JSON.stringify(inputItems), instruct(this.sourceLocale, batch.targetLocales));
|
|
75
76
|
translated = JSON.parse(translatedstr);
|
|
76
77
|
if (Array.isArray(translated)) {
|
|
77
78
|
translated = translated.slice(0, batch.messages.length); // may return more
|
package/dist/handler/files.js
CHANGED
|
@@ -226,7 +226,7 @@ export class Files {
|
|
|
226
226
|
return resolve(this.#localesDirAbs, generatedDir, `${ownerKey}.${id ?? ownerKey}.manifest.js`);
|
|
227
227
|
}
|
|
228
228
|
writeManifest = async (keys, id) => {
|
|
229
|
-
const content = `/** @type {(string | {text: string | string[], context?: string, isUrl?: boolean}
|
|
229
|
+
const content = `/** @type {(string | string[] | {text: string | string[], context?: string, isUrl?: boolean})[]} */\n` +
|
|
230
230
|
`export const keys = ${JSON.stringify(keys)}`;
|
|
231
231
|
await this.#fs.write(this.getManifestFilePath(id), content);
|
|
232
232
|
};
|
package/dist/handler/index.js
CHANGED
|
@@ -101,7 +101,7 @@ export class AdapterHandler {
|
|
|
101
101
|
const isUrl = itemIsUrl(item);
|
|
102
102
|
const id = item.translations.get(this.sourceLocale);
|
|
103
103
|
const text = id.length === 1 ? id[0] : id;
|
|
104
|
-
if (!isUrl && item.context
|
|
104
|
+
if (!isUrl && item.context == null) {
|
|
105
105
|
manifest[index] = text;
|
|
106
106
|
continue;
|
|
107
107
|
}
|
|
@@ -444,7 +444,7 @@ export class AdapterHandler {
|
|
|
444
444
|
}
|
|
445
445
|
const [hmrKeys, updatedItems] = await this.handleMessages(msgs, filename);
|
|
446
446
|
updated = updatedItems;
|
|
447
|
-
if (msgs.length && hmrVersion >= 0) {
|
|
447
|
+
if (!forServer && msgs.length > 0 && hmrVersion >= 0) {
|
|
448
448
|
hmrData = { version: hmrVersion, data: {} };
|
|
449
449
|
for (const loc of this.#config.locales) {
|
|
450
450
|
hmrData.data[loc] =
|
package/dist/hub.js
CHANGED
|
@@ -115,6 +115,7 @@ export class Hub {
|
|
|
115
115
|
const storage = adapter.storage({
|
|
116
116
|
locales: this.#config.locales,
|
|
117
117
|
root: this.#projectRoot,
|
|
118
|
+
localesDir: this.#config.localesDir,
|
|
118
119
|
sourceLocale: sourceLocale,
|
|
119
120
|
haveUrl: adapter.url != null,
|
|
120
121
|
fs: this.#fs,
|
|
@@ -236,26 +237,24 @@ export class Hub {
|
|
|
236
237
|
updated ||= (await Promise.all(filePaths.map(f => this.#visitFileHandl(f, handler)))).some(r => r);
|
|
237
238
|
}
|
|
238
239
|
// only owner adapter should clean
|
|
239
|
-
if (
|
|
240
|
-
const logPrefix = logPrefixHandler(handler.key);
|
|
241
|
-
this.#log.info(`${logPrefix} Cleaning...`);
|
|
240
|
+
if (handler.sharedState.ownerKey === handler.key) {
|
|
242
241
|
let cleaned = 0;
|
|
243
242
|
for (const [key, item] of catalog) {
|
|
244
243
|
const initRefsN = item.references.length;
|
|
245
244
|
// check if file deleted or pattern no longer matches
|
|
246
245
|
item.references = item.references.filter(ref => existingFiles.has(ref.file));
|
|
247
|
-
if (
|
|
248
|
-
catalog.delete(key);
|
|
246
|
+
if (item.references.length < initRefsN) {
|
|
249
247
|
updated = true;
|
|
250
|
-
cleaned++;
|
|
251
248
|
}
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
cleaned++;
|
|
249
|
+
if (!clean || !itemIsObsolete(item)) {
|
|
250
|
+
continue;
|
|
255
251
|
}
|
|
252
|
+
catalog.delete(key);
|
|
253
|
+
updated = true;
|
|
254
|
+
cleaned++;
|
|
256
255
|
}
|
|
257
|
-
if (cleaned) {
|
|
258
|
-
this.#log.info(`${
|
|
256
|
+
if (cleaned > 0) {
|
|
257
|
+
this.#log.info(`${logPrefixHandler(handler.key)} Cleaned ${cleaned} items`);
|
|
259
258
|
}
|
|
260
259
|
}
|
|
261
260
|
if (updated) {
|
package/dist/pofile.js
CHANGED
|
@@ -230,6 +230,8 @@ export class POFile {
|
|
|
230
230
|
}
|
|
231
231
|
}
|
|
232
232
|
export function pofile(pofOpts = {}) {
|
|
233
|
-
|
|
234
|
-
|
|
233
|
+
return opts => new POFile({
|
|
234
|
+
...opts,
|
|
235
|
+
...deepMergeObjects(pofOpts, { ...defaultOpts, dir: opts.localesDir }),
|
|
236
|
+
});
|
|
235
237
|
}
|
package/dist/storage.d.ts
CHANGED
|
@@ -52,6 +52,8 @@ export type Catalog = Map<string, Item>;
|
|
|
52
52
|
export type StorageFactoryOpts = {
|
|
53
53
|
locales: string[];
|
|
54
54
|
root: string;
|
|
55
|
+
/** shared locale artifacts directory from the top-level config */
|
|
56
|
+
localesDir: string;
|
|
55
57
|
/** whether the url is configured, can use to load separate url files */
|
|
56
58
|
haveUrl: boolean;
|
|
57
59
|
sourceLocale: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wuchale",
|
|
3
|
-
"version": "0.22.
|
|
3
|
+
"version": "0.22.6",
|
|
4
4
|
"description": "Protobuf-like i18n from plain code",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"dev": "tsc --watch",
|
|
@@ -88,7 +88,7 @@
|
|
|
88
88
|
"acorn": "^8.16.0",
|
|
89
89
|
"chokidar": "^5.0.0",
|
|
90
90
|
"magic-string": "^0.30.21",
|
|
91
|
-
"path-to-regexp": "^8.
|
|
91
|
+
"path-to-regexp": "^8.4.0",
|
|
92
92
|
"picomatch": "^4.0.4",
|
|
93
93
|
"pofile": "^1.1.4",
|
|
94
94
|
"tinyglobby": "^0.2.15"
|