From ec2c512bde0ce69677c769c8002352e9717e5dc0 Mon Sep 17 00:00:00 2001 From: Dilshan Senarath Date: Wed, 25 Oct 2023 14:53:16 +0530 Subject: [PATCH 1/3] fix the index out of bound issue --- .../webapp/includes/branding-preferences.jsp | 26 ++++++++++++++++--- .../webapp/includes/branding-preferences.jsp | 26 ++++++++++++++++--- 2 files changed, 44 insertions(+), 8 deletions(-) diff --git a/identity-apps-core/apps/authentication-portal/src/main/webapp/includes/branding-preferences.jsp b/identity-apps-core/apps/authentication-portal/src/main/webapp/includes/branding-preferences.jsp index 2863de919a6..45b75e90c75 100644 --- a/identity-apps-core/apps/authentication-portal/src/main/webapp/includes/branding-preferences.jsp +++ b/identity-apps-core/apps/authentication-portal/src/main/webapp/includes/branding-preferences.jsp @@ -66,8 +66,17 @@ if (localeFromCookie != null) { lang = localeFromCookie; try { - String langStr = lang.split("_")[0]; - String langLocale = lang.split("_")[1]; + String langStr = "en"; + String langLocale = "US"; + + if (lang.contains("_")) { + langStr = lang.split("_")[0]; + langLocale = lang.split("_")[1]; + } else if (lang.contains("-")) { + langStr = lang.split("-")[0]; + langLocale = lang.split("-")[1]; + } + userLocale = new Locale(langStr, langLocale); } catch (Exception e) { // In case the language is defined but not in the correct format @@ -75,8 +84,17 @@ } } else if (uiLocaleFromURL != null) { for (String localeStr : uiLocaleFromURL.split(" ")) { - String langStr = localeStr.split("_")[0]; - String langLocale = localeStr.split("_")[1]; + String langStr = "en"; + String langLocale = "US"; + + if (lang.contains("_")) { + langStr = lang.split("_")[0]; + langLocale = lang.split("_")[1]; + } else if (lang.contains("-")) { + langStr = lang.split("-")[0]; + langLocale = lang.split("-")[1]; + } + Locale tempLocale = new Locale(langStr, langLocale); // Trying to find out whether we have a resource bundle for the given locale try { diff --git a/identity-apps-core/apps/recovery-portal/src/main/webapp/includes/branding-preferences.jsp b/identity-apps-core/apps/recovery-portal/src/main/webapp/includes/branding-preferences.jsp index 54142a74b66..c4ed1addb38 100644 --- a/identity-apps-core/apps/recovery-portal/src/main/webapp/includes/branding-preferences.jsp +++ b/identity-apps-core/apps/recovery-portal/src/main/webapp/includes/branding-preferences.jsp @@ -66,8 +66,17 @@ if (localeFromCookie != null) { lang = localeFromCookie; try { - String langStr = lang.split("_")[0]; - String langLocale = lang.split("_")[1]; + String langStr = "en"; + String langLocale = "US"; + + if (lang.contains("_")) { + langStr = lang.split("_")[0]; + langLocale = lang.split("_")[1]; + } else if (lang.contains("-")) { + langStr = lang.split("-")[0]; + langLocale = lang.split("-")[1]; + } + userLocale = new Locale(langStr, langLocale); } catch (Exception e) { // In case the language is defined but not in the correct format @@ -75,8 +84,17 @@ } } else if (uiLocaleFromURL != null) { for (String localeStr : uiLocaleFromURL.split(" ")) { - String langStr = localeStr.split("_")[0]; - String langLocale = localeStr.split("_")[1]; + String langStr = "en"; + String langLocale = "US"; + + if (localeStr.contains("_")) { + langStr = localeStr.split("_")[0]; + langLocale = localeStr.split("_")[1]; + } else if (localeStr.contains("-")) { + langStr = localeStr.split("-")[0]; + langLocale = localeStr.split("-")[1]; + } + Locale tempLocale = new Locale(langStr, langLocale); // Trying to find out whether we have a resource bundle for the given locale try { From 1e781d0f265670bb695958893b86ae22d8b0e340 Mon Sep 17 00:00:00 2001 From: Dilshan Senarath Date: Wed, 25 Oct 2023 19:09:43 +0530 Subject: [PATCH 2/3] update the ui_locales resloving logic --- .../src/main/webapp/includes/localize.jsp | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/identity-apps-core/apps/authentication-portal/src/main/webapp/includes/localize.jsp b/identity-apps-core/apps/authentication-portal/src/main/webapp/includes/localize.jsp index 56a7e3187c9..850b1432a09 100644 --- a/identity-apps-core/apps/authentication-portal/src/main/webapp/includes/localize.jsp +++ b/identity-apps-core/apps/authentication-portal/src/main/webapp/includes/localize.jsp @@ -49,8 +49,16 @@ lang = localeFromCookie; try { - String langStr = lang.split("_")[0]; - String langLocale = lang.split("_")[1]; + String langStr = "en"; + String langLocale = "US"; + + if (lang.contains("_")) { + langStr = lang.split("_")[0]; + langLocale = lang.split("_")[1]; + } else if (lang.contains("-")) { + langStr = lang.split("-")[0]; + langLocale = lang.split("-")[1]; + } userLocale = new Locale(langStr, langLocale); } catch (Exception e) { @@ -59,8 +67,16 @@ } } else if (uiLocaleFromURL != null) { for (String localeStr : uiLocaleFromURL.split(" ")) { - String langStr = localeStr.split("_")[0]; - String langLocale = localeStr.split("_")[1]; + String langStr = "en"; + String langLocale = "US"; + + if (localeStr.contains("_")) { + langStr = localeStr.split("_")[0]; + langLocale = localeStr.split("_")[1]; + } else if (localeStr.contains("-")) { + langStr = localeStr.split("-")[0]; + langLocale = localeStr.split("-")[1]; + } Locale tempLocale = new Locale(langStr, langLocale); From 77f6e16f1fc8d100455c0e38b484237e32d4c085 Mon Sep 17 00:00:00 2001 From: Dilshan Senarath Date: Wed, 25 Oct 2023 19:10:57 +0530 Subject: [PATCH 3/3] =?UTF-8?q?Add=20changeset=20=F0=9F=A6=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .changeset/strange-foxes-invent.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/strange-foxes-invent.md diff --git a/.changeset/strange-foxes-invent.md b/.changeset/strange-foxes-invent.md new file mode 100644 index 00000000000..532c354c3c6 --- /dev/null +++ b/.changeset/strange-foxes-invent.md @@ -0,0 +1,5 @@ +--- +"@wso2is/identity-apps-core": patch +--- + +Update the ui_locales resolving logic