Class DirectionResolver

java.lang.Object
com.oorian.i18n.DirectionResolver

public final class DirectionResolver extends Object
Resolves text direction (LTR/RTL) from a Locale.

Maintains a set of known right-to-left language codes and provides methods to determine the appropriate TextDirection for any locale. This is used to set the HTML dir attribute and apply directional CSS.

Known RTL languages: Arabic, Hebrew, Persian (Farsi), Urdu, Yiddish, Syriac, Thaana (Dhivehi), N'Ko, and Samaritan.

Usage:


 // Check the current locale
 TextDirection dir = DirectionResolver.resolve(OorianLocale.get());
 // → TextDirection.RTL for Arabic, TextDirection.LTR for English

 // Quick RTL check
 if (DirectionResolver.isRtl(OorianLocale.get()))
 {
     // Apply RTL-specific layout
 }

 // Get direction for the current thread's locale
 TextDirection dir = DirectionResolver.resolveCurrentLocale();
 
Since:
2.1
Version:
1.0
Author:
Marvin P. Warble Jr.
See Also:
  • Method Details

    • resolve

      public static TextDirection resolve(Locale locale)
      Resolves the text direction for the given locale.
      Parameters:
      locale - the locale to check
      Returns:
      TextDirection.RTL if the locale's language is right-to-left, TextDirection.LTR otherwise
    • resolveCurrentLocale

      public static TextDirection resolveCurrentLocale()
      Resolves the text direction for the current thread's locale.

      Uses OorianLocale.get() to determine the active locale.

      Returns:
      the text direction for the current locale
    • isRtl

      public static boolean isRtl(Locale locale)
      Checks whether the given locale uses a right-to-left script.
      Parameters:
      locale - the locale to check
      Returns:
      true if the locale is RTL
    • isCurrentLocaleRtl

      public static boolean isCurrentLocaleRtl()
      Checks whether the current thread's locale uses a right-to-left script.
      Returns:
      true if the current locale is RTL
    • getHtmlDir

      public static String getHtmlDir(Locale locale)
      Returns the HTML dir attribute value for the given locale.

      Convenience method equivalent to resolve(locale).getValue().

      Parameters:
      locale - the locale to check
      Returns:
      "rtl" or "ltr"
    • getRtlLanguages

      public static Set<String> getRtlLanguages()
      Returns an unmodifiable set of all known RTL language codes.
      Returns:
      the set of RTL language codes (ISO 639)