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/dist/wineater-chatbot.mjs +312 -312
- package/dist/wineater-chatbot.umd.js +22 -22
- package/index.html +1 -1
- package/package.json +1 -1
- package/src/js/i18n.js +1 -1
- package/src/js/widget.js +53 -48
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: '
|
|
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
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
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
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
|
|