Widget:C.Translator

De Wiki Gla
Revisão de 21h36min de 31 de dezembro de 2025 por Gurren1 (discussão | contribs) (Criou página com '<!-- TRANSLATOR SYSTEM --> <script> (() => { 'use strict'; const normalizeLang = (s) => { s = (s || '').toLowerCase(); if (s === 'p...')
(dif) ← Edição anterior | Revisão atual (dif) | Versão posterior → (dif)
Ir para navegação Ir para pesquisar

<script>

   (() => {
       'use strict';
       const normalizeLang = (s) => {
           s = (s || ).toLowerCase();
           if (s === 'pt-br' || s === 'pt_br' || s === 'ptbr') return 'pt';
           return (s.split('-')[0] || 'pt');
       };
       const updateSkillsTabLabel = (norm) => {
           const map = { en: 'Skills', pt: 'Habilidades', es: 'Habilidades', pl: 'Umiejętności' };
           const btn = document.querySelector('.character-tabs .tab-btn[data-tab="skills"]');
           if (btn) btn.textContent = map[norm] || map.pt;
       };
       const pickDescFor = (icon, norm) => {
           const keyMap = { pt: 'descPt', en: 'descEn', es: 'descEs', pl: 'descPl' };
           const order = [keyMap[norm], 'descPt', 'descEn', 'descEs', 'descPl'].filter(Boolean);
           for (const k of order) {
               const v = (icon.dataset[k] || ).trim();
               if (v) return v;
           }
           return ;
       };
       const updateAllSkillDescs = (norm) => {
           document.querySelectorAll('.icon-bar .skill-icon').forEach(icon => {
               icon.dataset.desc = pickDescFor(icon, norm);
           });
       };
       const updateTierAndTags = (norm) => {
           const cont = document.querySelector('.class-tags');
           if (!cont) return;
           const tier = cont.querySelector('.class-tag.tier');
           if (tier) {
               const t = tier.getAttribute('data-tier-' + norm)
                   || tier.getAttribute('data-tier-pt')
                   || tier.getAttribute('data-tier-en')
                   || tier.getAttribute('data-tier-es')
                   || tier.getAttribute('data-tier-pl') || ;
               if (t) tier.textContent = t;
           }
           let tags = [];
           const pack = cont.getAttribute('data-tags-i18n');
           if (pack) {
               try {
                   const obj = JSON.parse(pack);
                   const arr = obj?.[norm] || obj?.pt || obj?.en || obj?.es || obj?.pl || [];
                   if (Array.isArray(arr)) tags = arr;
               } catch (e) { }
           }
           if (!tags.length) return;
           cont.querySelectorAll('.class-tag:not(.tier)').forEach(el => el.remove());
           tags.forEach(t => {
               const chip = document.createElement('span');
               chip.className = 'class-tag';
               chip.textContent = t;
               cont.appendChild(chip);
           });
       };
       const updateFlagTooltips = (norm) => {
           const skillsRoot = document.querySelector('#skills');
           if (!skillsRoot) return;
           let pack = {};
           try {
               pack = JSON.parse(skillsRoot.dataset.i18nFlags || '{}');
           } catch (e) { }
           const dict = pack[norm] || pack.pt || {};
           document.querySelectorAll('.skill-flags .skill-flag[data-flag]').forEach(el => {
               const key = el.getAttribute('data-flag');
               const tip = (dict && dict[key]) || ;
               if (tip) el.setAttribute('aria-label', tip);
           });
       };
       const updateAll = (langFull) => {
           const norm = normalizeLang(langFull);
           updateSkillsTabLabel(norm);
           updateAllSkillDescs(norm);
           updateTierAndTags(norm);
           updateFlagTooltips(norm);
       };
       // Listen to language changes
       document.querySelectorAll('.char-flag[data-lang]').forEach(btn => {
           btn.addEventListener('click', () => {
               const lang = btn.getAttribute('data-lang');
               updateAll(lang);
           });
       });
       // Initial update
       const currentLang = document.documentElement.lang || 'pt-br';
       updateAll(currentLang);
   })();

</script>