From da223f49f7e07ef2a94de0d4b075a9d5b049cf20 Mon Sep 17 00:00:00 2001 From: diodiogod <160325160+diodiogod@users.noreply.github.com> Date: Fri, 31 Oct 2025 18:38:58 -0300 Subject: [PATCH] Fix language code detection: load supported languages on module init Ensure SUPPORTED_LANGUAGES in language-constants.js is populated with all 55 codes before event handlers run, so isLanguageCode() works correctly. Prevents duplicate language codes like [hr:|hr:|...] by properly detecting language codes vs parameters. --- web/widget-event-handlers.js | 4 ++-- web/widget-ui-builder.js | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/web/widget-event-handlers.js b/web/widget-event-handlers.js index 8ab599e1..07964eb5 100644 --- a/web/widget-event-handlers.js +++ b/web/widget-event-handlers.js @@ -215,8 +215,8 @@ export function attachAllEventHandlers( if (isLanguageCode(beforeColon)) { // It's already a language tag - only update if language is different if (beforeColon === lang) { - // Same language already exists, don't add duplicate - return null; + // Same language already exists, return unchanged + return tagContent; } else { // Replace the language part with new language const charPart = firstPart.substring(colonIndex + 1); diff --git a/web/widget-ui-builder.js b/web/widget-ui-builder.js index eaa5afef..ac7d3a15 100644 --- a/web/widget-ui-builder.js +++ b/web/widget-ui-builder.js @@ -5,6 +5,10 @@ */ import { TagUtilities } from "./tag-utilities.js"; +import { loadSupportedLanguages } from "./language-constants.js"; + +// Load supported languages into memory on module load +loadSupportedLanguages(); export function buildHistorySection(state, storageKey) { const historySection = document.createElement("div");