@bebranded/bb-contents 1.0.31-beta → 1.0.32-beta

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 (2) hide show
  1. package/bb-contents.js +53 -15
  2. package/package.json +1 -1
package/bb-contents.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * BeBranded Contents
3
3
  * Contenus additionnels français pour Webflow
4
- * @version 1.0.31-beta
4
+ * @version 1.0.32-beta
5
5
  * @author BeBranded
6
6
  * @license MIT
7
7
  * @website https://www.bebranded.xyz
@@ -17,7 +17,7 @@
17
17
 
18
18
  // Configuration
19
19
  const config = {
20
- version: '1.0.31-beta',
20
+ version: '1.0.32-beta',
21
21
  debug: false, // Désactivé par défaut pour une console propre
22
22
  prefix: 'bb-', // utilisé pour générer les sélecteurs (data-bb-*)
23
23
  i18n: {
@@ -608,6 +608,7 @@
608
608
  const channelId = bbContents._getAttr(element, 'bb-youtube-channel');
609
609
  const videoCount = bbContents._getAttr(element, 'bb-youtube-video-count') || '10';
610
610
  const allowShorts = bbContents._getAttr(element, 'bb-youtube-allow-shorts') === 'true';
611
+ const language = bbContents._getAttr(element, 'bb-youtube-language') || 'fr';
611
612
  const endpoint = bbContents.config.youtubeEndpoint;
612
613
 
613
614
  if (!channelId) {
@@ -647,12 +648,12 @@
647
648
  element.setAttribute('data-bb-youtube-processed', 'true');
648
649
 
649
650
  // Vérifier le cache d'abord
650
- const cacheKey = `youtube_${channelId}_${videoCount}_${allowShorts}`;
651
+ const cacheKey = `youtube_${channelId}_${videoCount}_${allowShorts}_${language}`;
651
652
  const cachedData = this.cache.get(cacheKey);
652
653
 
653
654
  if (cachedData) {
654
655
  bbContents.utils.log('Données YouTube récupérées du cache (économie API)');
655
- this.generateYouTubeFeed(container, template, cachedData, allowShorts);
656
+ this.generateYouTubeFeed(container, template, cachedData, allowShorts, language);
656
657
  return;
657
658
  }
658
659
 
@@ -676,7 +677,7 @@
676
677
  this.cache.set(cacheKey, data);
677
678
  bbContents.utils.log('Données YouTube mises en cache pour 24h (économie API)');
678
679
 
679
- this.generateYouTubeFeed(container, template, data, allowShorts);
680
+ this.generateYouTubeFeed(container, template, data, allowShorts, language);
680
681
  })
681
682
  .catch(error => {
682
683
  bbContents.utils.log('Erreur dans le module youtube:', error);
@@ -699,7 +700,7 @@
699
700
  });
700
701
  },
701
702
 
702
- generateYouTubeFeed: function(container, template, data, allowShorts) {
703
+ generateYouTubeFeed: function(container, template, data, allowShorts, language = 'fr') {
703
704
  if (!data.items || data.items.length === 0) {
704
705
  container.innerHTML = '<div style="padding: 20px; text-align: center; color: #6b7280;">Aucune vidéo trouvée</div>';
705
706
  return;
@@ -728,7 +729,7 @@
728
729
  clone.style.display = ''; // Rendre visible
729
730
 
730
731
  // Remplir les données
731
- this.fillVideoData(clone, videoId, snippet);
732
+ this.fillVideoData(clone, videoId, snippet, language);
732
733
 
733
734
  // Ajouter au conteneur
734
735
  container.appendChild(clone);
@@ -737,7 +738,7 @@
737
738
  bbContents.utils.log(`YouTube Feed généré: ${videos.length} vidéos`);
738
739
  },
739
740
 
740
- fillVideoData: function(element, videoId, snippet) {
741
+ fillVideoData: function(element, videoId, snippet, language = 'fr') {
741
742
  // Remplir le lien directement sur l'élément (link block)
742
743
  if (element.tagName === 'A' || element.hasAttribute('bb-youtube-item')) {
743
744
  element.href = `https://www.youtube.com/watch?v=${videoId}`;
@@ -802,7 +803,7 @@
802
803
  // Remplir la date
803
804
  const date = element.querySelector('[bb-youtube-date]');
804
805
  if (date) {
805
- date.textContent = this.formatDate(snippet.publishedAt);
806
+ date.textContent = this.formatDate(snippet.publishedAt, language);
806
807
  }
807
808
 
808
809
  // Remplir le nom de la chaîne
@@ -812,17 +813,54 @@
812
813
  }
813
814
  },
814
815
 
815
- formatDate: function(dateString) {
816
+ formatDate: function(dateString, language = 'fr') {
816
817
  const date = new Date(dateString);
817
818
  const now = new Date();
818
819
  const diffTime = Math.abs(now - date);
819
820
  const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
820
821
 
821
- if (diffDays === 1) return 'Il y a 1 jour';
822
- if (diffDays < 7) return `Il y a ${diffDays} jours`;
823
- if (diffDays < 30) return `Il y a ${Math.floor(diffDays / 7)} semaines`;
824
- if (diffDays < 365) return `Il y a ${Math.floor(diffDays / 30)} mois`;
825
- return `Il y a ${Math.floor(diffDays / 365)} ans`;
822
+ // Traductions
823
+ const translations = {
824
+ fr: {
825
+ day: 'jour',
826
+ days: 'jours',
827
+ week: 'semaine',
828
+ weeks: 'semaines',
829
+ month: 'mois',
830
+ months: 'mois',
831
+ year: 'an',
832
+ years: 'ans',
833
+ ago: 'Il y a'
834
+ },
835
+ en: {
836
+ day: 'day',
837
+ days: 'days',
838
+ week: 'week',
839
+ weeks: 'weeks',
840
+ month: 'month',
841
+ months: 'months',
842
+ year: 'year',
843
+ years: 'years',
844
+ ago: 'ago'
845
+ }
846
+ };
847
+
848
+ const t = translations[language] || translations.fr;
849
+
850
+ if (diffDays === 1) return `${t.ago} 1 ${t.day}`;
851
+ if (diffDays < 7) return `${t.ago} ${diffDays} ${t.days}`;
852
+
853
+ const weeks = Math.floor(diffDays / 7);
854
+ if (weeks === 1) return `${t.ago} 1 ${t.week}`;
855
+ if (diffDays < 30) return `${t.ago} ${weeks} ${t.weeks}`;
856
+
857
+ const months = Math.floor(diffDays / 30);
858
+ if (months === 1) return `${t.ago} 1 ${t.month}`;
859
+ if (diffDays < 365) return `${t.ago} ${months} ${t.months}`;
860
+
861
+ const years = Math.floor(diffDays / 365);
862
+ if (years === 1) return `${t.ago} 1 ${t.year}`;
863
+ return `${t.ago} ${years} ${t.years}`;
826
864
  },
827
865
 
828
866
  // Fonction pour décoder les entités HTML
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bebranded/bb-contents",
3
- "version": "1.0.31-beta",
3
+ "version": "1.0.32-beta",
4
4
  "description": "Contenus additionnels français pour Webflow",
5
5
  "main": "bb-contents.js",
6
6
  "scripts": {