Example usage for java.util Locale getDisplayLanguage

List of usage examples for java.util Locale getDisplayLanguage

Introduction

In this page you can find the example usage for java.util Locale getDisplayLanguage.

Prototype

public String getDisplayLanguage(Locale inLocale) 

Source Link

Document

Returns a name for the locale's language that is appropriate for display to the user.

Usage

From source file:org.opencms.workplace.commons.CmsPreferences.java

/**
 * Builds the html for the language select box of the start settings.<p>
 * // www .  j a va  2s . co  m
 * @param htmlAttributes optional html attributes for the &lgt;select&gt; tag
 * @return the html for the language select box
 */
public String buildSelectLanguage(String htmlAttributes) {

    // get available locales from the workplace manager
    List locales = OpenCms.getWorkplaceManager().getLocales();
    List options = new ArrayList(locales.size());
    List values = new ArrayList(locales.size());
    int checkedIndex = 0;
    int counter = 0;
    Iterator i = locales.iterator();
    Locale setLocale = getSettings().getUserSettings().getLocale();
    while (i.hasNext()) {
        Locale currentLocale = (Locale) i.next();
        // add all locales to the select box
        String language = currentLocale.getDisplayLanguage(setLocale);
        if (CmsStringUtil.isNotEmpty(currentLocale.getCountry())) {
            language = language + " (" + currentLocale.getDisplayCountry(setLocale) + ")";
        }
        if (CmsStringUtil.isNotEmpty(currentLocale.getVariant())) {
            language = language + " (" + currentLocale.getDisplayVariant(setLocale) + ")";
        }
        options.add(language);
        values.add(currentLocale.toString());
        if (getParamTabWpLanguage().equals(currentLocale.toString())) {
            // mark the currently active locale
            checkedIndex = counter;
        }
        counter++;
    }
    return buildSelect(htmlAttributes, options, values, checkedIndex);
}

From source file:com.silverpeas.workflowdesigner.control.WorkflowDesignerSessionController.java

/**
* Returns names of available languages as configured in the properties, localised for the current
* user/*from  w  w  w  .j a v a 2s  .co m*/
*
* @param fDefault if <code>true</code> the 'default' option shall be included
* @return an array of language names
*/
public String[] retrieveLanguageNames(boolean fDefault) {
    StringTokenizer strtok = new StringTokenizer(getSettings().getString("languages"), ",");
    Locale locale = new Locale(getLanguage());
    List<String> list = new ArrayList<String>(strtok.countTokens() + 1);
    if (fDefault) {
        list.add(getString("workflowDesigner.default"));
    }
    while (strtok.hasMoreTokens()) {
        Locale inLocale = new Locale(strtok.nextToken());

        list.add(inLocale.getDisplayLanguage(locale));
    }
    return list.toArray(new String[list.size()]);
}

From source file:com.doculibre.constellio.wicket.panels.search.SearchFormPanel.java

@SuppressWarnings({ "rawtypes", "unchecked" })
public SearchFormPanel(String id, final IModel simpleSearchModel) {
    super(id);/*from  ww  w  .  j  a  v  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:com.github.spyhunter99.pdf.plugin.PdfMojo.java

/**
 * Generate the given Maven report only if it is not an external report and the report could be generated.
 *
 * @param mojoDescriptor not null, to catch linkage error
 * @param report could be null//from ww  w  . j  a va2  s .  c o m
 * @param locale not null
 * @throws IOException if any
 * @throws MojoExecutionException if any
 * @see #isValidGeneratedReport(MojoDescriptor, File, String)
 * @since 1.1
 */
private void generateMavenReport(MavenReport report, Artifact pluginArtifact, Locale locale)
        throws IOException, MojoExecutionException {
    if (report == null) {
        return;
    }

    String localReportName = report.getName(locale);
    if (!report.canGenerateReport()) {
        getLog().info("Skipped \"" + localReportName + "\" report.");
        getLog().debug("canGenerateReport() was false.");

        return;
    }

    if (report.isExternalReport()) {
        getLog().info("Skipped external \"" + localReportName + "\" report.");
        getLog().debug("isExternalReport() was false.");

        return;
    }

    for (final MavenReport generatedReport : getGeneratedMavenReports(locale)) {
        if (report.getName(locale).equals(generatedReport.getName(locale))) {
            if (getLog().isDebugEnabled()) {
                getLog().debug(report.getName(locale) + " was already generated.");
            }
            return;
        }
    }

    File outDir = new File(getGeneratedSiteDirectoryTmp(), "xdoc");
    if (!locale.getLanguage().equals(defaultLocale.getLanguage())) {
        outDir = new File(new File(getGeneratedSiteDirectoryTmp(), locale.getLanguage()), "xdoc");
    }
    outDir.mkdirs();

    File generatedReport = new File(outDir, report.getOutputName() + ".xml");

    String excludes = getDefaultExcludesWithLocales(getAvailableLocales(), getDefaultLocale());
    List<String> files = FileUtils.getFileNames(siteDirectory, "*/" + report.getOutputName() + ".*", excludes,
            false);
    if (!locale.getLanguage().equals(defaultLocale.getLanguage())) {
        files = FileUtils.getFileNames(new File(siteDirectory, locale.getLanguage()),
                "*/" + report.getOutputName() + ".*", excludes, false);
    }

    if (files.size() != 0) {
        String displayLanguage = locale.getDisplayLanguage(Locale.ENGLISH);

        if (getLog().isInfoEnabled()) {
            getLog().info("Skipped \"" + report.getName(locale) + "\" report, file \"" + report.getOutputName()
                    + "\" already exists for the " + displayLanguage + " version.");
        }

        return;
    }

    if (getLog().isInfoEnabled()) {
        getLog().info("Generating \"" + localReportName + "\" report.");
    }

    StringWriter sw = new StringWriter();

    PdfSink sink = null;
    try {
        sink = new PdfSink(sw);
        org.codehaus.doxia.sink.Sink proxy = (org.codehaus.doxia.sink.Sink) Proxy.newProxyInstance(
                org.codehaus.doxia.sink.Sink.class.getClassLoader(),
                new Class[] { org.codehaus.doxia.sink.Sink.class }, new SinkDelegate(sink));
        report.generate(proxy, locale);
    } catch (MavenReportException e) {
        throw new MojoExecutionException("MavenReportException: " + e.getMessage(), e);
    } finally {
        if (sink != null) {
            sink.close();
        }
    }

    writeGeneratedReport(sw.toString(), generatedReport);

    if (isValidGeneratedReport(pluginArtifact, generatedReport, localReportName)) {
        getGeneratedMavenReports(locale).add(report);
    }
}

From source file:net.sf.dvstar.transmission.TransmissionView.java

private void initLocale() {

    List<Locale> listLocales = Tools.getListOfAvailLanguages();
    for (int i = 0; i < listLocales.size(); i++) {
        Locale locale = listLocales.get(i);

        String country = locale.getCountry().length() > 0 ? locale.getCountry() : "uk";
        String flag = "/net/sf/dvstar/transmission/resources/images/flags/flags_" + country.toLowerCase()
                + ".png";

        URL urlFlag = getClass().getResource(flag);

        ImageIcon iconFlag = new ImageIcon(urlFlag);
        JMenuItem miLocale;//from w w  w. ja va2 s . c om
        if (iconFlag != null) {
            miLocale = new JMenuItem(locale.getDisplayLanguage(Locale.ENGLISH), iconFlag);
        } else {
            miLocale = new JMenuItem(locale.getDisplayLanguage(Locale.ENGLISH));
        }

        miLocale.addActionListener(new LocaleActionListener(locale));

        mnConfigLocale.add(miLocale);
    }
}