public static void main(String[] args) {

    // stream.collect(collector): values
    // Collectors.groupingBy(classifier)
    Stream<Locale> locales = Stream.of(Locale.getAvailableLocales());
    Map<String, List<Locale>> languageToLocales =
        locales.collect(Collectors.groupingBy(Locale::getDisplayLanguage));
    System.out.println(languageToLocales);

    System.out.println("--------------");

    // stream.collect(collector): values
    // Collectors.groupingBy(classifier, downstream)
    locales = Stream.of(Locale.getAvailableLocales());
    Map<String, Long> languageToLocalesCounting =
        locales.collect(Collectors.groupingBy(Locale::getDisplayLanguage, Collectors.counting()));
    System.out.println(languageToLocalesCounting);

    System.out.println("--------------");

    // stream.collect(collector): values
    // Collectors.partitioningBy(predicate)
    locales = Stream.of(Locale.getAvailableLocales());
    Map<Boolean, List<Locale>> englishAndOtherLocales =
        locales.collect(Collectors.partitioningBy(l -> l.getLanguage().equals("en")));
    List<Locale> englishLocales = englishAndOtherLocales.get(true);
    System.out.println(englishLocales);

    System.out.println("--------------");
  }
  /**
   * Note: we enforce that this method is called on the UI thread, so we can call
   * nativeVoicesChanged directly.
   */
  private void initialize() {
    assert mNativeTtsPlatformImplAndroid != 0;

    // Note: Android supports multiple speech engines, but querying the
    // metadata about all of them is expensive. So we deliberately only
    // support the default speech engine, and expose the different
    // supported languages for the default engine as different voices.
    String defaultEngineName = mTextToSpeech.getDefaultEngine();
    String engineLabel = defaultEngineName;
    for (TextToSpeech.EngineInfo info : mTextToSpeech.getEngines()) {
      if (info.name.equals(defaultEngineName)) engineLabel = info.label;
    }
    Locale[] locales = Locale.getAvailableLocales();
    mVoices = new ArrayList<TtsVoice>();
    for (int i = 0; i < locales.length; ++i) {
      if (!locales[i].getVariant().isEmpty()) continue;
      if (mTextToSpeech.isLanguageAvailable(locales[i]) > 0) {
        String name = locales[i].getDisplayLanguage();
        if (!locales[i].getCountry().isEmpty()) {
          name += " " + locales[i].getDisplayCountry();
        }
        TtsVoice voice = new TtsVoice(name, locales[i].toString());
        mVoices.add(voice);
      }
    }

    mInitialized = true;
    nativeVoicesChanged(mNativeTtsPlatformImplAndroid);
  }
  @Override
  public void onInit(int status) {
    int result;
    if (status == TextToSpeech.SUCCESS) {
      Locale[] AvalLoc = Locale.getAvailableLocales();

      Log.i("TTS", "Available locales " + Arrays.toString(AvalLoc));

      Locale pol_loc = new Locale("en", "EN");
      if (TextToSpeech.LANG_AVAILABLE == tts.isLanguageAvailable(pol_loc)) {
        result = tts.setLanguage(pol_loc);
      } else {
        result = tts.setLanguage(Locale.ITALIAN);
      }

      if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
        Log.e("TTS", "LANG_NOT_SUPPORTED");
      } else {
        btnSpeak.setEnabled(true);
        speakOut();
      }

    } else {
      Log.e("TTS", "Initialization Failed");
    }
  }
示例#4
0
 private static Map<String, Locale> getLocales() {
   Map<String, Locale> localeMap = Maps.newHashMap();
   for (Locale locale : Locale.getAvailableLocales()) {
     localeMap.put(locale.toString(), locale);
   }
   return localeMap;
 }
示例#5
0
  public List<Locale> getAvailableLanguages() {
    Locale[] locales = Locale.getAvailableLocales();
    Map<String, Locale> localeMap = new HashMap<String, Locale>();

    // remove all variants
    for (Locale locale : locales) {
      if (isTranslationsOnly()
          && !ArrayUtils.contains(config.getAvailableTranslations(), locale.getLanguage())) {
        continue;
      }

      if (localeMap.containsKey(locale.getLanguage())
          && locale.getDisplayName().indexOf('(') != -1) {
        continue;
      }

      localeMap.put(locale.getLanguage(), locale);
    }

    SortedSet<Locale> localeSet =
        new TreeSet<Locale>(new LocaleComparator(LocaleComparator.CompareType.LANGUAGE));

    for (Locale locale : localeMap.values()) {
      localeSet.add(locale);
    }

    return new ArrayList<Locale>(localeSet);
  }
 @Override
 public List<String> defaultLanguageCodes() {
   final TreeSet<String> set = new TreeSet<String>();
   set.add(Locale.getDefault().getLanguage());
   final TelephonyManager manager =
       (TelephonyManager) myApplication.getSystemService(Context.TELEPHONY_SERVICE);
   if (manager != null) {
     final String country0 = manager.getSimCountryIso().toLowerCase();
     final String country1 = manager.getNetworkCountryIso().toLowerCase();
     for (Locale locale : Locale.getAvailableLocales()) {
       final String country = locale.getCountry().toLowerCase();
       if (country != null
           && country.length() > 0
           && (country.equals(country0) || country.equals(country1))) {
         set.add(locale.getLanguage());
       }
     }
     if ("ru".equals(country0) || "ru".equals(country1)) {
       set.add("ru");
     } else if ("by".equals(country0) || "by".equals(country1)) {
       set.add("ru");
     } else if ("ua".equals(country0) || "ua".equals(country1)) {
       set.add("ru");
     }
   }
   set.add("multi");
   return new ArrayList<String>(set);
 }
示例#7
0
 public static void main(String[] args) {
   Locale[] locales = Locale.getAvailableLocales();
   for (Locale locale : locales) {
     //			System.out.println(locale.getDisplayCountry() + ":" + locale.getCountry());
     System.out.println(locale.getDisplayLanguage() + ":" + locale.getLanguage());
   }
 }
  static {
    String[] ids = null;

    try {
      Set<String> set = new TreeSet<>();

      Locale[] locales = Locale.getAvailableLocales();

      for (int i = 0; i < locales.length; i++) {
        Locale locale = locales[i];

        if (locale.getCountry().length() == 2) {
          Currency currency = Currency.getInstance(locale);

          String currencyId = currency.getCurrencyCode();

          set.add(currencyId);
        }
      }

      ids = set.toArray(new String[set.size()]);
    } catch (Exception e) {
      ids = new String[] {"USD", "CAD", "EUR", "GBP", "JPY"};
    } finally {
      CURRENCY_IDS = ids;
    }
  }
  @Test
  public void testLocale() {
    for (Locale locale : Locale.getAvailableLocales()) {

      System.out.println(locale.getLanguage());
    }
  }
示例#10
0
  private static void assertObsolete(String newCode, String oldCode, String displayName) {
    // Either code should get you the same locale.
    Locale newLocale = new Locale(newCode);
    Locale oldLocale = new Locale(oldCode);
    assertEquals(newLocale, oldLocale);

    // No matter what code you used to create the locale, you should get the old code back.
    assertEquals(oldCode, newLocale.getLanguage());
    assertEquals(oldCode, oldLocale.getLanguage());

    // Check we get the right display name.
    assertEquals(displayName, newLocale.getDisplayLanguage(newLocale));
    assertEquals(displayName, oldLocale.getDisplayLanguage(newLocale));
    assertEquals(displayName, newLocale.getDisplayLanguage(oldLocale));
    assertEquals(displayName, oldLocale.getDisplayLanguage(oldLocale));

    // Check that none of the 'getAvailableLocales' methods are accidentally returning two
    // equal locales (because to ICU they're different, but we mangle one into the other).
    assertOnce(newLocale, BreakIterator.getAvailableLocales());
    assertOnce(newLocale, Calendar.getAvailableLocales());
    assertOnce(newLocale, Collator.getAvailableLocales());
    assertOnce(newLocale, DateFormat.getAvailableLocales());
    assertOnce(newLocale, DateFormatSymbols.getAvailableLocales());
    assertOnce(newLocale, NumberFormat.getAvailableLocales());
    assertOnce(newLocale, Locale.getAvailableLocales());
  }
示例#11
0
  public static void main(String[] args) {
    Locale[] locales = Locale.getAvailableLocales();
    int min = Integer.MAX_VALUE;
    int max = Integer.MIN_VALUE;
    Map map = new HashMap(locales.length);
    int conflicts = 0;

    for (int i = 0; i < locales.length; i++) {
      Locale loc = locales[i];
      int hc = loc.hashCode();
      min = Math.min(hc, min);
      max = Math.max(hc, max);
      Integer key = new Integer(hc);
      if (map.containsKey(key)) {
        conflicts++;
        System.out.println("conflict: " + (Locale) map.get(key) + ", " + loc);
      } else {
        map.put(key, loc);
      }
    }
    System.out.println(
        locales.length
            + " locales: conflicts="
            + conflicts
            + ", min="
            + min
            + ", max="
            + max
            + ", diff="
            + (max - min));
    if (conflicts >= (locales.length / 10)) {
      throw new RuntimeException(
          "too many conflicts: " + conflicts + " per " + locales.length + " locales");
    }
  }
 private static void showAvailableLocales() {
   Locale[] localeList = Locale.getAvailableLocales();
   for (int i = 0; i < localeList.length; i++) {
     Locale locale = localeList[i];
     showLocale(locale);
   }
 }
示例#13
0
  private ComboBox createLocaleSelect() {
    ComboBox s = new ComboBox("Locale");
    s.addContainerProperty("caption", String.class, "");
    s.setItemCaptionPropertyId("caption");
    s.setFilteringMode(FilteringMode.CONTAINS);

    for (Locale l : Locale.getAvailableLocales()) {
      if (!s.containsId(l)) {
        Item i = s.addItem(l);
        i.getItemProperty("caption").setValue(getLocaleItemCaption(l));
      }
    }

    s.select(getLocale());
    s.setImmediate(true);
    s.addValueChangeListener(
        new ValueChangeListener() {

          private static final long serialVersionUID = 1L;

          @Override
          public void valueChange(ValueChangeEvent event) {
            updateCalendarLocale((Locale) event.getProperty().getValue());
          }
        });

    return s;
  }
示例#14
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.d(TAG, "onCreate Started");

    setContentView(R.layout.alarm_controller);

    prefs = PreferenceManager.getDefaultSharedPreferences(this);

    tpAlarm = (TimePicker) findViewById(R.id.tpAlarm);
    chkSnooze = (CheckBox) findViewById(R.id.chkSnooze);
    etxtSnoozeMin = (EditText) findViewById(R.id.etxtSnoozeMin);
    Button button = (Button) findViewById(R.id.btnSetAlarm);
    button.setOnClickListener(setAlarmListener);

    btnSetTone = (Button) findViewById(R.id.btnSetTone);
    btnSetTone.setOnClickListener(setTone);

    tpAlarm.setCurrentHour(prefs.getInt(M_HOUR, 0));
    tpAlarm.setCurrentMinute(prefs.getInt(M_MINT, 0));
    chkSnooze.setChecked(prefs.getBoolean(M_SNOOZE, false));
    etxtSnoozeMin.setText(prefs.getString(SNOOZE_T, "0"));

    Locale loc = new Locale("en");
    Log.i(TAG, Arrays.toString(loc.getAvailableLocales()));
  }
示例#15
0
文件: Obs.java 项目: sapna-m/openmrs
 /**
  * This was a convenience method for obtaining a Map of available locale to observation's value as
  * a string This method is a waste and should be not be used. This was used in the web layer
  * because jstl can't pass parameters to a method (${obs.valueAsString[locale]} was used instead
  * of what would be convenient ${obs.valueAsString(locale)}) Now the openmrs:format tag should be
  * used in the web layer: <openmrs:format obsValue="${obs}"/>
  *
  * @deprecated
  */
 public Map<Locale, String> getValueAsString() {
   Map<Locale, String> localeMap = new HashMap<Locale, String>();
   Locale[] locales = Locale.getAvailableLocales(); // ABKTODO: get actual available locales
   for (int i = 0; i < locales.length; i++) {
     localeMap.put(locales[i], getValueAsString(locales[i]));
   }
   return localeMap;
 }
示例#16
0
 /** @bug 4107014 */
 public void TestGetAvailableLocales() {
   Locale[] locales = Locale.getAvailableLocales();
   if (locales == null || locales.length == 0)
     errln("Locale.getAvailableLocales() returned no installed locales!");
   else {
     logln("Locale.getAvailableLocales() returned a list of " + locales.length + " locales.");
     for (int i = 0; i < locales.length; i++) logln(locales[i].toString());
   }
 }
示例#17
0
 @Test
 public void _11_그룹핑() {
   final Stream<Locale> stream = Stream.of(Locale.getAvailableLocales());
   Map<String, List<Locale>> countryToLocales =
       stream.collect(
           Collectors.groupingBy(Locale::getCountry) // 묶을 기준값
           );
   System.out.println(countryToLocales.get("CH"));
 }
 @Test
 public void testListAllSerbianCountries() {
   for (final Locale aLocale :
       CollectionHelper.getSorted(Locale.getAvailableLocales(), new ComparatorLocale()))
     if (aLocale.getLanguage().equals("sr")
         || aLocale.getLanguage().equals("sh")
         || aLocale.getLanguage().equals("bs"))
       s_aLogger.info(aLocale.toString() + ": " + aLocale.getDisplayName());
 }
示例#19
0
 CurrencyConverter() {
   Arrays.asList(Locale.getAvailableLocales())
       .stream()
       .filter(locale -> StringUtils.hasText(locale.getCountry()))
       .forEach(
           locale ->
               currencies.put(
                   Currency.getInstance(locale).getCurrencyCode(),
                   Currency.getInstance(locale).getSymbol(locale)));
 }
示例#20
0
 /**
  * Find a Locale that matches the supplied language / country / variant triple.
  *
  * @param language the language for the required Locale
  * @param country the country code for the required Locale
  * @param variant the variant for the required Locale
  * @return the requested Locale, or <code>null</code>
  */
 protected Locale findLocale(String language, String country, String variant) {
   for (Locale l : Locale.getAvailableLocales()) {
     if (l.getCountry().equals(country)
         && l.getLanguage().equals(language)
         && l.getVariant().equals(variant)) {
       return l;
     }
   }
   return null;
 }
示例#21
0
  private static Map<String, Locale> createLocaleMap() {
    Locale[] availableLocales = Locale.getAvailableLocales();

    Map<String, Locale> map = new HashMap<>();

    for (Locale availableLocale : availableLocales) {
      map.put(availableLocale.getLanguage(), availableLocale);
    }

    return map;
  }
 public static Choice[] getNLChoices() {
   Locale[] locales = Locale.getAvailableLocales();
   Choice[] choices = new Choice[locales.length];
   for (int i = 0; i < locales.length; i++) {
     Locale locale = locales[i];
     choices[i] =
         new Choice(
             locale.toString(),
             locale.toString() + " - " + locale.getDisplayName()); // $NON-NLS-1$
   }
   return choices;
 }
示例#23
0
  @Test
  public void should_serialize_valid_locale() {
    Locale[] locales = Locale.getAvailableLocales();

    for (Locale locale : locales) {
      String languageTag = LocaleUtil.toLanguageTag(locale);
      assertEquals(
          locale.getLanguage()
              + (StringUtils.isNotBlank(locale.getCountry()) ? ("-" + locale.getCountry()) : ""),
          languageTag);
    }
  }
  // determines the calendar language
  static Locale set_language(String[] args, Locale locale) {
    Locale[] locales = Locale.getAvailableLocales();

    for (Locale options : locales) {
      if (args[0] == options) {
        locale = new Locale(args[0]);
      }
    }
    if (locale == null) locale = Locale.getDefault();

    return locale;
  }
示例#25
0
 private Locale getLocale(String name) {
   for (Locale locale : Locale.getAvailableLocales()) {
     if (locale.toString().equals(name)) {
       return locale;
     }
   }
   assert Locale.ROOT.toString().equals("");
   if (name.equals(Locale.ROOT.toString())) {
     return Locale.ROOT;
   }
   throw new MorphlineCompilationException("Unknown locale: " + name, getConfig());
 }
  /** Background thread task to get the available locales. */
  public void run() {
    String locale;

    synchronized (mLocale) {
      mLocales = Locale.getAvailableLocales();
      locale = mFilter.getLocale().getDisplayName();
      for (int i = 0; i < mLocales.length; i++)
        if (!locale.equals(mLocales[i].getDisplayName()))
          mLocale.addItem(mLocales[i].getDisplayName());
      mLocale.invalidate();
    }
  }
 public static final Locale getLanguage(final String language, final Locale locale) {
   synchronized (localeMap) {
     if (localeMap.containsKey(locale) == false) {
       final Map<String, Locale> m = new HashMap<String, Locale>();
       for (final Locale lc : Locale.getAvailableLocales()) {
         m.put(lc.getDisplayName(locale), lc);
       }
       localeMap.put(locale, m);
     }
   }
   return localeMap.get(locale).get(language);
 }
示例#28
0
 @Test
 public void _10_toMap() {
   Stream<Locale> localeStream = Stream.of(Locale.getAvailableLocales());
   Map<String, String> languageNames =
       localeStream.collect(
           Collectors.toMap(
               l -> l.getDisplayLanguage(), // key 맵핑
               l -> l.getDisplayLanguage(l), // value 맵핑
               (existingValue, newValue) -> existingValue)); // key가 충돌하는 경우 머지 함수
   assertThat(languageNames.get("우크라이나어"), is("українська"));
   assertThat(languageNames.get("태국어"), is("ไทย"));
 }
示例#29
0
  /**
   * Available locales
   *
   * @return
   */
  public static List<Locale> getAvailableLocales() {
    List<Locale> locales = new ArrayList<Locale>();

    for (Locale locale : Locale.getAvailableLocales()) {
      if (!StringUtils.isBlank(locale.getDisplayCountry())) {
        locales.add(locale);
      }
    }

    Collections.sort(locales, new LocaleComparator(LocaleComparator.CompareType.COUNTRY));

    return locales;
  }
  void test1() {
    Locale[] available = Locale.getAvailableLocales();
    List<Locale> jreimplloc =
        Arrays.asList(
            LocaleProviderAdapter.forJRE().getTimeZoneNameProvider().getAvailableLocales());
    List<Locale> providerLocales = Arrays.asList(tznp.getAvailableLocales());
    String[] ids = TimeZone.getAvailableIDs();

    for (Locale target : available) {
      // pure JRE implementation
      OpenListResourceBundle rb =
          ((ResourceBundleBasedAdapter) LocaleProviderAdapter.forJRE())
              .getLocaleData()
              .getTimeZoneNames(target);
      boolean jreSupportsTarget = jreimplloc.contains(target);

      for (String id : ids) {
        // the time zone
        TimeZone tz = TimeZone.getTimeZone(id);

        // JRE string array for the id
        String[] jrearray = null;
        if (jreSupportsTarget) {
          try {
            jrearray = rb.getStringArray(id);
          } catch (MissingResourceException mre) {
          }
        }

        for (int i = 1; i <= (tz.useDaylightTime() ? 4 : 2); i++) {
          // the localized name
          String name = tz.getDisplayName(i >= 3, i % 2, target);

          // provider's name (if any)
          String providersname = null;
          if (providerLocales.contains(target)) {
            providersname = tznp.getDisplayName(id, i >= 3, i % 2, target);
          }

          // JRE's name
          String jresname = null;
          if (jrearray != null) {
            jresname = jrearray[i];
          }

          checkValidity(
              target, jresname, providersname, name, jreSupportsTarget && jresname != null);
        }
      }
    }
  }