From 53c72d87f2678f7a5ae67ecf2b447e66e04c7397 Mon Sep 17 00:00:00 2001 From: Rishi Mehta Date: Thu, 21 Aug 2025 12:06:48 +0530 Subject: [PATCH] Fixing language 404 error --- .../container/clientlibs/site/js/formcontainerview.js | 7 +++++-- .../container/clientlibs/site/js/formcontainerview.js | 7 +++++-- ui.frontend/src/LanguageUtils.js | 10 +++++++++- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/it/apps/src/main/content/jcr_root/apps/forms-core-components-it/components/container/v1/container/clientlibs/site/js/formcontainerview.js b/it/apps/src/main/content/jcr_root/apps/forms-core-components-it/components/container/v1/container/clientlibs/site/js/formcontainerview.js index bfa5e296c7..8a10597e30 100644 --- a/it/apps/src/main/content/jcr_root/apps/forms-core-components-it/components/container/v1/container/clientlibs/site/js/formcontainerview.js +++ b/it/apps/src/main/content/jcr_root/apps/forms-core-components-it/components/container/v1/container/clientlibs/site/js/formcontainerview.js @@ -150,8 +150,11 @@ // before initializing the form container load all the locale specific json resources // for runtime const formLanguage = formContainer.getLang(); - const aemLangUrl = `/etc.clientlibs/core/fd/af-clientlibs/core-forms-components-runtime-all/resources/i18n/${formLanguage}.json`; - await FormView.LanguageUtils.loadLang(formLanguage, aemLangUrl, true); + // Only load locale if it's a valid product locale + if (FormView.LanguageUtils.isProductLocale(formLanguage)) { + const aemLangUrl = `/etc.clientlibs/core/fd/af-clientlibs/core-forms-components-runtime-all/resources/i18n/${formLanguage}.json`; + await FormView.LanguageUtils.loadLang(formLanguage, aemLangUrl, true); + } formContainer.subscribe(); return formContainer; }, FormContainerV2.selectors.self, FormContainerV2.IS); diff --git a/ui.af.apps/src/main/content/jcr_root/apps/core/fd/components/form/container/v2/container/clientlibs/site/js/formcontainerview.js b/ui.af.apps/src/main/content/jcr_root/apps/core/fd/components/form/container/v2/container/clientlibs/site/js/formcontainerview.js index 177f5853e9..2f487b2900 100644 --- a/ui.af.apps/src/main/content/jcr_root/apps/core/fd/components/form/container/v2/container/clientlibs/site/js/formcontainerview.js +++ b/ui.af.apps/src/main/content/jcr_root/apps/core/fd/components/form/container/v2/container/clientlibs/site/js/formcontainerview.js @@ -141,8 +141,11 @@ // before initializing the form container load all the locale specific json resources // for runtime const formLanguage = formContainer.getLang(); - const aemLangUrl = `/etc.clientlibs/core/fd/af-clientlibs/core-forms-components-runtime-all/resources/i18n/${formLanguage}.json`; - await FormView.LanguageUtils.loadLang(formLanguage, aemLangUrl, true); + // Only load locale if it's a valid product locale + if (FormView.LanguageUtils.isProductLocale(formLanguage)) { + const aemLangUrl = `/etc.clientlibs/core/fd/af-clientlibs/core-forms-components-runtime-all/resources/i18n/${formLanguage}.json`; + await FormView.LanguageUtils.loadLang(formLanguage, aemLangUrl, true); + } formContainer.subscribe(); return formContainer; }, FormContainerV2.selectors.self, FormContainerV2.IS); diff --git a/ui.frontend/src/LanguageUtils.js b/ui.frontend/src/LanguageUtils.js index 0fdd8a6491..2a15b957f0 100644 --- a/ui.frontend/src/LanguageUtils.js +++ b/ui.frontend/src/LanguageUtils.js @@ -70,7 +70,15 @@ class LanguageUtils { } } - + /** + * Check if the given locale is a valid product locale. + * @param {string} lang - The language code to check. + * @returns {boolean} True if the locale is a valid product locale, false otherwise. + */ + static isProductLocale(lang) { + const productLocales = ['en', 'de', 'es', 'fr', 'it', 'ja', 'ko-kr', 'pt-br', 'zh-cn', 'zh-tw']; + return productLocales.includes(lang); + } /** * Returns the translated string for the given language and key.