wineater-bot 3.7.0 → 3.8.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.
package/index.html CHANGED
@@ -4,7 +4,7 @@
4
4
  <meta charset="UTF-8">
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
6
  <title>Chatbot</title>
7
- <script>window.wineaterData = {CLIENT_TOKEN: 'dRBwg6wB6LeEKFUiLHdlXa84TgSVDuR8HhE0hhq1l4vVeq3cE12DJkPDwXvuhT01', TYPE: 'widget', WIDGET_TYPE: 'store', WIDGET_WRAPPER: 'wineater-widget-conteiner'};</script>
7
+ <script>window.wineaterData = {CLIENT_TOKEN: 'OjvAprylAugk5pKTHRIzZxcPPb6HMPr9qHhrazG0sF3uHjkrvBzufPZ65igfRJJa', TYPE: 'widget', WIDGET_TYPE: 'bar', WIDGET_WRAPPER: 'wineater-widget-conteiner'};</script>
8
8
  <!-- <script type="module" src="./dist/wineater-chatbot.umd.js"></script> -->
9
9
  <script type="module" src="./src/index.js"></script>
10
10
  </head>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wineater-bot",
3
- "version": "3.7.0",
3
+ "version": "3.8.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "src/index.js",
package/src/js/i18n.js CHANGED
@@ -614,7 +614,7 @@ class Translator {
614
614
  const texts = Object.values(textObject);
615
615
  const joinedText = texts.join(' ||| ');
616
616
 
617
- const prompt = `Translate the following texts to ${this.language}. Return only the translated texts separated by " ||| " in the same order:
617
+ const prompt = `Translate the following texts to language with the next code: ${this.language}. Return only the translated texts separated by " ||| " in the same order:
618
618
 
619
619
  ${joinedText}`;
620
620
 
package/src/js/widget.js CHANGED
@@ -399,54 +399,59 @@ export class WineWidget {
399
399
  if (translator.language === translator.storeLanguage || this.widgetType !== 'bar') {
400
400
  return;
401
401
  }
402
- const fieldsToTranslate = ['Short Description', 'reason', 'pairing_recommendation', 'Tags'];
403
- const language = translator.language;
404
-
405
- const batchSize = 4;
406
- for (let i = 0; i < wines.length; i += batchSize) {
407
- const batch = wines.slice(i, i + batchSize);
408
-
409
- const translationPromises = batch.map(async (wine, index) => {
410
- const globalIndex = i + index;
411
- const textObject = {};
412
-
413
- fieldsToTranslate.forEach(field => {
414
- const val = wine[field] || wine[field.toLowerCase()];
415
- if (val) textObject[field] = Array.isArray(val) ? val.join(', ') : val;
416
- });
417
-
418
- if (Object.keys(textObject).length === 0) return;
419
-
420
- const translated = await translator.translateTexts(textObject);
421
-
422
- const popup = document.querySelector(`.card-popup[data-wine-index="${globalIndex}"]`);
423
- if (!popup) return;
424
-
425
- if (translated['Short Description']) {
426
- const el = popup.querySelector('.popup-short-desc');
427
- if (el) el.textContent = translated['Short Description'];
428
- }
429
-
430
- if (translated.reason) {
431
- const el = popup.querySelector('.popup-reason');
432
- if (el) el.textContent = translated.reason;
433
- }
434
-
435
- if (translated.pairing_recommendation) {
436
- const el = popup.querySelector('.popup-pairing');
437
- if (el) el.textContent = translated.pairing_recommendation;
438
- }
439
-
440
- if (translated.Tags) {
441
- const tagsArray = translated.Tags.split(',').map(tag => tag.trim());
442
- const tagHTML = tagsArray.map(tag => `<span class="popup-tag">${tag}</span>`).join('');
443
- const tagsContainer = popup.querySelector('.popup-tags');
444
- if (tagsContainer) tagsContainer.innerHTML = tagHTML;
445
- }
446
- });
447
-
448
- // Ждём выполнения всей пачки
449
- await Promise.all(translationPromises);
402
+ const possibleFields = ['Short Description', 'reason', 'pairing_recommendation', 'Tags', 'tags'];
403
+ const firstWine = wines[0];
404
+
405
+ // Фильтруем по реально существующим ключам в первом объекте
406
+ const fieldsToTranslate = possibleFields.filter(field => field in firstWine);
407
+
408
+ const language = translator.language;
409
+ const batchSize = 4;
410
+
411
+ for (let i = 0; i < wines.length; i += batchSize) {
412
+ const batch = wines.slice(i, i + batchSize);
413
+
414
+ const translationPromises = batch.map(async (wine, index) => {
415
+ const globalIndex = i + index;
416
+ const textObject = {};
417
+
418
+ fieldsToTranslate.forEach(field => {
419
+ const val = wine[field] || wine[field.toLowerCase()];
420
+ if (val) textObject[field] = Array.isArray(val) ? val.join(', ') : val;
421
+ });
422
+
423
+ if (Object.keys(textObject).length === 0) return;
424
+
425
+ const translated = await translator.translateTexts(textObject);
426
+
427
+ const popup = document.querySelector(`.card-popup[data-wine-index="${globalIndex}"]`);
428
+ if (!popup) return;
429
+
430
+ if (translated['Short Description']) {
431
+ const el = popup.querySelector('.popup-short-desc');
432
+ if (el) el.textContent = translated['Short Description'];
433
+ }
434
+
435
+ if (translated.reason) {
436
+ const el = popup.querySelector('.popup-reason');
437
+ if (el) el.textContent = translated.reason;
438
+ }
439
+
440
+ if (translated.pairing_recommendation) {
441
+ const el = popup.querySelector('.popup-pairing');
442
+ if (el) el.textContent = translated.pairing_recommendation;
443
+ }
444
+
445
+ if (translated.tags || translated.Tags) {
446
+ const tagsString = translated.tags || translated.Tags;
447
+ const tagsArray = tagsString.split(',').map(tag => tag.trim());
448
+ const tagHTML = tagsArray.map(tag => `<span class="popup-tag">${tag}</span>`).join('');
449
+ const tagsContainer = popup.querySelector('.popup-tags');
450
+ if (tagsContainer) tagsContainer.innerHTML = tagHTML;
451
+ }
452
+ });
453
+
454
+ await Promise.all(translationPromises);
450
455
  }
451
456
  }
452
457