LocaleUtil { public static int getLayoutDirectionFromLocale(Locale locale) { if (locale != null && !locale.equals(Locale.ROOT)) { final String scriptSubtag = ICU.getScript(ICU.addLikelySubtags(locale.toString())); if (scriptSubtag == null) return getLayoutDirectionFromFirstChar(locale); if (scriptSubtag.equalsIgnoreCase(ARAB_SCRIPT_SUBTAG) || scriptSubtag.equalsIgnoreCase(HEBR_SCRIPT_SUBTAG)) { return TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE; } } return TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE; } private  LocaleUtil(); static int getLayoutDirectionFromLocale(Locale locale); static final int TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE; static final int TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE; }
@TestTargetNew( level = TestLevel.COMPLETE, method = "getLayoutDirectionFromLocale", args = {Locale.class} ) public void testGetLayoutDirectionFromLocale() { assertEquals(TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE, LocaleUtil.getLayoutDirectionFromLocale(null)); assertEquals(TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE, LocaleUtil.getLayoutDirectionFromLocale(Locale.ENGLISH)); assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE, LocaleUtil.getLayoutDirectionFromLocale(Locale.CANADA)); assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE, LocaleUtil.getLayoutDirectionFromLocale(Locale.CANADA_FRENCH)); assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE, LocaleUtil.getLayoutDirectionFromLocale(Locale.FRANCE)); assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE, LocaleUtil.getLayoutDirectionFromLocale(Locale.FRENCH)); assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE, LocaleUtil.getLayoutDirectionFromLocale(Locale.GERMAN)); assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE, LocaleUtil.getLayoutDirectionFromLocale(Locale.GERMANY)); assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE, LocaleUtil.getLayoutDirectionFromLocale(Locale.ITALIAN)); assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE, LocaleUtil.getLayoutDirectionFromLocale(Locale.ITALY)); assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE, LocaleUtil.getLayoutDirectionFromLocale(Locale.UK)); assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE, LocaleUtil.getLayoutDirectionFromLocale(Locale.US)); assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE, LocaleUtil.getLayoutDirectionFromLocale(Locale.ROOT)); assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE, LocaleUtil.getLayoutDirectionFromLocale(Locale.CHINA)); assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE, LocaleUtil.getLayoutDirectionFromLocale(Locale.CHINESE)); assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE, LocaleUtil.getLayoutDirectionFromLocale(Locale.JAPAN)); assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE, LocaleUtil.getLayoutDirectionFromLocale(Locale.JAPANESE)); assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE, LocaleUtil.getLayoutDirectionFromLocale(Locale.KOREA)); assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE, LocaleUtil.getLayoutDirectionFromLocale(Locale.KOREAN)); assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE, LocaleUtil.getLayoutDirectionFromLocale(Locale.PRC)); assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE, LocaleUtil.getLayoutDirectionFromLocale(Locale.SIMPLIFIED_CHINESE)); assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE, LocaleUtil.getLayoutDirectionFromLocale(Locale.TAIWAN)); assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE, LocaleUtil.getLayoutDirectionFromLocale(Locale.TRADITIONAL_CHINESE)); Locale locale = new Locale("ar"); assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE, LocaleUtil.getLayoutDirectionFromLocale(locale)); locale = new Locale("ar", "AE"); assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE, LocaleUtil.getLayoutDirectionFromLocale(locale)); locale = new Locale("ar", "BH"); assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE, LocaleUtil.getLayoutDirectionFromLocale(locale)); locale = new Locale("ar", "DZ"); assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE, LocaleUtil.getLayoutDirectionFromLocale(locale)); locale = new Locale("ar", "EG"); assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE, LocaleUtil.getLayoutDirectionFromLocale(locale)); locale = new Locale("ar", "IQ"); assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE, LocaleUtil.getLayoutDirectionFromLocale(locale)); locale = new Locale("ar", "JO"); assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE, LocaleUtil.getLayoutDirectionFromLocale(locale)); locale = new Locale("ar", "KW"); assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE, LocaleUtil.getLayoutDirectionFromLocale(locale)); locale = new Locale("ar", "LB"); assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE, LocaleUtil.getLayoutDirectionFromLocale(locale)); locale = new Locale("ar", "LY"); assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE, LocaleUtil.getLayoutDirectionFromLocale(locale)); locale = new Locale("ar", "MA"); assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE, LocaleUtil.getLayoutDirectionFromLocale(locale)); locale = new Locale("ar", "OM"); assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE, LocaleUtil.getLayoutDirectionFromLocale(locale)); locale = new Locale("ar", "QA"); assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE, LocaleUtil.getLayoutDirectionFromLocale(locale)); locale = new Locale("ar", "SA"); assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE, LocaleUtil.getLayoutDirectionFromLocale(locale)); locale = new Locale("ar", "SD"); assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE, LocaleUtil.getLayoutDirectionFromLocale(locale)); locale = new Locale("ar", "SY"); assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE, LocaleUtil.getLayoutDirectionFromLocale(locale)); locale = new Locale("ar", "TN"); assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE, LocaleUtil.getLayoutDirectionFromLocale(locale)); locale = new Locale("ar", "YE"); assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE, LocaleUtil.getLayoutDirectionFromLocale(locale)); locale = new Locale("fa"); assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE, LocaleUtil.getLayoutDirectionFromLocale(locale)); locale = new Locale("fa", "AF"); assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE, LocaleUtil.getLayoutDirectionFromLocale(locale)); locale = new Locale("fa", "IR"); assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE, LocaleUtil.getLayoutDirectionFromLocale(locale)); locale = new Locale("iw"); assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE, LocaleUtil.getLayoutDirectionFromLocale(locale)); locale = new Locale("iw", "IL"); assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE, LocaleUtil.getLayoutDirectionFromLocale(locale)); locale = new Locale("he"); assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE, LocaleUtil.getLayoutDirectionFromLocale(locale)); locale = new Locale("he", "IL"); assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE, LocaleUtil.getLayoutDirectionFromLocale(locale)); locale = new Locale("pa_Arab"); assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE, LocaleUtil.getLayoutDirectionFromLocale(locale)); locale = new Locale("pa_Arab", "PK"); assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE, LocaleUtil.getLayoutDirectionFromLocale(locale)); locale = new Locale("ps"); assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE, LocaleUtil.getLayoutDirectionFromLocale(locale)); locale = new Locale("ps", "AF"); assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE, LocaleUtil.getLayoutDirectionFromLocale(locale)); locale = new Locale("ur"); assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE, LocaleUtil.getLayoutDirectionFromLocale(locale)); locale = new Locale("ur", "IN"); assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE, LocaleUtil.getLayoutDirectionFromLocale(locale)); locale = new Locale("ur", "PK"); assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE, LocaleUtil.getLayoutDirectionFromLocale(locale)); locale = new Locale("uz_Arab"); assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE, LocaleUtil.getLayoutDirectionFromLocale(locale)); locale = new Locale("uz_Arab", "AF"); assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE, LocaleUtil.getLayoutDirectionFromLocale(locale)); locale = new Locale("zz"); assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE, LocaleUtil.getLayoutDirectionFromLocale(locale)); }