diff --git a/services/src/main/java/org/keycloak/theme/beans/LocaleBean.java b/services/src/main/java/org/keycloak/theme/beans/LocaleBean.java index 81eaa95703..99b2cdac1a 100755 --- a/services/src/main/java/org/keycloak/theme/beans/LocaleBean.java +++ b/services/src/main/java/org/keycloak/theme/beans/LocaleBean.java @@ -20,9 +20,11 @@ package org.keycloak.theme.beans; import org.keycloak.models.RealmModel; import jakarta.ws.rs.core.UriBuilder; + import java.text.Collator; import java.util.List; import java.util.Properties; +import java.util.Set; import java.util.stream.Collectors; /** @@ -30,13 +32,18 @@ import java.util.stream.Collectors; */ public class LocaleBean { + private static final Set RTL_LANGUAGE_CODES = + Set.of("ar", "dv", "fa", "ha", "he", "iw", "ji", "ps", "sd", "ug", "ur", "yi"); + private String current; private String currentLanguageTag; + private boolean rtl; // right-to-left language private List supported; public LocaleBean(RealmModel realm, java.util.Locale current, UriBuilder uriBuilder, Properties messages) { this.currentLanguageTag = current.toLanguageTag(); this.current = messages.getProperty("locale_" + this.currentLanguageTag, this.currentLanguageTag); + this.rtl = RTL_LANGUAGE_CODES.contains(current.getLanguage()); Collator collator = Collator.getInstance(current); collator.setStrength(Collator.PRIMARY); // ignore case and accents @@ -59,6 +66,13 @@ public class LocaleBean { return currentLanguageTag; } + /** + * Whether it is Right-to-Left language or not. + */ + public boolean isRtl() { + return rtl; + } + public List getSupported() { return supported; } diff --git a/themes/src/main/resources/theme/base/login/login-config-totp.ftl b/themes/src/main/resources/theme/base/login/login-config-totp.ftl index 5b21da49cf..d531eba0ff 100755 --- a/themes/src/main/resources/theme/base/login/login-config-totp.ftl +++ b/themes/src/main/resources/theme/base/login/login-config-totp.ftl @@ -58,6 +58,7 @@
<#if messagesPerField.existsError('totp')> @@ -78,7 +79,7 @@
<#if messagesPerField.existsError('userLabel')> diff --git a/themes/src/main/resources/theme/base/login/login-oauth2-device-verify-user-code.ftl b/themes/src/main/resources/theme/base/login/login-oauth2-device-verify-user-code.ftl index dfb625fe8b..f254254a89 100644 --- a/themes/src/main/resources/theme/base/login/login-oauth2-device-verify-user-code.ftl +++ b/themes/src/main/resources/theme/base/login/login-oauth2-device-verify-user-code.ftl @@ -10,7 +10,7 @@
- +
diff --git a/themes/src/main/resources/theme/base/login/login-otp.ftl b/themes/src/main/resources/theme/base/login/login-otp.ftl index a43778d900..f187fb6cbb 100755 --- a/themes/src/main/resources/theme/base/login/login-otp.ftl +++ b/themes/src/main/resources/theme/base/login/login-otp.ftl @@ -30,7 +30,8 @@
+ autofocus aria-invalid="<#if messagesPerField.existsError('totp')>true" + dir="ltr" /> <#if messagesPerField.existsError('totp')> + type="text" autofocus autocomplete="off" + dir="ltr"/> <#if messagesPerField.existsError('username')> ${kcSanitize(messagesPerField.get('username'))?no_esc} diff --git a/themes/src/main/resources/theme/base/login/login-password.ftl b/themes/src/main/resources/theme/base/login/login-password.ftl index aa984b1a90..1c591186ac 100755 --- a/themes/src/main/resources/theme/base/login/login-password.ftl +++ b/themes/src/main/resources/theme/base/login/login-password.ftl @@ -10,7 +10,7 @@

-
+
+ autofocus + dir="ltr"/> <#if messagesPerField.existsError('recoveryCodeInput')> diff --git a/themes/src/main/resources/theme/base/login/login-reset-password.ftl b/themes/src/main/resources/theme/base/login/login-reset-password.ftl index 800faea1f0..8e96fb4a9f 100755 --- a/themes/src/main/resources/theme/base/login/login-reset-password.ftl +++ b/themes/src/main/resources/theme/base/login/login-reset-password.ftl @@ -9,7 +9,7 @@
- + <#if messagesPerField.existsError('username')> ${kcSanitize(messagesPerField.get('username'))?no_esc} diff --git a/themes/src/main/resources/theme/base/login/login-update-password.ftl b/themes/src/main/resources/theme/base/login/login-update-password.ftl index f6414ec9f8..4861f447f3 100755 --- a/themes/src/main/resources/theme/base/login/login-update-password.ftl +++ b/themes/src/main/resources/theme/base/login/login-update-password.ftl @@ -10,7 +10,7 @@
-
+
${msg("passwordConfirm")}
-
+
+ type="text" autofocus autocomplete="off" + dir="ltr"/> <#if messagesPerField.existsError('username')> diff --git a/themes/src/main/resources/theme/base/login/login.ftl b/themes/src/main/resources/theme/base/login/login.ftl index a7361e9f46..e50b1be03f 100755 --- a/themes/src/main/resources/theme/base/login/login.ftl +++ b/themes/src/main/resources/theme/base/login/login.ftl @@ -13,6 +13,7 @@ <#if messagesPerField.existsError('username','password')> @@ -27,7 +28,7 @@
-
+
diff --git a/themes/src/main/resources/theme/base/login/register.ftl b/themes/src/main/resources/theme/base/login/register.ftl index f640848683..a122f6f996 100755 --- a/themes/src/main/resources/theme/base/login/register.ftl +++ b/themes/src/main/resources/theme/base/login/register.ftl @@ -20,7 +20,7 @@ *
-
+
${msg("passwordConfirm")} *
-
+
- lang="${locale.currentLanguageTag}"> + lang="${locale.currentLanguageTag}" dir="${(locale.rtl)?then('rtl','ltr')}"> diff --git a/themes/src/main/resources/theme/keycloak.v2/login/login-config-totp.ftl b/themes/src/main/resources/theme/keycloak.v2/login/login-config-totp.ftl index 644df4df2f..d6a0ccc4bf 100755 --- a/themes/src/main/resources/theme/keycloak.v2/login/login-config-totp.ftl +++ b/themes/src/main/resources/theme/keycloak.v2/login/login-config-totp.ftl @@ -60,6 +60,7 @@
<#if messagesPerField.existsError('totp')> @@ -88,6 +89,7 @@
<#if messagesPerField.existsError('userLabel')> diff --git a/themes/src/main/resources/theme/keycloak.v2/login/login-update-password.ftl b/themes/src/main/resources/theme/keycloak.v2/login/login-update-password.ftl index b08d753973..40cc7a082c 100755 --- a/themes/src/main/resources/theme/keycloak.v2/login/login-update-password.ftl +++ b/themes/src/main/resources/theme/keycloak.v2/login/login-update-password.ftl @@ -12,7 +12,7 @@
- + @@ -39,7 +39,7 @@
- + <#if messagesPerField.existsError('username','password')> @@ -42,7 +43,7 @@ ${msg("password")} -
+
- +
-
+
- lang="${locale.currentLanguageTag}"> + lang="${locale.currentLanguageTag}" dir="${(locale.rtl)?then('rtl','ltr')}">