コード例 #1
0
ファイル: LocaleValueProvider.java プロジェクト: rlugojr/aura
 private List<LocalizedLabel> getNameOfWeekdays(AuraLocale locale) throws QuickFixException {
   DateFormatSymbols weekdaySymbols = DateFormatSymbols.getInstance(locale.getLanguageLocale());
   String[] weekdays = weekdaySymbols.getWeekdays();
   String[] shortWeekdays = weekdaySymbols.getShortWeekdays();
   ArrayList<LocalizedLabel> weekdayList = new ArrayList<>(7);
   for (int i = 1; i < weekdays.length; i++) {
     weekdayList.add(
         new LocalizedLabel(
             weekdays[i], shortWeekdays[i].toUpperCase(locale.getLanguageLocale())));
   }
   return weekdayList;
 }
コード例 #2
0
ファイル: LocaleValueProvider.java プロジェクト: rlugojr/aura
 private List<LocalizedLabel> getNameOfMonths(AuraLocale locale) throws QuickFixException {
   DateFormatSymbols monthSymbols = DateFormatSymbols.getInstance(locale.getLanguageLocale());
   String[] months = monthSymbols.getMonths();
   String[] shortMonths = monthSymbols.getShortMonths();
   ArrayList<LocalizedLabel> monthList = new ArrayList<>(months.length);
   for (int i = 0; i < months.length; i++) {
     monthList.add(new LocalizedLabel(months[i], shortMonths[i]));
   }
   return monthList;
 }
コード例 #3
0
ファイル: LocaleValueProvider.java プロジェクト: rlugojr/aura
  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
    }

    builder.put(
        FIRST_DAY_OF_WEEK, Calendar.getInstance(al.getTimeZone(), userLocale).getFirstDayOfWeek());

    // 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);
    }

    String timezoneId = al.getTimeZone().getID();
    String availableTimezoneId = Aura.getConfigAdapter().getAvailableTimezone(timezoneId);
    builder.put(TIME_ZONE, availableTimezoneId);
    builder.put(TIME_ZONE_FILE_NAME, availableTimezoneId.replace("/", "-"));

    builder.put(IS_EASTERN_NAME_STYLE, al.isEasternNameStyle());

    // DecimalFormat is expected
    DecimalFormat df = (DecimalFormat) DecimalFormat.getNumberInstance(al.getNumberLocale());

    // Patterns are not localized; the "." means "locale decimal" not "dot"
    builder.put(NUMBER_FORMAT, df.toPattern());
    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());

    // Don't localize the patterns
    builder.put(PERCENT_FORMAT, df.toPattern());

    df = (DecimalFormat) DecimalFormat.getCurrencyInstance(al.getCurrencyLocale());

    // Don't localize the patterns
    builder.put(CURRENCY_FORMAT, df.toPattern());
    DecimalFormatSymbols cdfs = df.getDecimalFormatSymbols();
    Currency cur = cdfs.getCurrency();
    builder.put(CURRENCY_CODE, cur != null ? cur.getCurrencyCode() : "");
    builder.put(CURRENCY, cdfs.getCurrencySymbol());

    data = builder.build();
  }