FAQ: contenido bilingüe en un solo campo (marcador === EN ===)

El webhook solo persiste area/Question/Answer, así que el texto lleva las dos
versiones separadas por un marcador y la página muestra la que corresponde al
idioma elegido.
This commit is contained in:
webmanager committed 2026-11-07 17:19:03 +00:00
1 parent 06568c36a6
commit 31bad988e6
1 file changed
+11 -2
+11 -2
View File
@@ -137,6 +137,15 @@ function pick(it, field) {
return it[field] ?? ''; return it[field] ?? '';
} }
// One field, two languages: "texto ES\n=== EN ===\ntext EN"
const LANG_SPLIT = /\n\s*===\s*EN\s*===\s*\n/i;
function content(it, field) {
const raw = pick(it, field);
if (typeof raw !== 'string' || !LANG_SPLIT.test(raw)) return raw;
const parts = raw.split(LANG_SPLIT);
return (state.lang === 'en' ? parts[1] : parts[0]) || parts[0] || '';
}
// Optional language tag on an item (lang / language / idioma) // Optional language tag on an item (lang / language / idioma)
function itemLang(it) { function itemLang(it) {
const key = Object.keys(it).find(k => ['lang', 'language', 'idioma'].includes(k.toLowerCase())); const key = Object.keys(it).find(k => ['lang', 'language', 'idioma'].includes(k.toLowerCase()));
@@ -181,10 +190,10 @@ function render() {
const card = document.createElement('details'); const card = document.createElement('details');
card.className = 'card'; card.className = 'card';
const sum = document.createElement('summary'); const sum = document.createElement('summary');
sum.textContent = pick(it, 'Question') || '—'; sum.textContent = content(it, 'Question') || '—';
const ans = document.createElement('p'); const ans = document.createElement('p');
ans.className = 'ans'; ans.className = 'ans';
ans.textContent = pick(it, 'Answer') || ''; ans.textContent = content(it, 'Answer') || '';
card.append(sum, ans); card.append(sum, ans);
sec.appendChild(card); sec.appendChild(card);
}); });