import com.ibm.icu.text.DateFormat; import com.ibm.icu.util.Calendar; import com.ibm.icu.util.ULocale; ... ULocale locale = new ULocale("fa_IR@calendar=persian"); Calendar calendar = Calendar.getInstance(locale); DateFormat df = DateFormat.getDateInstance(DateFormat.FULL, locale); System.out.println(df.format(calendar));
/** * Convenience method to return the locale corresponding to the (canonical) original ID. */ public ULocale canonicalLocale() { return new ULocale(primaryID); }
/** * Returns a locale's language localized for display in the provided locale. * This is a cover for the ICU4C API. * @param localeID the id of the locale whose language will be displayed * @param displayLocaleID the id of the locale in which to display the name. * @return the localized language name. * @stable ICU 3.0 */ public static String getDisplayLanguage(String localeID, String displayLocaleID) { return getDisplayLanguageInternal(new ULocale(localeID), new ULocale(displayLocaleID), false); }
/** * Returns a locale's language localized for display in the provided locale. * This is a cover for the ICU4C API. * @param localeID the id of the locale whose language will be displayed * @param displayLocaleID the id of the locale in which to display the name. * @return the localized language name. * @stable ICU 3.0 */ public static String getDisplayLanguage(String localeID, String displayLocaleID) { return getDisplayLanguageInternal(new ULocale(localeID), new ULocale(displayLocaleID), false); }
/** * Returns a locale's variant localized for display in the provided locale. * This is a cover for the ICU4C API. * @param localeID the id of the locale whose variant will be displayed * @param displayLocaleID the id of the locale in which to display the name. * @return the localized variant name. * @stable ICU 3.0 */ public static String getDisplayVariant(String localeID, String displayLocaleID){ return getDisplayVariantInternal(new ULocale(localeID), new ULocale(displayLocaleID)); }
/** * {@icu} Returns a locale's variant localized for display in the provided locale. * This is a cover for the ICU4C API. * @param localeID the id of the locale whose variant will be displayed * @param displayLocaleID the id of the locale in which to display the name. * @return the localized variant name. * @stable ICU 3.0 */ public static String getDisplayVariant(String localeID, String displayLocaleID){ return getDisplayVariantInternal(new ULocale(localeID), new ULocale(displayLocaleID)); }
/** * {@icu} Returns the locale ID localized for display in the provided locale. * This is a cover for the ICU4C API. * @param localeID the locale whose name is to be displayed. * @param displayLocaleID the id of the locale in which to display the locale name. * @return the localized locale name. * @stable ICU 3.0 */ public static String getDisplayName(String localeID, String displayLocaleID) { return getDisplayNameInternal(new ULocale(localeID), new ULocale(displayLocaleID)); }
/** * Returns the locale ID localized for display in the provided locale. * This is a cover for the ICU4C API. * @param localeID the locale whose name is to be displayed. * @param displayLocale the locale in which to display the locale name. * @return the localized locale name. * @stable ICU 3.0 */ public static String getDisplayName(String localeID, ULocale displayLocale) { return getDisplayNameInternal(new ULocale(localeID), displayLocale); }
/** * {@icu} Returns the locale ID localized for display in the provided locale. * If a dialect name is present in the locale data, then it is returned. * This is a cover for the ICU4C API. * @param localeID the locale whose name is to be displayed. * @param displayLocale the locale in which to display the locale name. * @return the localized locale name. * @stable ICU 4.4 */ public static String getDisplayNameWithDialect(String localeID, ULocale displayLocale) { return getDisplayNameWithDialectInternal(new ULocale(localeID), displayLocale); }
/** * Returns a locale's variant localized for display in the provided locale. * This is a cover for the ICU4C API. * @param localeID the id of the locale whose variant will be displayed. * @param displayLocale the locale in which to display the name. * @return the localized variant name. * @stable ICU 3.0 */ public static String getDisplayVariant(String localeID, ULocale displayLocale) { return getDisplayVariantInternal(new ULocale(localeID), displayLocale); }
/** * {@icu} Creates a ULocale from the id by first canonicalizing the id. * @param nonCanonicalID the locale id to canonicalize * @return the locale created from the canonical version of the ID. * @stable ICU 3.0 */ public static ULocale createCanonical(String nonCanonicalID) { return new ULocale(canonicalize(nonCanonicalID), (Locale)null); }
/** * {@icu} Returns a locale's script localized for display in the provided locale. * @param localeID the id of the locale whose script will be displayed. * @param displayLocale the locale in which to display the name. * @return the localized script name. * @internal * @deprecated This API is ICU internal only. */ @Deprecated public static String getDisplayScriptInContext(String localeID, ULocale displayLocale) { return getDisplayScriptInContextInternal(new ULocale(localeID), displayLocale); }
/** * {@icu} Returns the locale ID localized for display in the provided locale. * This is a cover for the ICU4C API. * @param localeID the locale whose name is to be displayed. * @param displayLocale the locale in which to display the locale name. * @return the localized locale name. * @stable ICU 3.0 */ public static String getDisplayName(String localeID, ULocale displayLocale) { return getDisplayNameInternal(new ULocale(localeID), displayLocale); }
/** * Returns the {@link ULocale} of this message bundle. Subclasses are encouraged to override this * to provide efficient implementations. */ @Nullable public ULocale getLocale() { return getLocaleString() == null ? null : new ULocale(getLocaleString()); }
/** * Construct a DateTimePatternGenerator for a given locale. * * @param gwtLocale */ public DateTimePatternGenerator(GwtLocale gwtLocale) { String localeName = gwtLocale.getAsString(); localeName = ULocale.canonicalize(localeName); ULocale locale = new ULocale(localeName); dtpg = com.ibm.icu.text.DateTimePatternGenerator.getInstance(locale); }
/** Returns whether a locale, given as a string in the ICU syntax, is RTL. */ public static boolean isRtlLanguage(String locale) { try { return UScript.isRightToLeft( UCharacter.getPropertyValueEnum( UProperty.SCRIPT, ULocale.addLikelySubtags(new ULocale(locale)).getScript())); } catch (IllegalArgumentException e) { return false; } }
/** Returns whether a locale, given as a string in the ICU syntax, is RTL. */ public static boolean isRtlLanguage(String locale) { try { return UScript.isRightToLeft( UCharacter.getPropertyValueEnum( UProperty.SCRIPT, ULocale.addLikelySubtags(new ULocale(locale)).getScript())); } catch (IllegalArgumentException e) { return false; } }
public IValue printDateInLocale(IDateTime inputDate, IString locale) //@doc{Print an input date using a specific locale and a default format string} { try { SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd",new ULocale(locale.getValue())); Calendar cal = getCalendarForDate(inputDate); sd.setCalendar(cal); return values.string(sd.format(cal.getTime())); } catch (IllegalArgumentException iae) { throw RuntimeExceptionFactory.dateTimePrintingError("Cannot print time " + inputDate + " in locale: " + locale.getValue(), null, null); } }
public IValue printDateInLocale(IDateTime inputDate, IString formatString, IString locale) //@doc{Print an input date using a specific locale and format string} { try { SimpleDateFormat sd = new SimpleDateFormat(formatString.getValue(),new ULocale(locale.getValue())); Calendar cal = getCalendarForDate(inputDate); sd.setCalendar(cal); return values.string(sd.format(cal.getTime())); } catch (IllegalArgumentException iae) { throw RuntimeExceptionFactory.dateTimePrintingError("Cannot print date " + inputDate + " with format " + formatString.getValue() + ", in locale: " + locale.getValue(), null, null); } }