@adminforth/i18n 1.0.14 → 1.0.17-next.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.
Files changed (3) hide show
  1. package/dist/index.js +12 -8
  2. package/index.ts +12 -8
  3. package/package.json +2 -1
package/dist/index.js CHANGED
@@ -277,19 +277,23 @@ export default class I18N extends AdminForthPlugin {
277
277
  confirm: 'Are you sure you want to translate selected items?',
278
278
  state: 'selected',
279
279
  action: (_j) => __awaiter(this, [_j], void 0, function* ({ selectedIds, tr }) {
280
+ let translatedCount = 0;
280
281
  try {
281
- yield this.bulkTranslate({ selectedIds });
282
+ translatedCount = yield this.bulkTranslate({ selectedIds });
282
283
  }
283
284
  catch (e) {
284
285
  if (e instanceof AiTranslateError) {
286
+ process.env.HEAVY_DEBUG && console.error('🪲⛔ bulkTranslate error', e);
285
287
  return { ok: false, error: e.message };
286
288
  }
287
289
  }
288
- console.log('🪲bulkTranslate done', selectedIds);
290
+ process.env.HEAVY_DEBUG && console.log('🪲bulkTranslate done', selectedIds);
289
291
  this.updateUntranslatedMenuBadge();
290
292
  return {
291
293
  ok: true, error: undefined,
292
- successMessage: yield tr(`Translated {count} items`, 'backend', { count: selectedIds.length }),
294
+ successMessage: yield tr(`Translated {count} items`, 'backend', {
295
+ count: translatedCount,
296
+ }),
293
297
  };
294
298
  })
295
299
  });
@@ -351,7 +355,7 @@ export default class I18N extends AdminForthPlugin {
351
355
  let totalTranslated = 0;
352
356
  for (let i = 0; i < strings.length; i += maxKeysInOneReq) {
353
357
  const slicedStrings = strings.slice(i, i + maxKeysInOneReq);
354
- console.log('🪲🔪slicedStrings ', slicedStrings);
358
+ process.env.HEAVY_DEBUG && console.log('🪲🔪slicedStrings len', slicedStrings.length);
355
359
  totalTranslated += yield translateToLang(langIsoCode, slicedStrings, plurals);
356
360
  }
357
361
  return totalTranslated;
@@ -370,10 +374,10 @@ ${JSON.stringify(strings.reduce((acc, s) => {
370
374
  }, {}), null, 2)}
371
375
  \`\`\`
372
376
  `;
373
- process.env.HEAVY_DEBUG && console.log('llm prompt', prompt);
377
+ process.env.HEAVY_DEBUG && console.log('🧠 llm prompt', prompt);
374
378
  // call OpenAI
375
379
  const resp = yield this.options.completeAdapter.complete(prompt, [], 300);
376
- process.env.HEAVY_DEBUG && console.log('llm resp', resp);
380
+ process.env.HEAVY_DEBUG && console.log('🧠 llm resp', resp);
377
381
  if (resp.error) {
378
382
  throw new AiTranslateError(resp.error);
379
383
  }
@@ -388,7 +392,7 @@ ${JSON.stringify(strings.reduce((acc, s) => {
388
392
  }
389
393
  catch (e) {
390
394
  console.error('error in parsing OpenAI', resp);
391
- return;
395
+ throw new AiTranslateError('Error in parsing OpenAI response');
392
396
  }
393
397
  res = JSON.parse(res);
394
398
  for (const [enStr, translatedStr] of Object.entries(res)) {
@@ -408,7 +412,7 @@ ${JSON.stringify(strings.reduce((acc, s) => {
408
412
  updateStrings[translation[this.primaryKeyFieldName]].updates[this.trFieldNames[lang]] = translatedStr;
409
413
  }
410
414
  }
411
- return res.length;
415
+ return Object.keys(updateStrings).length;
412
416
  });
413
417
  const langsInvolved = new Set(Object.keys(needToTranslateByLang));
414
418
  let totalTranslated = 0;
package/index.ts CHANGED
@@ -318,18 +318,22 @@ export default class I18N extends AdminForthPlugin {
318
318
  confirm: 'Are you sure you want to translate selected items?',
319
319
  state: 'selected',
320
320
  action: async ({ selectedIds, tr }) => {
321
+ let translatedCount = 0;
321
322
  try {
322
- await this.bulkTranslate({ selectedIds });
323
+ translatedCount = await this.bulkTranslate({ selectedIds });
323
324
  } catch (e) {
324
325
  if (e instanceof AiTranslateError) {
326
+ process.env.HEAVY_DEBUG && console.error('🪲⛔ bulkTranslate error', e);
325
327
  return { ok: false, error: e.message };
326
328
  }
327
329
  }
328
- console.log('🪲bulkTranslate done', selectedIds);
330
+ process.env.HEAVY_DEBUG && console.log('🪲bulkTranslate done', selectedIds);
329
331
  this.updateUntranslatedMenuBadge();
330
332
  return {
331
333
  ok: true, error: undefined,
332
- successMessage: await tr(`Translated {count} items`, 'backend', {count: selectedIds.length}),
334
+ successMessage: await tr(`Translated {count} items`, 'backend', {
335
+ count: translatedCount,
336
+ }),
333
337
  };
334
338
  }
335
339
  }
@@ -411,7 +415,7 @@ export default class I18N extends AdminForthPlugin {
411
415
  let totalTranslated = 0;
412
416
  for (let i = 0; i < strings.length; i += maxKeysInOneReq) {
413
417
  const slicedStrings = strings.slice(i, i + maxKeysInOneReq);
414
- console.log('🪲🔪slicedStrings ', slicedStrings);
418
+ process.env.HEAVY_DEBUG && console.log('🪲🔪slicedStrings len', slicedStrings.length);
415
419
  totalTranslated += await translateToLang(langIsoCode, slicedStrings, plurals);
416
420
  }
417
421
  return totalTranslated;
@@ -435,7 +439,7 @@ ${
435
439
  \`\`\`
436
440
  `;
437
441
 
438
- process.env.HEAVY_DEBUG && console.log('llm prompt', prompt);
442
+ process.env.HEAVY_DEBUG && console.log('🧠 llm prompt', prompt);
439
443
 
440
444
  // call OpenAI
441
445
  const resp = await this.options.completeAdapter.complete(
@@ -444,7 +448,7 @@ ${
444
448
  300,
445
449
  );
446
450
 
447
- process.env.HEAVY_DEBUG && console.log('llm resp', resp);
451
+ process.env.HEAVY_DEBUG && console.log('🧠 llm resp', resp);
448
452
 
449
453
  if (resp.error) {
450
454
  throw new AiTranslateError(resp.error);
@@ -460,7 +464,7 @@ ${
460
464
  res = resp.content.split("```json")[1].split("```")[0];
461
465
  } catch (e) {
462
466
  console.error('error in parsing OpenAI', resp);
463
- return;
467
+ throw new AiTranslateError('Error in parsing OpenAI response');
464
468
  }
465
469
  res = JSON.parse(res);
466
470
 
@@ -486,7 +490,7 @@ ${
486
490
  }
487
491
  }
488
492
 
489
- return res.length;
493
+ return Object.keys(updateStrings).length;
490
494
  }
491
495
 
492
496
  const langsInvolved = new Set(Object.keys(needToTranslateByLang));
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@adminforth/i18n",
3
- "version": "1.0.14",
3
+ "version": "1.0.17-next.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",
7
7
  "scripts": {
8
8
  "build": "tsc && rsync -av --exclude 'node_modules' custom dist/ && npm version patch",
9
9
  "rollout": "npm run build && npm publish --access public",
10
+ "rollout-next": "npm run build && npm version prerelease --preid=next && npm publish --tag next",
10
11
  "prepare": "npm link adminforth"
11
12
  },
12
13
  "keywords": [],