List of usage examples for java.util Locale getLanguage
public String getLanguage()
From source file:com.android.screenspeak.eventprocessor.ProcessorPhoneticLetters.java
/** * Map a character to a phonetic letter. *//*from w ww . j a v a 2 s . c o m*/ private String getPhoneticLetter(String locale, String letter) { Locale bcp47_locale = parseLanguageTag(locale); String normalized_letter = letter.toLowerCase(bcp47_locale); String value = getPhoneticLetterMap(locale).get(normalized_letter); if (value == null) { if (bcp47_locale.getCountry().isEmpty()) { // As a last resort, fall back to English. value = getPhoneticLetterMap(FALLBACK_LOCALE).get(normalized_letter); } else { // Get the letter for the base language, if possible. value = getPhoneticLetter(bcp47_locale.getLanguage(), normalized_letter); } } return value; }
From source file:com.redhat.satellite.search.index.IndexManager.java
private String lookupLocale(String lang) { String ret = docLocaleLookUp.get(lang.toLowerCase()); if (StringUtils.isBlank(ret)) { Locale l = new Locale(lang); ret = docLocaleLookUp.get(l.getLanguage().toLowerCase()); }//from w w w . java 2s . co m return ret; }
From source file:com.salesmanager.core.service.reference.ReferenceService.java
@Transactional public Collection<DynamicLabel> getDynamicLabelsByTitles(int merchantId, List<String> ids, Locale locale) throws Exception { return dynamicLabelDao.findByMerchantIdAndTitleAndLanguageId(merchantId, ids, LanguageUtil.getLanguageNumberCode(locale.getLanguage())); }
From source file:com.salesmanager.core.service.reference.ReferenceService.java
@Transactional public Collection<DynamicLabel> getDynamicLabelsByIds(int merchantId, List<Long> ids, Locale locale) throws Exception { return dynamicLabelDao.findByMerchantIdAndLabelIdAndLanguageId(merchantId, ids, LanguageUtil.getLanguageNumberCode(locale.getLanguage())); }
From source file:com.doculibre.constellio.wicket.panels.search.SearchFormPanel.java
@SuppressWarnings({ "rawtypes", "unchecked" }) public SearchFormPanel(String id, final IModel simpleSearchModel) { super(id);/*from w w w .j av a 2 s.c o m*/ searchForm = new WebMarkupContainer("searchForm", new CompoundPropertyModel(simpleSearchModel)); simpleSearchFormDiv = new WebMarkupContainer("simpleSearchFormDiv") { @Override public boolean isVisible() { SimpleSearch search = (SimpleSearch) simpleSearchModel.getObject(); return search.getAdvancedSearchRule() == null; } }; advancedSearchFormDiv = new WebMarkupContainer("advancedSearchFormDiv") { @Override public boolean isVisible() { SimpleSearch search = (SimpleSearch) simpleSearchModel.getObject(); return search.getAdvancedSearchRule() != null; } }; advancedSearchPanel = new AdvancedSearchPanel("advanceForm", simpleSearchModel); searchForm.add(new AttributeModifier("action", new LoadableDetachableModel() { @Override protected Object load() { PageFactoryPlugin pageFactoryPlugin = PluginFactory.getPlugin(PageFactoryPlugin.class); return urlFor(pageFactoryPlugin.getSearchResultsPage(), new PageParameters()); } })); hiddenFields = new ListView("hiddenFields", new LoadableDetachableModel() { @Override protected Object load() { List<SimpleParam> hiddenParams = new ArrayList<SimpleParam>(); HiddenSearchFormParamsPlugin hiddenSearchFormParamsPlugin = PluginFactory .getPlugin(HiddenSearchFormParamsPlugin.class); if (hiddenSearchFormParamsPlugin != null) { WebRequestCycle webRequestCycle = (WebRequestCycle) RequestCycle.get(); HttpServletRequest request = webRequestCycle.getWebRequest().getHttpServletRequest(); SimpleParams hiddenSimpleParams = hiddenSearchFormParamsPlugin.getHiddenParams(request); for (String paramName : hiddenSimpleParams.keySet()) { for (String paramValue : hiddenSimpleParams.getList(paramName)) { hiddenParams.add(new SimpleParam(paramName, paramValue)); } } } SimpleSearch simpleSearch = (SimpleSearch) simpleSearchModel.getObject(); SimpleSearch clone = simpleSearch.clone(); SearchInterfaceConfigServices searchInterfaceConfigServices = ConstellioSpringUtils .getSearchInterfaceConfigServices(); SearchInterfaceConfig config = searchInterfaceConfigServices.get(); if (!config.isKeepFacetsNewSearch()) { // Will be true if we just clicked on a delete link // on the CurrentSearchPanel if (!clone.isRefinedSearch()) { clone.getSearchedFacets().clear(); clone.setCloudKeyword(null); } // We must click on a delete link on // CurrentSearchPanel so that it is considered // again as refined clone.setRefinedSearch(false); } clone.initFacetPages(); List<String> ignoredParamNames = Arrays.asList("query", "searchType", "page", "singleSearchLocale"); SimpleParams searchParams = clone.toSimpleParams(); for (String paramName : searchParams.keySet()) { if (!ignoredParamNames.contains(paramName) && !paramName.contains(SearchRule.ROOT_PREFIX)) { List<String> paramValues = searchParams.getList(paramName); for (String paramValue : paramValues) { SimpleParam hiddenParam = new SimpleParam(paramName, paramValue); hiddenParams.add(hiddenParam); } } } return hiddenParams; } }) { @Override protected void populateItem(ListItem item) { SimpleParam hiddenParam = (SimpleParam) item.getModelObject(); if (hiddenParam.value != null) { item.add(new SimpleAttributeModifier("name", hiddenParam.name)); item.add(new SimpleAttributeModifier("value", hiddenParam.value)); } else { item.setVisible(false); } } }; SearchInterfaceConfigServices searchInterfaceConfigServices = ConstellioSpringUtils .getSearchInterfaceConfigServices(); SearchInterfaceConfig config = searchInterfaceConfigServices.get(); if (config.isSimpleSearchAutocompletion() && ((SimpleSearch) simpleSearchModel.getObject()).getAdvancedSearchRule() == null) { AutoCompleteSettings settings = new AutoCompleteSettings(); settings.setCssClassName("simpleSearchAutoCompleteChoices"); IModel model = new Model(((SimpleSearch) simpleSearchModel.getObject()).getQuery()); WordsAndValueAutoCompleteRenderer render = new WordsAndValueAutoCompleteRenderer() { @Override protected String getTextValue(String word, Object value) { return word; } }; queryField = new TextAndValueAutoCompleteTextField("query", model, String.class, settings, render) { @Override public String getInputName() { return super.getId(); } @Override protected Iterator getChoicesForWord(String word) { SimpleSearch simpleSearch = (SimpleSearch) simpleSearchModel.getObject(); String collectionName = simpleSearch.getCollectionName(); AutocompleteServices autocompleteServices = ConstellioSpringUtils.getAutocompleteServices(); RecordCollectionServices collectionServices = ConstellioSpringUtils .getRecordCollectionServices(); RecordCollection collection = collectionServices.get(collectionName); List<String> suggestions = autocompleteServices.suggestSimpleSearch(word, collection, getLocale()); return suggestions.iterator(); } @Override protected boolean supportMultipleWords() { return false; } }; } else { queryField = new TextField("query") { @Override public String getInputName() { return super.getId(); } }; } searchTypeField = new RadioGroup("searchType") { @Override public String getInputName() { return super.getId(); } }; IModel languages = new LoadableDetachableModel() { protected Object load() { Set<String> localeCodes = new HashSet<String>(); SimpleSearch simpleSearch = (SimpleSearch) simpleSearchModel.getObject(); RecordCollectionServices recordCollectionServices = ConstellioSpringUtils .getRecordCollectionServices(); RecordCollection collection = recordCollectionServices.get(simpleSearch.getCollectionName()); List<Locale> searchableLocales = ConstellioSpringUtils.getSearchableLocales(); if (!collection.isOpenSearch()) { localeCodes.add(""); if (!searchableLocales.isEmpty()) { for (Locale searchableLocale : searchableLocales) { localeCodes.add(searchableLocale.getLanguage()); } } else { IndexFieldServices indexFieldServices = ConstellioSpringUtils.getIndexFieldServices(); IndexField languageField = indexFieldServices.get(IndexField.LANGUAGE_FIELD, collection); for (String localeCode : indexFieldServices.suggestValues(languageField)) { localeCodes.add(localeCode); } } } else { localeCodes.add(""); if (!searchableLocales.isEmpty()) { for (Locale searchableLocale : searchableLocales) { localeCodes.add(searchableLocale.getLanguage()); } } else { for (Locale availableLocale : Locale.getAvailableLocales()) { localeCodes.add(availableLocale.getLanguage()); } } } List<Locale> locales = new ArrayList<Locale>(); for (String localeCode : localeCodes) { locales.add(new Locale(localeCode)); } Collections.sort(locales, new Comparator<Locale>() { @Override public int compare(Locale locale1, Locale locale2) { Locale locale1Display; Locale locale2Display; SearchInterfaceConfig config = ConstellioSpringUtils.getSearchInterfaceConfigServices() .get(); if (config.isTranslateLanguageNames()) { locale1Display = locale2Display = getLocale(); } else { locale1Display = locale1; locale2Display = locale2; } List<Locale> searchableLocales = ConstellioSpringUtils.getSearchableLocales(); if (searchableLocales.isEmpty()) { searchableLocales = ConstellioSpringUtils.getSupportedLocales(); } Integer indexOfLocale1; Integer indexOfLocale2; if (locale1.getLanguage().equals(getLocale().getLanguage())) { indexOfLocale1 = Integer.MIN_VALUE; } else { indexOfLocale1 = searchableLocales.indexOf(locale1); } if (locale2.getLanguage().equals(getLocale().getLanguage())) { indexOfLocale2 = Integer.MIN_VALUE; } else { indexOfLocale2 = searchableLocales.indexOf(locale2); } if (indexOfLocale1 == -1) { indexOfLocale1 = Integer.MAX_VALUE; } if (indexOfLocale2 == -1) { indexOfLocale2 = Integer.MAX_VALUE; } if (!indexOfLocale1.equals(Integer.MAX_VALUE) || !indexOfLocale2.equals(Integer.MAX_VALUE)) { return indexOfLocale1.compareTo(indexOfLocale2); } else if (StringUtils.isBlank(locale1.getLanguage())) { return Integer.MIN_VALUE; } else { return locale1.getDisplayLanguage(locale1Display) .compareTo(locale2.getDisplayLanguage(locale2Display)); } } }); return locales; } }; IChoiceRenderer languageRenderer = new ChoiceRenderer() { @Override public Object getDisplayValue(Object object) { Locale locale = (Locale) object; String text; if (locale.getLanguage().isEmpty()) { text = (String) new StringResourceModel("all", SearchFormPanel.this, null).getObject(); } else { Locale localeDisplay; SearchInterfaceConfig config = ConstellioSpringUtils.getSearchInterfaceConfigServices().get(); if (config.isTranslateLanguageNames()) { localeDisplay = getLocale(); } else { localeDisplay = locale; } text = StringUtils.capitalize(locale.getDisplayLanguage(localeDisplay)); } return text; } @Override public String getIdValue(Object object, int index) { return ((Locale) object).getLanguage(); } }; IModel languageModel = new Model() { @Override public Object getObject() { SimpleSearch simpleSearch = (SimpleSearch) simpleSearchModel.getObject(); Locale singleSearchLocale = simpleSearch.getSingleSearchLocale(); if (singleSearchLocale == null) { SearchedFacet facet = simpleSearch.getSearchedFacet(IndexField.LANGUAGE_FIELD); List<String> values = facet == null ? new ArrayList<String>() : facet.getIncludedValues(); singleSearchLocale = values.isEmpty() ? null : new Locale(values.get(0)); } if (singleSearchLocale == null) { singleSearchLocale = getLocale(); } return singleSearchLocale; } @Override public void setObject(Object object) { Locale singleSearchLocale = (Locale) object; SimpleSearch simpleSearch = (SimpleSearch) simpleSearchModel.getObject(); simpleSearch.setSingleSearchLocale(singleSearchLocale); } }; languageDropDown = new DropDownChoice("singleSearchLocale", languageModel, languages, languageRenderer) { @Override public String getInputName() { return "singleSearchLocale"; } @Override public boolean isVisible() { SearchInterfaceConfigServices searchInterfaceConfigServices = ConstellioSpringUtils .getSearchInterfaceConfigServices(); SearchInterfaceConfig config = searchInterfaceConfigServices.get(); return config.isLanguageInSearchForm(); } @Override protected CharSequence getDefaultChoice(Object selected) { return ""; }; }; searchButton = new Button("searchButton") { @Override public String getMarkupId() { return super.getId(); } @Override public String getInputName() { return super.getId(); } }; String submitImgUrl = "" + urlFor(new ResourceReference(BaseConstellioPage.class, "images/ico_loupe.png")); add(searchForm); searchForm.add(simpleSearchFormDiv); searchForm.add(advancedSearchFormDiv); searchForm.add(hiddenFields); queryField.add(new SetFocusBehavior(queryField)); addChoice(SimpleSearch.ALL_WORDS); addChoice(SimpleSearch.AT_LEAST_ONE_WORD); addChoice(SimpleSearch.EXACT_EXPRESSION); simpleSearchFormDiv.add(queryField); simpleSearchFormDiv.add(searchTypeField); simpleSearchFormDiv.add(languageDropDown); simpleSearchFormDiv.add(searchButton); advancedSearchFormDiv.add(advancedSearchPanel); searchButton.add(new SimpleAttributeModifier("src", submitImgUrl)); }
From source file:it.govpay.web.utils.Utils.java
public Map<String, Map<String, String>> getMapLingue() { Map<String, Map<String, String>> map = new HashMap<String, Map<String, String>>(); for (Locale locale : Utils.getListaLingueDisponibili()) { Map<String, String> etichetteLingua = this.getEtichetteLingua(locale); map.put(locale.getLanguage(), etichetteLingua); }/* w w w . j a v a2s . co m*/ return map; }
From source file:com.salesmanager.core.service.reference.ReferenceService.java
@Transactional public Collection<DynamicLabel> getDynamicLabels(int merchantId, int sectionId, Locale locale) throws Exception { return dynamicLabelDao.findByMerchantIdAndSectionIdAndLanguageId(merchantId, sectionId, LanguageUtil.getLanguageNumberCode(locale.getLanguage())); }
From source file:com.salesmanager.core.service.reference.ReferenceService.java
@Transactional public Collection<DynamicLabel> getDynamicLabels(int merchantId, List<Integer> sections, Locale locale) throws Exception { return dynamicLabelDao.findByMerchantIdAnsSectionIdsAndLanguageId(merchantId, sections, LanguageUtil.getLanguageNumberCode(locale.getLanguage())); }
From source file:com.icesoft.faces.context.DOMResponseWriter.java
private void enhanceHtml(Element html) { //add lang attribute Locale locale = context.getViewRoot().getLocale(); //id required for forwarded (server-side) redirects html.setAttribute("id", "document:html"); html.setAttribute("lang", locale.getLanguage()); }
From source file:com.hiperium.bo.manager.exception.ExceptionManager.java
/** * This method finds the name of the entity table required for error message * generation in the case of Foreign Keys. * /*from w ww . j a v a 2s. c om*/ * @param infoExcepcion * Exception information detail * @param locale * user logged locale * @return the detail of the referenced table * @throws EntidadNoEncontradaException * if the method not found the referenced entity table detail */ private String findEntityTableName(InformationException infoExcepcion, Locale locale) throws NoResultException, InformationException { this.log.debug("findEntityTableName - START"); String message = infoExcepcion.getMessage(); String[] messageSplit = message.split("fk_"); String key = null; if (messageSplit.length > 0) { key = "fk_" + messageSplit[1].split("\"")[0]; } Integrity integrity = this.integrityDAO.findByConstraintName(key); if (integrity == null) { throw new NoResultException(key); } String tableCode = integrity.getReferencedTableName(); EntityLanguagePK languagePK = new EntityLanguagePK(tableCode, locale.getLanguage()); EntityLanguage entityLanguage = this.entityLanguageDAO.findById(languagePK, false, true); String entityName = null; if (entityLanguage == null) { EntityTable entityTable = this.entityTableDAO.findById(tableCode, false, true); if (entityTable == null) { throw new NoResultException(tableCode); } } else { entityName = entityLanguage.getText(); } this.log.debug("findEntityTableName - END"); return entityName; }