List of usage examples for java.util Locale getDisplayName
public final String getDisplayName()
From source file:org.openmrs.util.databasechange.ConceptValidatorChangeSet.java
/** * Sets the fully specified name from available names * * @param localeConceptNamesMap, list of all concept names for the concept * @return// w ww .j av a 2 s . com */ private boolean setFullySpecifiedName(int conceptId, Map<Locale, List<ConceptName>> localeConceptNamesMap) { //Pick the first name in any locale by searching in order from the allowed locales for (Locale allowedLoc : allowedLocales) { List<ConceptName> possibleFullySpecNames = localeConceptNamesMap.get(allowedLoc); if (CollectionUtils.isEmpty(possibleFullySpecNames)) { continue; } //try the synonyms for (ConceptName cn : possibleFullySpecNames) { if (cn.isSynonym()) { cn.setConceptNameType(ConceptNameType.FULLY_SPECIFIED); reportUpdatedName(cn, "ConceptName with id " + cn.getConceptNameId() + " (" + cn.getName() + ") in locale '" + allowedLoc.getDisplayName() + "' has been set as the fully specified name for concept with id : " + conceptId); return true; } } //try the short names for (ConceptName cn : possibleFullySpecNames) { if (cn.isShort()) { cn.setConceptNameType(ConceptNameType.FULLY_SPECIFIED); reportUpdatedName(cn, "ConceptName with id " + cn.getConceptNameId() + " (" + cn.getName() + ") in locale '" + allowedLoc.getDisplayName() + "' has been changed from short to fully specified name for concept with id : " + conceptId); return true; } } } //pick a name randomly from the conceptName map for (Map.Entry<Locale, List<ConceptName>> entry : localeConceptNamesMap.entrySet()) { Locale locale = entry.getKey(); if (locale != null) { ConceptName fullySpecName = entry.getValue().get(0); fullySpecName.setConceptNameType(ConceptNameType.FULLY_SPECIFIED); reportUpdatedName(fullySpecName, "ConceptName with id " + fullySpecName.getConceptNameId() + " (" + fullySpecName.getName() + ") in locale '" + locale.getDisplayName() + "' has been set as the fully specified name for concept with id : " + conceptId); return true; } } //most probably this concept has no names added to it yet return false; }
From source file:com.aurel.track.dbase.InitDatabase.java
/** * This method loads resource strings from properties files (ApplicationResources.properties) * into the database./*from ww w. j av a 2 s .com*/ * @throws ServletException */ public static void loadResourcesFromPropertiesFiles(Boolean customOnly, ServletContext servletContext) { Boolean useProjects = true; Connection con = null; try { con = getConnection(); Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery("SELECT * FROM ID_TABLE WHERE TABLE_NAME = 'USESPACES'"); if (rs.next()) { useProjects = false; // We have an installation that uses the workspace terminology } } catch (Exception e) { LOGGER.error("Problem reading from ID_TABLE when checking for USESPACES"); LOGGER.debug(STACKTRACE, e); } finally { if (con != null) { try { con.close(); } catch (Exception ee) { LOGGER.debug(ee); } } } List<Locale> locs = LocaleHandler.getPropertiesLocales(); int numberOfLocales = locs.size(); int step = Math.round((float) ApplicationStarter.RESOURCE_UPGRADE[1] / numberOfLocales); float delta = new Float(ApplicationStarter.RESOURCE_UPGRADE[1] / new Float(numberOfLocales)) - step; Iterator<Locale> it = locs.iterator(); while (it.hasNext()) { Locale loc = it.next(); String locCode = loc.getLanguage(); if (ApplicationBean.getInstance().isInTestMode() && locCode != "en") { continue; } if (loc.getCountry() != null && !"".equals(loc.getCountry())) { locCode = locCode + "_" + loc.getCountry(); } if (!customOnly) { ApplicationStarter.getInstance().actualizePercentComplete(step, ApplicationStarter.RESOURCE_UPGRADE_LOCALE_TEXT + loc.getDisplayName() + "..."); addResourceToDatabase(loc, locCode, useProjects); } addCustomResourceToDatabase(loc, locCode); } if (!customOnly) { ApplicationStarter.getInstance().actualizePercentComplete(step, ApplicationStarter.RESOURCE_UPGRADE_DEFAULT_LOCALE_TEXT); addResourceToDatabase(Locale.getDefault(), null, useProjects); } addCustomResourceToDatabase(Locale.getDefault(), null); if (!customOnly) { ApplicationStarter.getInstance().actualizePercentComplete(Math.round(delta), ApplicationStarter.RESOURCE_UPGRADE_DEFAULT_LOCALE_TEXT); } }
From source file:edu.ku.brc.specify.tools.StrLocalizerApp.java
/** * @param hideExisting// ww w . jav a2 s .c o m * @return */ private Locale doChooseLangLocale(final boolean hideExisting) { HashSet<String> existingLocs = new HashSet<String>(); if (hideExisting) { for (String nm : rootDir.list()) { if (!nm.startsWith(".")) { existingLocs.add(nm); } } } Vector<Locale> locales = new Vector<Locale>(); for (Locale l : Locale.getAvailableLocales()) { if (!hideExisting || !existingLocs.contains(getFullLang(l))) { locales.add(l); } } Collections.sort(locales, new Comparator<Locale>() { public int compare(Locale o1, Locale o2) { return o1.getDisplayName().compareTo(o2.getDisplayName()); } }); Vector<String> localeNames = new Vector<String>(); for (Locale l : locales) { localeNames.add(l.getDisplayName()); } ToggleButtonChooserDlg<String> chooser = new ToggleButtonChooserDlg<String>((Frame) null, "CHOOSE_LOCALE", localeNames, ToggleButtonChooserPanel.Type.RadioButton); chooser.setUseScrollPane(true); chooser.setVisible(true); if (!chooser.isCancelled()) { return locales.get(chooser.getSelectedIndex()); } return null; }
From source file:edu.ku.brc.specify.tools.StrLocalizerApp.java
/** * build a list of languages //from ww w . jav a 2 s . co 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:edu.ku.brc.specify.tools.l10nios.StrLocalizerAppForiOS.java
/** * @param hideExisting/*from w w w. j a v a2s. co m*/ * @return */ private Locale doChooseLangLocale(final Locale hideLocale) { Vector<Locale> locales = new Vector<Locale>(); Collections.addAll(locales, Locale.getAvailableLocales()); String[] langs = { "es", "sv", "sq", "fr" }; Vector<Locale> destLocales = new Vector<Locale>(); destLocales.add(Locale.GERMAN); for (String lang : langs) { appendLocale(locales, destLocales, lang); } Vector<String> localeNames = new Vector<String>(); for (Locale l : destLocales) { localeNames.add(l.getDisplayName()); } ToggleButtonChooserDlg<String> chooser = new ToggleButtonChooserDlg<String>((Frame) null, "CHOOSE_LOCALE", localeNames, ToggleButtonChooserPanel.Type.RadioButton); chooser.setUseScrollPane(true); UIHelper.centerAndShow(chooser); if (!chooser.isCancelled()) { return destLocales.get(chooser.getSelectedIndex()); } return null; }
From source file:org.opencms.ui.editors.messagebundle.CmsMessageBundleEditorModel.java
/** * Loads the propertyvfsbundle for the provided locale. * If the bundle file is not present, it will be created. * @param locale the locale for which the localization should be loaded * * @throws IOException thrown if loading fails. * @throws CmsException thrown if reading or creation fails. *//* w ww . j a va 2 s.c o m*/ private void loadLocalizationFromPropertyBundle(Locale locale) throws IOException, CmsException { // may throw exception again String sitePath = m_sitepath + m_basename + "_" + locale.toString(); CmsResource resource = null; if (m_cms.existsResource(sitePath)) { resource = m_cms.readResource(sitePath); if (!OpenCms.getResourceManager().getResourceType(resource).getTypeName() .equals(CmsMessageBundleEditorTypes.BundleType.PROPERTY.toString())) { throw new CmsException(new CmsMessageContainer(Messages.get(), Messages.ERR_RESOURCE_HAS_WRONG_TYPE_2, locale.getDisplayName(), resource.getRootPath())); } } else { resource = m_cms.createResource(sitePath, OpenCms.getResourceManager() .getResourceType(CmsMessageBundleEditorTypes.BundleType.PROPERTY.toString())); LockedFile lf = LockedFile.lockResource(m_cms, resource); lf.setCreated(true); m_lockedBundleFiles.put(locale, lf); } m_bundleFiles.put(locale, resource); SortedProperties props = new SortedProperties(); props.load(new InputStreamReader(new ByteArrayInputStream(m_cms.readFile(resource).getContents()), CmsFileUtil.getEncoding(m_cms, resource))); m_localizations.put(locale, props); }
From source file:org.openmrs16.Concept.java
/** * Returns the preferred short form name for a locale, or if none has been identified, the * shortest name available in the locale. * // ww w. ja v a2 s .c om * @param locale the language and country in which the short name is used * @param exact true/false to return only exact locale (no default locale) * @return the appropriate short name, or null if not found */ public ConceptName getShortestName(Locale locale, Boolean exact) { if (log.isDebugEnabled()) log.debug("Getting shortest conceptName for locale: " + locale); ConceptName foundName = null; ConceptName shortestName = null; if (locale == null) locale = LocaleUtility.getDefaultLocale(); String desiredLanguage = locale.getLanguage(); if (desiredLanguage.length() > 2) desiredLanguage = desiredLanguage.substring(0, 2); for (Iterator<ConceptName> i = getNames().iterator(); i.hasNext() && foundName == null;) { ConceptName possibleName = i.next(); if ((shortestName == null) || (possibleName.getName().length() < shortestName.getName().length())) { shortestName = possibleName; } } if (foundName == null) { // no name with the given locale was found. if (exact) { // return null if exact match desired log.warn("No short concept name found for concept id " + conceptId + " for locale " + locale.getDisplayName()); } else if (shortestName != null) { // returning default name locale ("en") if exact match not // desired foundName = shortestName; } else { log.warn("No concept name found for default locale for concept id " + conceptId); } } return foundName; }
From source file:org.openmrs18.Concept.java
/** * Returns the short form name for a locale, or if none has been identified, the shortest name * available in the locale. If exact is false, the shortest name from any locale is returned * //from www.j av a 2 s . co m * @param locale the language and country in which the short name is used * @param exact true/false to return only exact locale (no default locale) * @return the appropriate short name, or null if not found * @should return the name marked as the shortName for the locale if it is present * @should return the shortest name in a given locale for a concept if exact is true * @should return the shortest name for the concept from any locale if exact is false * @should return null if their are no names in the specified locale and exact is true */ public ConceptName getShortestName(Locale locale, Boolean exact) { if (log.isDebugEnabled()) log.debug("Getting shortest conceptName for locale: " + locale); ConceptName shortNameInLocale = getShortNameInLocale(locale); if (shortNameInLocale != null) return shortNameInLocale; ConceptName shortestNameForLocale = null; ConceptName shortestNameForConcept = null; if (locale != null) { for (Iterator<ConceptName> i = getNames().iterator(); i.hasNext();) { ConceptName possibleName = i.next(); if (possibleName.getLocale().equals(locale)) { if ((shortestNameForLocale == null) || (possibleName.getName().length() < shortestNameForLocale.getName().length())) { shortestNameForLocale = possibleName; } } if ((shortestNameForConcept == null) || (possibleName.getName().length() < shortestNameForConcept.getName().length())) { shortestNameForConcept = possibleName; } } } if (exact) { if (shortestNameForLocale == null) log.warn("No short concept name found for concept id " + conceptId + " for locale " + locale.getDisplayName()); return shortestNameForLocale; } return shortestNameForConcept; }
From source file:gr.abiss.calipso.CalipsoServiceImpl.java
public void setLocaleList(String[] array) { locales = new LinkedHashMap<String, String>(); for (String localeString : array) { Locale locale = org.springframework.util.StringUtils.parseLocaleString(localeString); locales.put(localeString, localeString + " - " + locale.getDisplayName()); if (dao.get(Language.class, localeString) == null) { dao.save(new Language(localeString)); }// w w w.ja v a 2s. c o m } logger.info("available locales configured " + locales); }
From source file:org.openmrs.Concept.java
/** * Returns the short form name for a locale, or if none has been identified, the shortest name * available in the locale. If exact is false, the shortest name from any locale is returned * /*from ww w .ja v a 2 s.com*/ * @param locale the language and country in which the short name is used * @param exact true/false to return only exact locale (no default locale) * @return the appropriate short name, or null if not found * @should return the name marked as the shortName for the locale if it is present * @should return the shortest name in a given locale for a concept if exact is true * @should return the shortest name for the concept from any locale if exact is false * @should return null if their are no names in the specified locale and exact is true */ public ConceptName getShortestName(Locale locale, Boolean exact) { if (log.isDebugEnabled()) { log.debug("Getting shortest conceptName for locale: " + locale); } ConceptName shortNameInLocale = getShortNameInLocale(locale); if (shortNameInLocale != null) { return shortNameInLocale; } ConceptName shortestNameForLocale = null; ConceptName shortestNameForConcept = null; if (locale != null) { for (ConceptName possibleName : getNames()) { if (possibleName.getLocale().equals(locale) && ((shortestNameForLocale == null) || (possibleName.getName().length() < shortestNameForLocale.getName().length()))) { shortestNameForLocale = possibleName; } if ((shortestNameForConcept == null) || (possibleName.getName().length() < shortestNameForConcept.getName().length())) { shortestNameForConcept = possibleName; } } } if (exact) { if (shortestNameForLocale == null) { log.warn("No short concept name found for concept id " + conceptId + " for locale " + locale.getDisplayName()); } return shortestNameForLocale; } return shortestNameForConcept; }