List of usage examples for java.util Locale getVariant
public String getVariant()
From source file:com.bluexml.side.Framework.alfresco.notification.NotificationHelper.java
/** * This method loads the file resourceCustomPaths+"/cm:"+propertyFileName.basename+<language>+propertyFileName.extension as InputStream * @param language the language to load; if not null the propertyFileName is modified in propertyFileName.basename+<language>+propertyFileName.extension; if null the propertyFileName is not modified * @param propertyFileName the property file name to load * @param resourceCustomPath the folder where the propertyFileName may be loaded (with the embedded language if not null) * @param classPath if true, the propertyFileName is loaded from the classpath (without resourceCustomPath) * @return the inputstream resourceCustomPaths+"/cm:"+propertyFileName.basename+<language>+propertyFileName.extension content *//*from ww w . j a va 2 s. co m*/ public InputStream getPropertiesInputStream(String language, String propertyFileName, String resourceCustomPath, boolean classPath) { InputStream s = null; // compute path with language String[] path_dictionary = propertyFileName.split("\\."); if (!resourceCustomPath.endsWith("/")) resourceCustomPath += "/"; path_dictionary[0] = resourceCustomPath + TYPE_CONTENT_PREFIX + ":" + path_dictionary[0]; String resourcePath_dictionary = path_dictionary[0]; if (language != null) resourcePath_dictionary += "_" + language; resourcePath_dictionary += "." + path_dictionary[1]; if (logger.isDebugEnabled()) { logger.debug("getPropertiesInputStream path_dictionary=" + path_dictionary); logger.debug("getPropertiesInputStream language=" + language); logger.debug("getPropertiesInputStream resourcePath_dictionary=" + resourcePath_dictionary); } try { // try to get the template that match the language (country[variant]?) s = getInputStream(resourcePath_dictionary); } catch (FileNotFoundException e) { s = null; String country = null; if (language != null) { logger.debug("no perfect match try on country"); // no perfect match found, try to get template for country (without variant) Locale parseLocale = I18NUtil.parseLocale(language); logger.debug("local country :" + parseLocale.getCountry()); logger.debug("local variant :" + parseLocale.getVariant()); country = parseLocale.getCountry().toLowerCase(); if (!language.equals(country)) { // try on country ? resourcePath_dictionary = path_dictionary[0] + "_" + country + "." + path_dictionary[1]; try { s = getInputStream(resourcePath_dictionary); } catch (FileNotFoundException e1) { logger.debug("no match on country"); } } } if (s == null && classPath) { // file not exist so go ahead, and search for the default configuration for this country if (country != null) { language = country; logger.debug("Load default configuration from classPath"); // search in classPath (for default values) String[] path = PROPERTIES_PATH.split("\\."); String resourcePath = path[0] + "_" + language + "." + path[1]; s = this.getClass().getResourceAsStream(resourcePath); } if (s == null) { // not found so we load default file s = this.getClass().getResourceAsStream(PROPERTIES_PATH); logger.debug("configuration for language :" + language + " not found, so use default language"); } } } return s; }
From source file:ca.oson.json.gson.functional.DefaultTypeAdaptersTest.java
public void testLocaleDeserializationWithLanguageCountryVariant() { String json = "\"de_DE_EURO\""; Locale locale = oson.fromJson(json, Locale.class); assertEquals("de", locale.getLanguage()); assertEquals("DE", locale.getCountry()); assertEquals("EURO", locale.getVariant()); }
From source file:org.apache.beehive.netui.compiler.model.validation.ValidationModel.java
private void writeLocaleSet(XmlModelWriter xw, Element element, LocaleSet localeSet) { Locale locale = localeSet.getLocale(); Element formSetElement = null; if (locale == null) { formSetElement = findChildElement(xw, element, "formset", "language", null, false, null); } else {/*from w w w. j ava2 s. c o m*/ Element possibleMatch = findChildElement(xw, element, "formset", "language", locale.getLanguage()); if (possibleMatch != null) { String country = getElementAttribute(possibleMatch, "country"); String variant = getElementAttribute(possibleMatch, "variant"); String localeCountry = locale.getCountry(); String localeVariant = locale.getVariant(); if (((localeCountry.length() == 0 && country == null) || localeCountry.equals(country)) && ((localeVariant.length() == 0 && variant == null) || localeVariant.equals(variant))) { formSetElement = possibleMatch; } } } if (formSetElement == null) { formSetElement = xw.addElement(element, "formset"); } localeSet.writeXML(xw, formSetElement); }
From source file:org.openmrs.module.emrapi.concept.HibernateEmrConceptDAO.java
@Override @Transactional(readOnly = true)// w w w .j a va 2 s. co m public List<ConceptSearchResult> conceptSearch(String query, Locale locale, Collection<ConceptClass> classes, Collection<Concept> inSets, Collection<ConceptSource> sources, Integer limit) { List<String> uniqueWords = getUniqueWords(query, locale); if (uniqueWords.size() == 0) { return Collections.emptyList(); } List<ConceptSearchResult> results = new ArrayList<ConceptSearchResult>(); // find matches based on name { Criteria criteria = sessionFactory.getCurrentSession().createCriteria(ConceptName.class, "cn"); criteria.add(Restrictions.eq("voided", false)); if (StringUtils.isNotBlank(locale.getCountry()) || StringUtils.isNotBlank(locale.getVariant())) { Locale[] locales = new Locale[] { locale, new Locale(locale.getLanguage()) }; criteria.add(Restrictions.in("locale", locales)); } else { criteria.add(Restrictions.eq("locale", locale)); } criteria.setMaxResults(limit); Criteria conceptCriteria = criteria.createCriteria("concept"); conceptCriteria.add(Restrictions.eq("retired", false)); if (classes != null) { conceptCriteria.add(Restrictions.in("conceptClass", classes)); } if (inSets != null) { DetachedCriteria allowedSetMembers = DetachedCriteria.forClass(ConceptSet.class); allowedSetMembers.add(Restrictions.in("conceptSet", inSets)); allowedSetMembers.setProjection(Projections.property("concept")); criteria.add(Subqueries.propertyIn("concept", allowedSetMembers)); } for (String word : uniqueWords) { criteria.add(Restrictions.ilike("name", word, MatchMode.ANYWHERE)); } Set<Concept> conceptsMatchedByPreferredName = new HashSet<Concept>(); for (ConceptName matchedName : (List<ConceptName>) criteria.list()) { results.add(new ConceptSearchResult(null, matchedName.getConcept(), matchedName, calculateMatchScore(query, uniqueWords, matchedName))); if (matchedName.isLocalePreferred()) { conceptsMatchedByPreferredName.add(matchedName.getConcept()); } } // don't display synonym matches if the preferred name matches too for (Iterator<ConceptSearchResult> i = results.iterator(); i.hasNext();) { ConceptSearchResult candidate = i.next(); if (!candidate.getConceptName().isLocalePreferred() && conceptsMatchedByPreferredName.contains(candidate.getConcept())) { i.remove(); } } } // find matches based on mapping if (sources != null) { Criteria criteria = sessionFactory.getCurrentSession().createCriteria(ConceptMap.class); criteria.setMaxResults(limit); Criteria conceptCriteria = criteria.createCriteria("concept"); conceptCriteria.add(Restrictions.eq("retired", false)); if (classes != null) { conceptCriteria.add(Restrictions.in("conceptClass", classes)); } Criteria mappedTerm = criteria.createCriteria("conceptReferenceTerm"); mappedTerm.add(Restrictions.eq("retired", false)); mappedTerm.add(Restrictions.in("conceptSource", sources)); mappedTerm.add(Restrictions.ilike("code", query, MatchMode.EXACT)); for (ConceptMap mapping : (List<ConceptMap>) criteria.list()) { results.add(new ConceptSearchResult(null, mapping.getConcept(), null, calculateMatchScore(query, mapping))); } } Collections.sort(results, new Comparator<ConceptSearchResult>() { @Override public int compare(ConceptSearchResult left, ConceptSearchResult right) { return right.getTransientWeight().compareTo(left.getTransientWeight()); } }); if (results.size() > limit) { results = results.subList(0, limit); } return results; }
From source file:no.abmu.common.locale.LocaleUtil.java
/** * Method for logging of locale. Used under test and development. * /*from ww w. j av a 2 s.c o m*/ * @param request current HTTP request */ public void logLocale(HttpServletRequest request) { HttpSession session = request.getSession(false); String parameterSiteLocale = request.getParameter("siteLocale"); String parameterStartLocale = request.getParameter("startLocale"); String rcSiteLocale = (String) request.getAttribute("siteLocale"); // String seSiteLocale = (String) session.getAttribute("siteLocale"); Locale locale = RequestContextUtils.getLocale(request); logger.info("request siteLocale: " + rcSiteLocale); logger.info("request parameter siteLocale: " + parameterSiteLocale); logger.info("request parameter startLocale: " + parameterStartLocale); // logger.info("session siteLocale: " + seSiteLocale); logger.info("Locale getDisplayCountry: " + locale.getDisplayCountry()); logger.info("Locale getDisplayLanguage: " + locale.getDisplayLanguage()); logger.info("Locale getDisplayVariant: " + locale.getDisplayVariant()); logger.info("Locale getDisplayName: " + locale.getDisplayName()); logger.info("Locale getISO3Country: " + locale.getISO3Country()); logger.info("Locale getLanguage: " + locale.getLanguage()); logger.info("Locale getVariant: " + locale.getVariant()); logger.info("Locale toString: " + locale.toString()); }
From source file:org.sakaiproject.metaobj.shared.mgt.home.StructuredArtifactHome.java
protected Content i18nFilterAnnotations(Element content) throws JDOMException { Locale locale = rl.getLocale(); Map<String, Element> documentElements = new Hashtable<String, Element>(); filterElements(documentElements, content, null); filterElements(documentElements, content, locale.getLanguage()); filterElements(documentElements, content, locale.getLanguage() + "_" + locale.getCountry()); filterElements(documentElements, content, locale.getLanguage() + "_" + locale.getCountry() + "_" + locale.getVariant()); Element returned = (Element) content.clone(); returned.removeChildren("documentation", content.getNamespace()); for (Iterator<Element> i = documentElements.values().iterator(); i.hasNext();) { returned.addContent((Content) i.next().clone()); }//from w ww .j a va 2s .c o m return returned; }
From source file:hudson.model.Descriptor.java
private InputStream getHelpStream(Class c, String suffix) { Locale locale = Stapler.getCurrentRequest().getLocale(); String base = c.getName().replace('.', '/') + "/help" + suffix; ClassLoader cl = c.getClassLoader(); if (cl == null) return null; InputStream in;//from w w w . j a v a 2 s . c o m in = cl.getResourceAsStream(base + '_' + locale.getLanguage() + '_' + locale.getCountry() + '_' + locale.getVariant() + ".html"); if (in != null) return in; in = cl.getResourceAsStream(base + '_' + locale.getLanguage() + '_' + locale.getCountry() + ".html"); if (in != null) return in; in = cl.getResourceAsStream(base + '_' + locale.getLanguage() + ".html"); if (in != null) return in; // default return cl.getResourceAsStream(base + ".html"); }
From source file:org.sakaiproject.util.ResourceLoader.java
/** ** Return a locale's display Name// www . java 2 s . com ** ** @return String used to display Locale ** ** @author Jean-Francois Leveque (Universite Pierre et Marie Curie - Paris 6) **/ public String getLocaleDisplayName(Locale loc) { Locale preferedLoc = getLocale(); StringBuilder displayName = new StringBuilder(loc.getDisplayLanguage(loc)); if (StringUtils.isNotBlank(loc.getDisplayCountry(loc))) { displayName.append(" - ").append(loc.getDisplayCountry(loc)); } if (StringUtils.isNotBlank(loc.getVariant())) { displayName.append(" (").append(loc.getDisplayVariant(loc)).append(")"); } displayName.append(" [").append(loc.toString()).append("] "); displayName.append(loc.getDisplayLanguage(preferedLoc)); if (StringUtils.isNotBlank(loc.getDisplayCountry(preferedLoc))) { displayName.append(" - ").append(loc.getDisplayCountry(preferedLoc)); } return displayName.toString(); }
From source file:im.vector.VectorApp.java
/** * Save the new application locale.// w ww .j a v a 2s .c o m */ private static void saveApplicationLocale(Locale locale) { Context context = VectorApp.getInstance(); SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences.Editor editor = preferences.edit(); String language = locale.getLanguage(); if (!TextUtils.isEmpty(language)) { editor.putString(APPLICATION_LOCALE_LANGUAGE_KEY, language); } else { editor.remove(APPLICATION_LOCALE_LANGUAGE_KEY); } String country = locale.getCountry(); if (!TextUtils.isEmpty(country)) { editor.putString(APPLICATION_LOCALE_COUNTRY_KEY, country); } else { editor.remove(APPLICATION_LOCALE_COUNTRY_KEY); } String variant = locale.getVariant(); if (!TextUtils.isEmpty(variant)) { editor.putString(APPLICATION_LOCALE_VARIANT_KEY, variant); } else { editor.remove(APPLICATION_LOCALE_VARIANT_KEY); } editor.commit(); }
From source file:edu.ku.brc.specify.tools.schemalocale.SchemaLocalizerDlg.java
@Override public Vector<Locale> getLocalesInUse() { Hashtable<String, Boolean> localeHash = new Hashtable<String, Boolean>(); // Add any from the Database Vector<Locale> localeList = getLocalesInUseInDB(schemaType); for (Locale locale : localeList) { localeHash.put(SchemaLocalizerXMLHelper.makeLocaleKey(locale.getLanguage(), locale.getCountry(), locale.getVariant()), true); }/*from ww w. j a v a2 s . co m*/ for (SpLocaleContainer container : tables) { SchemaLocalizerXMLHelper.checkForLocales(container, localeHash); for (LocalizableItemIFace f : container.getContainerItems()) { SchemaLocalizerXMLHelper.checkForLocales(f, localeHash); } } localeList.clear(); for (String key : localeHash.keySet()) { String[] toks = StringUtils.split(key, "_"); localeList.add(new Locale(toks[0], "", "")); } return localeList; }