@adminforth/i18n 1.2.1 → 1.2.3

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 CHANGED
@@ -1,2 +1,7 @@
1
+ # AdminForth i18n Plugin
1
2
 
2
- Ussage guide and documentation: https://adminforth.dev/docs/tutorial/Plugins/i18n/
3
+ <img src="https://img.shields.io/badge/License-MIT-blue.svg" alt="License: MIT" /> <img src="https://woodpecker.devforth.io/api/badges/3848/status.svg" alt="Build Status" /> <a href="https://www.npmjs.com/package/@adminforth/i18n"> <img src="https://img.shields.io/npm/dt/@adminforth/i18n" alt="npm downloads" /></a> <a href="https://www.npmjs.com/package/@adminforth/i18n"><img src="https://img.shields.io/npm/v/@adminforth/i18n" alt="npm version" /></a> <a href="https://www.npmjs.com/package/@adminforth/i18n">
4
+
5
+ Allows to store all translation strings in an adminforth application in a single resource.
6
+
7
+ ## For ussage, see [AdminForth i18n Documentation](https://adminforth.dev/docs/tutorial/Plugins/i18n/)
package/dist/index.js CHANGED
@@ -360,9 +360,8 @@ export default class I18nPlugin extends AdminForthPlugin {
360
360
  icon: 'flowbite:language-outline',
361
361
  // if optional `confirm` is provided, user will be asked to confirm action
362
362
  confirm: 'Are you sure you want to translate selected items?',
363
- state: 'selected',
364
363
  allowed: (_a) => __awaiter(this, [_a], void 0, function* ({ resource, adminUser, selectedIds, allowedActions }) {
365
- console.log('allowedActions', JSON.stringify(allowedActions));
364
+ process.env.HEAVY_DEBUG && console.log('allowedActions', JSON.stringify(allowedActions));
366
365
  return allowedActions.edit;
367
366
  }),
368
367
  action: (_a) => __awaiter(this, [_a], void 0, function* ({ selectedIds, tr }) {
@@ -445,7 +444,8 @@ ${JSON.stringify(strings.reduce((acc, s) => {
445
444
  \`\`\`
446
445
  `;
447
446
  // call OpenAI
448
- const resp = yield this.options.completeAdapter.complete(prompt, [], 300);
447
+ const resp = yield this.options.completeAdapter.complete(prompt, [], prompt.length * 2);
448
+ process.env.HEAVY_DEBUG && console.log(`🪲🔪LLM resp >> ${prompt.length}, <<${resp.content.length} :\n\n`, JSON.stringify(resp));
449
449
  if (resp.error) {
450
450
  throw new AiTranslateError(resp.error);
451
451
  }
@@ -680,7 +680,9 @@ ${JSON.stringify(strings.reduce((acc, s) => {
680
680
  }
681
681
  if (params) {
682
682
  for (const [key, value] of Object.entries(params)) {
683
- result = result.replace(`{${key}}`, value);
683
+ if (result) {
684
+ result = result.replace(`{${key}}`, value);
685
+ }
684
686
  }
685
687
  }
686
688
  return result;
package/index.ts CHANGED
@@ -409,9 +409,8 @@ export default class I18nPlugin extends AdminForthPlugin {
409
409
  icon: 'flowbite:language-outline',
410
410
  // if optional `confirm` is provided, user will be asked to confirm action
411
411
  confirm: 'Are you sure you want to translate selected items?',
412
- state: 'selected',
413
412
  allowed: async ({ resource, adminUser, selectedIds, allowedActions }) => {
414
- console.log('allowedActions', JSON.stringify(allowedActions));
413
+ process.env.HEAVY_DEBUG && console.log('allowedActions', JSON.stringify(allowedActions));
415
414
  return allowedActions.edit;
416
415
  },
417
416
  action: async ({ selectedIds, tr }) => {
@@ -507,9 +506,10 @@ JSON.stringify(strings.reduce((acc: object, s: { en_string: string }): object =>
507
506
  const resp = await this.options.completeAdapter.complete(
508
507
  prompt,
509
508
  [],
510
- 300,
509
+ prompt.length * 2,
511
510
  );
512
511
 
512
+ process.env.HEAVY_DEBUG && console.log(`🪲🔪LLM resp >> ${prompt.length}, <<${resp.content.length} :\n\n`, JSON.stringify(resp));
513
513
 
514
514
  if (resp.error) {
515
515
  throw new AiTranslateError(resp.error);
@@ -803,7 +803,9 @@ JSON.stringify(strings.reduce((acc: object, s: { en_string: string }): object =>
803
803
 
804
804
  if (params) {
805
805
  for (const [key, value] of Object.entries(params)) {
806
- result = result.replace(`{${key}}`, value);
806
+ if (result) {
807
+ result = result.replace(`{${key}}`, value);
808
+ }
807
809
  }
808
810
  }
809
811
  return result;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adminforth/i18n",
3
- "version": "1.2.1",
3
+ "version": "1.2.3",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",