List of usage examples for java.util Locale getAvailableLocales
public static Locale[] getAvailableLocales()
From source file:org.texconverter.TexConverter.java
private static Locale getLocale(final String localeCode) { Locale locale = null;//from w w w.jav a 2 s . co m if (localeCode != null) { Locale[] locales = Locale.getAvailableLocales(); for (int i = 0; i < locales.length; i++) { if (localeCode.equalsIgnoreCase(locales[i].getISO3Language())) { locale = locales[i]; break; } } if (locale == null) { locale = Locale.getDefault(); LOGGER.warn("getLocale -> unknown locale code " + localeCode + ", using system locale " + locale.getISO3Language() + " instead."); } } else { locale = Locale.getDefault(); } return locale; }
From source file:edu.ku.brc.specify.tools.StrLocalizerApp.java
/** * build a list of languages /*from w ww. j a v a 2 s . c o m*/ */ protected void loadLanguages() { languages.clear(); boolean doXML = false; if (doXML) { Element root = XMLHelper.readDOMFromConfigDir("languagecodes.xml"); for (Object langObj : root.selectNodes("languagecode")) { Element lang = (Element) langObj; languages.add(new LanguageEntry(lang.attributeValue("englishname"), lang.attributeValue("code"))); } } else { for (Locale l : Locale.getAvailableLocales()) { System.out.println(l.getDisplayName()); languages.add(new LanguageEntry(l.getDisplayName(), getFullLang(l))); } /*languages.add(new LanguageEntry("Albania", "sq")); languages.add(new LanguageEntry("English", "en")); languages.add(new LanguageEntry("Swedish", "sv")); languages.add(new LanguageEntry("Portugese", "pt")); languages.add(new LanguageEntry("Spanish", "es")); languages.add(new LanguageEntry("German", "es"));*/ } Collections.sort(languages); }
From source file:morphy.command.SetCommand.java
private String[] getDistinctLocalesByLanguage() { List<String> list = new ArrayList<String>(); Locale[] arr = Locale.getAvailableLocales(); for (Locale l : arr) { String v = l.getDisplayLanguage(); if (!list.contains(v)) list.add(v);/*w w w. j a va 2 s . com*/ } return list.toArray(new String[list.size()]); }
From source file:com.mg.framework.utils.MiscUtils.java
/** * Returns a List of available locales sorted by display name *///from w w w . j a v a 2 s. c om public static List<Locale> availableLocales() { if (availableLocaleList == null) { synchronized (MiscUtils.class) { if (availableLocaleList == null) { TreeMap<String, Locale> localeMap = new TreeMap<String, Locale>(); Locale[] locales = Locale.getAvailableLocales(); for (int i = 0; i < locales.length; i++) { localeMap.put(locales[i].getDisplayName(), locales[i]); } availableLocaleList = new LinkedList<Locale>(localeMap.values()); } } } return availableLocaleList; }
From source file:org.apache.maven.doxia.tools.DefaultSiteTool.java
/** {@inheritDoc} */ public List<Locale> getSiteLocales(String locales) { if (locales == null) { return Collections.singletonList(DEFAULT_LOCALE); }//from w w w .j a v a 2s . c o m String[] localesArray = StringUtils.split(locales, ","); List<Locale> localesList = new ArrayList<Locale>(localesArray.length); for (String localeString : localesArray) { Locale locale = codeToLocale(localeString); if (locale == null) { continue; } if (!Arrays.asList(Locale.getAvailableLocales()).contains(locale)) { if (getLogger().isWarnEnabled()) { getLogger().warn( "The locale defined by '" + locale + "' is not available in this Java Virtual Machine (" + System.getProperty("java.version") + " from " + System.getProperty("java.vendor") + ") - IGNORING"); } continue; } // Default bundles are in English if ((!locale.getLanguage().equals(DEFAULT_LOCALE.getLanguage())) && (!i18n .getBundle("site-tool", locale).getLocale().getLanguage().equals(locale.getLanguage()))) { if (getLogger().isWarnEnabled()) { getLogger().warn("The locale '" + locale + "' (" + locale.getDisplayName(Locale.ENGLISH) + ") is not currently supported by Maven Site - IGNORING." + "\nContributions are welcome and greatly appreciated!" + "\nIf you want to contribute a new translation, please visit " + "http://maven.apache.org/plugins/localization.html for detailed instructions."); } continue; } localesList.add(locale); } if (localesList.isEmpty()) { localesList = Collections.singletonList(DEFAULT_LOCALE); } return localesList; }
From source file:org.opensextant.util.TextUtils.java
/** * Initialize language codes and metadata. This establishes a map for the * most common language codes/names that exist in at least ISO-639-1 and * have a non-zero 2-char ID.// w ww.j a v a2s.co m * * <pre> * Based on: * http://stackoverflow.com/questions/674041/is-there-an-elegant-way * -to-convert-iso-639-2-3-letter-language-codes-to-java-lo * * Actual code mappings: en => eng eng => en * * cel => '' // Celtic; Avoid this. * * tr => tur tur => tr * * Names: tr => turkish tur => turkish turkish => tr // ISO2 only * * </pre> */ public static void initLanguageData() { Locale[] locales = Locale.getAvailableLocales(); for (Locale locale : locales) { Language l = new Language(locale.getISO3Language(), locale.getLanguage(), locale.getDisplayLanguage()); addLanguage(l); } }
From source file:org.de.jmg.learn.SettingsActivity.java
private void initSpinners(boolean blnRestart) { libLearn.gStatus = "initSpinners"; try {/*from w ww . jav a 2s .co m*/ spnAbfragebereich = (Spinner) findViewById(R.id.spnAbfragebereich); spnASCII = (Spinner) findViewById(R.id.spnASCII); spnStep = (Spinner) findViewById(R.id.spnStep); spnDisplayDurationWord = (Spinner) findViewById(R.id.spnAnzeigedauerWord); spnDisplayDurationBed = (Spinner) findViewById(R.id.spnAnzeigedauerBed); spnPaukRepetitions = (Spinner) findViewById(R.id.spnRepetitions); spnProbabilityFactor = (Spinner) findViewById(R.id.spnProbabilityFactor); spnRestartInterval = (Spinner) findViewById(R.id.spnRestartInterval); spnLanguages = (Spinner) findViewById(R.id.spnLanguages); spnColors = (org.de.jmg.lib.NoClickSpinner) findViewById(R.id.spnColors); spnSounds = (org.de.jmg.lib.NoClickSpinner) findViewById(R.id.spnSounds); spnLangWord = (Spinner) findViewById(R.id.spnLangWord); spnLangMeaning = (Spinner) findViewById(R.id.spnLangMeaning); if (!blnRestart) langinitialized = 0; else langinitialized = 0; if (spnAbfragebereich.getAdapter() != null && spnAbfragebereich.getAdapter().getCount() > 0) return; if (Colors == null || Colors != null) { Colors = new ColorsArrayAdapter(_main, R.layout.spinnerrow); Colors.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); Sounds = new SoundsArrayAdapter(_main, R.layout.soundsspinnerrow); Sounds.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); } spnASCII.getBackground().setColorFilter(Color.BLACK, PorterDuff.Mode.SRC_ATOP); spnStep.getBackground().setColorFilter(Color.BLACK, PorterDuff.Mode.SRC_ATOP); spnDisplayDurationBed.getBackground().setColorFilter(Color.BLACK, PorterDuff.Mode.SRC_ATOP); spnDisplayDurationWord.getBackground().setColorFilter(Color.BLACK, PorterDuff.Mode.SRC_ATOP); spnAbfragebereich.getBackground().setColorFilter(Color.BLACK, PorterDuff.Mode.SRC_ATOP); spnPaukRepetitions.getBackground().setColorFilter(Color.BLACK, PorterDuff.Mode.SRC_ATOP); spnProbabilityFactor.getBackground().setColorFilter(Color.BLACK, PorterDuff.Mode.SRC_ATOP); spnRestartInterval.getBackground().setColorFilter(Color.BLACK, PorterDuff.Mode.SRC_ATOP); spnLanguages.getBackground().setColorFilter(Color.BLACK, PorterDuff.Mode.SRC_ATOP); //spnColors.getBackground().setColorFilter(Color.BLACK, PorterDuff.Mode.SRC_ATOP); //spnSounds.getBackground().setColorFilter(Color.BLACK, PorterDuff.Mode.SRC_ATOP); // Create an ArrayAdapter using the string array and a default // spinner layout ScaledArrayAdapter<CharSequence> adapter = ScaledArrayAdapter.createFromResource(_main, R.array.spnAbfragebereichEntries, android.R.layout.simple_spinner_item); // Specify the layout to use when the list of choices appears adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); if (lib.NookSimpleTouch() && mScale == 1) adapter.Scale = 1.8f; // Apply the adapter to the spinner spnAbfragebereich.setAdapter(adapter); spnAbfragebereich.setSelection(getIntent().getShortExtra("Abfragebereich", (short) -1) + 1); spnAbfragebereich.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { intent.putExtra("Abfragebereich", (short) (position - 1)); intent.putExtra("OK", "OK"); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); ScaledArrayAdapter<CharSequence> adapterStep = ScaledArrayAdapter.createFromResource(_main, R.array.spnStepEntries, android.R.layout.simple_spinner_item); // Specify the layout to use when the list of choices appears adapterStep.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // Apply the adapter to the spinner if (lib.NookSimpleTouch() && mScale == 1) adapterStep.Scale = 1.8f; spnStep.setAdapter(adapterStep); spnStep.setSelection(adapterStep.getPosition("" + getIntent().getShortExtra("Step", (short) 5))); spnStep.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { intent.putExtra("Step", (short) (Integer.parseInt((String) parent.getItemAtPosition(position)))); intent.putExtra("OK", "OK"); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); ScaledArrayAdapter<String> adapterASCII = new ScaledArrayAdapter<String>(_main, android.R.layout.simple_spinner_item); // adapterASCII.addAll(Charset.availableCharsets().values()); ArrayList<String> charsets = new ArrayList<String>(); for (Charset c : Charset.availableCharsets().values()) { charsets.add(c.name()); } adapterASCII.addAll(charsets); // Specify the layout to use when the list of choices appears adapterASCII.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // Apply the adapter to the spinner if (lib.NookSimpleTouch() && mScale == 1) adapterASCII.Scale = 1.8f; spnASCII.setAdapter(adapterASCII); String CharsetASCII = getIntent().getStringExtra("CharsetASCII"); if (!libString.IsNullOrEmpty(CharsetASCII)) { int i = 0; for (Charset c : Charset.availableCharsets().values()) { if (c.name().equalsIgnoreCase(CharsetASCII)) { break; } i++; } if (i < adapterASCII.getCount()) { spnASCII.setSelection(i); } } spnASCII.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { intent.putExtra("CharsetASCII", ((String) (parent.getSelectedItem()))); intent.putExtra("OK", "OK"); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); final ScaledArrayAdapter<CharSequence> adapterDDWord = ScaledArrayAdapter.createFromResource(_main, R.array.spnDurations, android.R.layout.simple_spinner_item); // Specify the layout to use when the list of choices appears adapterDDWord.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); if (lib.NookSimpleTouch() && mScale == 1) adapterDDWord.Scale = 1.8f; // Apply the adapter to the spinner spnDisplayDurationWord.setAdapter(adapterDDWord); String strDD = "" + getIntent().getFloatExtra("DisplayDurationWord", 1.5f); strDD = strDD.replace(".0", ""); int Pos = adapterDDWord.getPosition(strDD); spnDisplayDurationWord.setSelection(Pos); spnDisplayDurationWord.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { intent.putExtra("DisplayDurationWord", (Float.parseFloat((String) parent.getItemAtPosition(position)))); intent.putExtra("OK", "OK"); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); ScaledArrayAdapter<CharSequence> adapterDDBed = ScaledArrayAdapter.createFromResource(_main, R.array.spnDurations, android.R.layout.simple_spinner_item); // Specify the layout to use when the list of choices appears adapterDDBed.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); if (lib.NookSimpleTouch() && mScale == 1) adapterDDBed.Scale = 1.8f; // Apply the adapter to the spinner spnDisplayDurationBed.setAdapter(adapterDDBed); strDD = "" + getIntent().getFloatExtra("DisplayDurationBed", 2.5f); strDD = strDD.replace(".0", ""); Pos = adapterDDBed.getPosition(strDD); spnDisplayDurationBed.setSelection(Pos); spnDisplayDurationBed.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { intent.putExtra("DisplayDurationBed", (Float.parseFloat((String) parent.getItemAtPosition(position)))); intent.putExtra("OK", "OK"); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); ScaledArrayAdapter<CharSequence> adapterPaukRepetitions = ScaledArrayAdapter.createFromResource(_main, R.array.spnRepetitions, android.R.layout.simple_spinner_item); // Specify the layout to use when the list of choices appears adapterPaukRepetitions.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); if (lib.NookSimpleTouch() && mScale == 1) adapterPaukRepetitions.Scale = 1.8f; spnPaukRepetitions.setAdapter(adapterPaukRepetitions); Pos = getIntent().getIntExtra("PaukRepetitions", 3) - 1; spnPaukRepetitions.setSelection(Pos); spnPaukRepetitions.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { intent.putExtra("PaukRepetitions", (Integer.parseInt((String) parent.getItemAtPosition(position)))); intent.putExtra("OK", "OK"); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); ScaledArrayAdapter<CharSequence> adapterProbabilityFactor = ScaledArrayAdapter.createFromResource(_main, R.array.spnProbabilityFactors, android.R.layout.simple_spinner_item); // Specify the layout to use when the list of choices appears adapterProbabilityFactor.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); if (lib.NookSimpleTouch() && mScale == 1) adapterProbabilityFactor.Scale = 1.8f; spnProbabilityFactor.setAdapter(adapterProbabilityFactor); float ProbabilityFactor = getIntent().getFloatExtra("ProbabilityFactor", -1f); if (ProbabilityFactor == -1) { strDD = _main.getString((R.string.auto)); } else { strDD = "" + ProbabilityFactor; strDD = strDD.replace(".0", ""); } ArrayAdapter<CharSequence> a1 = adapterProbabilityFactor; if (a1 != null) { try { libLearn.gStatus = "get Spinneradapter ProbabilityFactor"; Pos = (a1.getPosition(strDD)); spnProbabilityFactor.setSelection(Pos); } catch (Exception ex) { lib.ShowException(_main, ex); } } spnProbabilityFactor.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { String strDD = (String) parent.getItemAtPosition(position); if (strDD.equalsIgnoreCase(_main.getString(R.string.auto))) strDD = "-1"; intent.putExtra("ProbabilityFactor", (Float.parseFloat(strDD))); intent.putExtra("OK", "OK"); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); ScaledArrayAdapter<CharSequence> adapterRestartInterval = ScaledArrayAdapter.createFromResource(_main, R.array.spnRestartInterval, android.R.layout.simple_spinner_item); // Specify the layout to use when the list of choices appears adapterRestartInterval.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); if (lib.NookSimpleTouch() && mScale == 1) adapterRestartInterval.Scale = 1.8f; spnRestartInterval.setAdapter(adapterRestartInterval); int RestartInterval = getIntent().getIntExtra("RestartInterval", -1); if (RestartInterval == -1) { strDD = _main.getString(R.string.off); } else { strDD = "" + RestartInterval; } a1 = adapterRestartInterval; if (a1 != null) { try { libLearn.gStatus = "get Spinneradapter ProbabilityFactor"; Pos = (a1.getPosition(strDD)); spnRestartInterval.setSelection(Pos); } catch (Exception ex) { lib.ShowException(_main, ex); } } spnRestartInterval.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { String strDD = (String) parent.getItemAtPosition(position); if (strDD.equalsIgnoreCase(_main.getString(R.string.off))) strDD = "-1"; intent.putExtra("RestartInterval", (Integer.parseInt(strDD))); intent.putExtra("OK", "OK"); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); ScaledArrayAdapter<CharSequence> adapterLanguages = ScaledArrayAdapter.createFromResource(_main, R.array.spnLanguages, android.R.layout.simple_spinner_item); // Specify the layout to use when the list of choices appears adapterLanguages.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); if (lib.NookSimpleTouch() && mScale == 1) adapterLanguages.Scale = 1.8f; spnLanguages.setAdapter(adapterLanguages); int Language = getIntent().getIntExtra("Language", org.de.jmg.learn.vok.Vokabel.EnumSprachen.undefiniert.ordinal()); spnLanguages.setSelection(Language); spnLanguages.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { intent.putExtra("Language", position); intent.putExtra("OK", "OK"); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); adapterLangWord = new ScaledArrayAdapter<>(_main, android.R.layout.simple_spinner_item); // Specify the layout to use when the list of choices appears adapterLangWord.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); if (lib.NookSimpleTouch() && mScale == 1) adapterLangWord.Scale = 1.8f; adapterLangWord.add(new DisplayLocale(new Locale("", ""))); adapterLangWord.add(new DisplayLocale(new Locale("_off"))); for (Locale l : Locale.getAvailableLocales()) { DisplayLocale dl = new DisplayLocale(l); adapterLangWord.add(dl); } sortLangWord(); spnLangWord.setAdapter(adapterLangWord); /* if (selectedLocale != null) { int pos = adapterLangWord.getPosition(selectedLocale); spnLangWord.setSelection (-1); spnLangWord.setSelection(pos); }*/ spnLangWord.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { if (position <= 0 || langinitialized == 0) { langinitialized += 1; return; } Locale l = adapterLangWord.getItem(position).locale; int res = 0; if (_main.tts.isLanguageAvailable(Locale.US) >= 0) { res = _main.tts.setLanguage(l); } if (!chkTextToSpeech.isChecked() || res >= 0 || l.toString().equalsIgnoreCase("_off") || !_main.blnTextToSpeech || lib.ShowMessageYesNo(_main, String.format(_main.getString(R.string.msgLanguageNotavailable), l.getDisplayLanguage() + " " + l.getDisplayCountry()), "") == yesnoundefined.yes) { intent.putExtra("langword", lib.toLanguageTag(l)); intent.putExtra("OK", "OK"); } } @Override public void onNothingSelected(AdapterView<?> parent) { } }); adapterLangMeaning = new ScaledArrayAdapter<>(_main, android.R.layout.simple_spinner_item); // Specify the layout to use when the list of choices appears adapterLangMeaning.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); if (lib.NookSimpleTouch() && mScale == 1) adapterLangMeaning.Scale = 1.8f; adapterLangMeaning.add(new DisplayLocale(new Locale("", ""))); adapterLangMeaning.add(new DisplayLocale(new Locale("_off"))); for (Locale l : Locale.getAvailableLocales()) { DisplayLocale dl = new DisplayLocale((l)); adapterLangMeaning.add(dl); } sortLangMeaning(); spnLangMeaning.setAdapter(adapterLangMeaning); /* if (selectedLocale != null) { int pos = adapterLangMeaning.getPosition(selectedLocale); spnLangMeaning.setSelection(-1); spnLangMeaning.setSelection(pos); } */ spnLangMeaning.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { if (position <= 0 || langinitialized < 2) { langinitialized += 1; return; } Locale l = adapterLangMeaning.getItem(position).locale; int res = 0; if (_main.tts.isLanguageAvailable(Locale.US) >= 0) { res = _main.tts.setLanguage(l); } if (!chkTextToSpeech.isChecked() || res >= 0 || l.toString().equalsIgnoreCase("_off") || !_main.blnTextToSpeech || lib.ShowMessageYesNo(_main, String.format(_main.getString(R.string.msgLanguageNotavailable), l.getDisplayLanguage() + " " + l.getDisplayCountry()), "") == yesnoundefined.yes) { intent.putExtra("langmeaning", lib.toLanguageTag(l)); intent.putExtra("OK", "OK"); } } @Override public void onNothingSelected(AdapterView<?> parent) { } }); if (lib.NookSimpleTouch() && mScale == 1) Colors.Scale = 1.8f; spnColors.setAdapter(Colors); spnColors.setOnLongClickListener(new android.widget.AdapterView.OnLongClickListener() { @Override public boolean onLongClick(View v) { spnColors.blnDontCallOnClick = true; ShowColorDialog(); return false; } }); spnColors.setOnItemLongClickListener(new android.widget.AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { spnColors.blnDontCallOnClick = true; ShowColorDialog(); return false; } }); if (lib.NookSimpleTouch() && mScale == 1) Sounds.Scale = 1.8f; spnSounds.setAdapter(Sounds); spnSounds.setOnLongClickListener(new android.widget.AdapterView.OnLongClickListener() { @Override public boolean onLongClick(View v) { spnSounds.blnDontCallOnClick = true; ShowSoundsDialog(); return false; } }); spnSounds.setOnItemLongClickListener(new android.widget.AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { spnSounds.blnDontCallOnClick = true; ShowSoundsDialog(); return false; } }); spnSounds.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { SoundSetting item = (SoundSetting) parent.getItemAtPosition(position); File F = new File(item.SoundPath); try { if (F.exists()) lib.playSound(F); else lib.playSound(_main.getAssets(), item.SoundPath); } catch (Exception e) { e.printStackTrace(); } } @Override public void onNothingSelected(AdapterView<?> parent) { } }); } catch (Exception ex) { lib.ShowException(_main, ex); } }
From source file:com.doculibre.constellio.services.IndexFieldServicesImpl.java
@Override public Map<String, String> getDefaultLabelledValues(IndexField indexField, Locale locale) { Map<String, String> labels = new HashMap<String, String>(); String indexFieldName = indexField.getName(); if (IndexField.COLLECTION_ID_FIELD.equals(indexFieldName)) { RecordCollectionServices collectionServices = ConstellioSpringUtils.getRecordCollectionServices(); for (RecordCollection collection : collectionServices.list()) { Locale displayLocale = collection.getDisplayLocale(locale); labels.put("" + collection.getId(), collection.getTitle(displayLocale)); }// w w w . j a va 2 s. co m } else if (IndexField.CONNECTOR_INSTANCE_ID_FIELD.equals(indexFieldName)) { ConnectorInstanceServices connectorInstanceServices = ConstellioSpringUtils .getConnectorInstanceServices(); for (ConnectorInstance connectorInstance : connectorInstanceServices.list()) { labels.put("" + connectorInstance.getId(), connectorInstance.getDisplayName()); } } else if (IndexField.CONNECTOR_TYPE_ID_FIELD.equals(indexFieldName)) { ConnectorTypeServices connectorTypeServices = ConstellioSpringUtils.getConnectorTypeServices(); for (ConnectorType connectorType : connectorTypeServices.list()) { labels.put("" + connectorType.getId(), connectorType.getName()); } } else if (IndexField.LANGUAGE_FIELD.equals(indexFieldName)) { for (Locale availableLocale : Locale.getAvailableLocales()) { labels.put(availableLocale.getLanguage(), StringUtils.capitalize(availableLocale.getDisplayLanguage(locale))); } } else if (IndexField.MIME_TYPE_FIELD.equals(indexFieldName)) { // Source : http://www.w3schools.com/media/media_mimeref.asp String prefix = "mimeType."; Set<String> mimeTypeResourceKeys = ResourceBundleUtils.getKeys(prefix, ApplicationResources.class); for (String mimeTypeResourceKey : mimeTypeResourceKeys) { String mimeType = mimeTypeResourceKey.substring(prefix.length()); String mimeTypeLabel = ResourceBundleUtils.getString(mimeTypeResourceKey, locale, ApplicationResources.class); labels.put(mimeType, mimeTypeLabel); } } return labels; }
From source file:org.openmrs.Obs.java
/** * 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: <code><openmrs:format obsValue="${obs}"/></code> * //from w w w. jav a2 s. c o m * @deprecated */ @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; }