private final Map<String, Object> data;
public LocaleValueProvider() {
Builder<String, Object> builder = ImmutableMap.builder();
AuraLocale al = Aura.getLocalizationAdapter().getAuraLocale();
Locale userLocale = al.getLocale();
Locale lang = al.getLanguageLocale();
Locale dateLocale = al.getDateLocale();
builder.put(USER_LOCALE_LANGUAGE, userLocale.getLanguage());
builder.put(USER_LOCALE_COUNTRY, userLocale.getCountry());
builder.put(LANGUAGE, lang.getLanguage());
builder.put(COUNTRY, lang.getCountry());
builder.put(VARIANT, lang.getVariant());
builder.put(LANGUAGE_LOCALE, lang.toString());
try {
builder.put(MONTH_NAME, this.getNameOfMonths(al));
builder.put(WEEKDAY_NAME, this.getNameOfWeekdays(al));
builder.put(TODAY_LABEL, this.getLabelForToday());
} catch (QuickFixException qfe) {
// Ignore
}
// using java DateFormat because the year pattern "MMM d, y" (although valid) isn't understood by moment.js
DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.DEFAULT, dateLocale);
DateFormat datetimeFormat = DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT, dateLocale);
DateFormat timeFormat = DateFormat.getTimeInstance(DateFormat.DEFAULT, dateLocale);
try {
SimpleDateFormat sdf = (SimpleDateFormat) dateFormat;
builder.put(DATE_FORMAT, sdf.toPattern());
SimpleDateFormat sdtf = (SimpleDateFormat) datetimeFormat;
builder.put(DATETIME_FORMAT, sdtf.toPattern());
SimpleDateFormat stf = (SimpleDateFormat) timeFormat;
builder.put(TIME_FORMAT, stf.toPattern());
} catch (ClassCastException cce) {
builder.put(DATE_FORMAT, DEFAULT_DATE_FORMAT);
builder.put(DATETIME_FORMAT, DEFAULT_DATETIME_FORMAT);
builder.put(TIME_FORMAT, DEFAULT_TIME_FORMAT);
}
builder.put(TIME_ZONE, al.getTimeZone().getID());
builder.put(TIME_ZONE_FILE_NAME, al.getTimeZone().getID().replace("/", "-"));
builder.put(IS_EASTERN_NAME_STYLE, al.isEasternNameStyle());
// DecimalFormat is expected
DecimalFormat df = (DecimalFormat) DecimalFormat.getNumberInstance(al.getNumberLocale());
builder.put(NUMBER_FORMAT, df.toLocalizedPattern());
DecimalFormatSymbols dfs = df.getDecimalFormatSymbols();
builder.put(DECIMAL, dfs.getDecimalSeparator());
builder.put(GROUPING, dfs.getGroupingSeparator());
builder.put(ZERO_DIGIT, dfs.getZeroDigit());
df = (DecimalFormat) DecimalFormat.getPercentInstance(al.getNumberLocale());
builder.put(PERCENT_FORMAT, df.toLocalizedPattern());
df = (DecimalFormat) DecimalFormat.getCurrencyInstance(al.getCurrencyLocale());
builder.put(CURRENCY_FORMAT, df.toLocalizedPattern());
DecimalFormatSymbols cdfs = df.getDecimalFormatSymbols();
Currency cur = cdfs.getCurrency();
builder.put(CURRENCY_CODE, cur != null ? cur.getCurrencyCode() : "");