Example usage for java.util Locale getLanguage

List of usage examples for java.util Locale getLanguage

Introduction

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

Prototype

public String getLanguage() 

Source Link

Document

Returns the language code of this Locale.

Usage

From source file:jp.terasoluna.fw.web.codelist.AbstractMultilingualCodeListLoader.java

/**
 * ?P?[R?[hXg???B//from w ww . j a va  2  s  .  co  m
 * <p>
 * ?w?P?[R?[hXg????A
 * ??P?[R?[hXg???B
 * 
 * @param locale ?P?[
 * @return R?[hXg
 */
protected CodeBean[] createCodeBeans(Locale locale) {

    if (log.isDebugEnabled()) {
        log.debug("createCodeBeans(" + locale + ") called.");
    }

    if (localeMap == null) {
        if (log.isDebugEnabled()) {
            log.debug("field codeListsMap is null.");
        }
        // codeListsMap?z?B
        return new CodeBean[0];
    }

    if (locale == null) {
        if (log.isDebugEnabled()) {
            log.debug("arg locale is null. replace locale default : " + defaultLocale);
        }
        if (defaultLocale == null) {
            throw new IllegalStateException("Default locale is null.");
        }
        locale = defaultLocale;
    }

    List<CodeBean> codeLists = localeMap.get(locale);

    // R?[hXg???A??P?[???
    if (codeLists == null) {
        if (locale.getVariant().length() > 0) {
            return createCodeBeans(new Locale(locale.getLanguage(), locale.getCountry()));
        } else if (locale.getCountry().length() > 0) {
            return createCodeBeans(new Locale(locale.getLanguage()));
        }

        // codeLists?z?B
        return new CodeBean[0];
    }

    CodeBean[] cb = new CodeBean[codeLists.size()];
    for (int i = 0; i < codeLists.size(); i++) {
        cb[i] = new CodeBean();
        cb[i].setId(codeLists.get(i).getId());
        cb[i].setName(codeLists.get(i).getName());
    }
    return cb;
}

From source file:alfio.manager.WaitingQueueManager.java

public boolean subscribe(Event event, CustomerName customerName, String email, Integer selectedCategoryId,
        Locale userLanguage) {
    try {//from   ww w .j av  a2s .com
        if (configurationManager.getBooleanConfigValue(
                Configuration.from(event.getOrganizationId(), event.getId(), STOP_WAITING_QUEUE_SUBSCRIPTIONS),
                false)) {
            log.info("waiting queue subscription denied for event {} ({})", event.getShortName(),
                    event.getId());
            return false;
        }
        WaitingQueueSubscription.Type subscriptionType = getSubscriptionType(event);
        validateSubscriptionType(event, subscriptionType);
        validateSelectedCategoryId(event.getId(), selectedCategoryId);
        AffectedRowCountAndKey<Integer> key = waitingQueueRepository.insert(event.getId(),
                customerName.getFullName(), customerName.getFirstName(), customerName.getLastName(), email,
                ZonedDateTime.now(event.getZoneId()), userLanguage.getLanguage(), subscriptionType,
                selectedCategoryId);
        notifySubscription(event, customerName, email, userLanguage, subscriptionType);
        pluginManager.handleWaitingQueueSubscription(waitingQueueRepository.loadById(key.getKey()));
        extensionManager.handleWaitingQueueSubscription(waitingQueueRepository.loadById(key.getKey()));
        return true;
    } catch (DuplicateKeyException e) {
        return true;//why are you subscribing twice?
    } catch (Exception e) {
        log.error("error during subscription", e);
        return false;
    }
}

From source file:om.edu.squ.squportal.portlet.dps.registration.postpone.db.PostponeDBImpl.java

/**
 * /*from w w  w.  jav  a2 s .com*/
 * method name  : getPostponeReasons
 * @param locale
 * @return
 * PostponeDBImpl
 * return type  : List<PostponeReason>
 * 
 * purpose      : Get list of default reasons for postpone 
 *
 * Date          :   May 25, 2017 4:15:05 PM
 */
public List<PostponeReason> getPostponeReasons(Locale locale) {
    String SQL_POSTPONE_REASONS = queryPostpone.getProperty(Constants.CONST_SQL_POSTPONE_REASONS);

    RowMapper<PostponeReason> rowMapper = new RowMapper<PostponeReason>() {

        @Override
        public PostponeReason mapRow(ResultSet rs, int rowNum) throws SQLException {
            PostponeReason postponeReason = new PostponeReason();
            postponeReason.setSiscodecd(rs.getString(Constants.CONST_COLMN_SISCODECD));
            postponeReason.setReasonName(rs.getString(Constants.CONST_COLMN_POSTPONE_REASON_NAME));
            return postponeReason;
        }
    };

    Map<String, String> namedParameterMap = new HashMap<String, String>();
    namedParameterMap.put("paramLocale", locale.getLanguage());

    return nPJdbcTemplDpsPostpone.query(SQL_POSTPONE_REASONS, namedParameterMap, rowMapper);
}

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));
        }//ww  w.jav  a2 s .  c om
    } 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:com.salesmanager.central.profile.ProfileAction.java

public String changeLanguage() {

    Context context = super.getContext();

    String language = super.getServletRequest().getParameter("lang");
    if (!StringUtils.isBlank(language)) {

        RefCache cache = RefCache.getInstance();

        Map countries = cache.getAllcountriesmap(LanguageUtil.getLanguageNumberCode(context.getLang()));
        Country c = (Country) countries.get(context.getCountryid());

        Locale locale = new Locale(language, c.getCountryIsoCode2());
        super.setLocale(locale);

        Context ctx = super.getContext();
        ctx.setLang(locale.getLanguage());

    }// w  w w  .  j ava  2 s  .  c  om

    return SUCCESS;

}

From source file:com.doculibre.constellio.entities.search.SimpleSearch.java

public void setSingleSearchLocale(Locale singleSearchLocale) {
    this.singleSearchLocale = singleSearchLocale;
    SearchedFacet languageFacet = getSearchedFacet(IndexField.LANGUAGE_FIELD);
    if (languageFacet != null) {
        languageFacet.getIncludedValues().clear();
        languageFacet.getIncludedValues().add(singleSearchLocale.getLanguage());
    }/*ww  w .j  a v  a 2s . c  o m*/
}

From source file:org.sakaiproject.emailtemplateservice.service.impl.EmailTemplateServiceImpl.java

public EmailTemplate getEmailTemplate(String key, Locale locale) {
    if (key == null || "".equals(key)) {
        throw new IllegalArgumentException("key cannot be null or empty");
    }/*from  w  w w  .j av  a  2  s .  co  m*/

    if (log.isDebugEnabled()) {
        log.debug("getEmailTemplate(key=" + key + ", locale=" + locale + ")");
    }
    EmailTemplate et = null;
    // TODO make this more efficient
    if (locale != null) {
        Search search = new Search("key", key);
        search.addRestriction(new Restriction("locale", locale.toString()));
        et = dao.findOneBySearch(EmailTemplate.class, search);
        if (et == null) {
            search.addRestriction(new Restriction("locale", locale.getLanguage()));
            et = dao.findOneBySearch(EmailTemplate.class, search);
        }
    }
    if (et == null) {
        Search search = new Search("key", key);
        search.addRestriction(new Restriction("locale", EmailTemplate.DEFAULT_LOCALE));
        et = dao.findOneBySearch(EmailTemplate.class, search);
    }
    if (et == null) {
        log.warn("no template found for: " + key + " in locale " + locale);
    }
    return et;
}

From source file:om.edu.squ.squportal.portlet.dps.registration.postpone.db.PostponeDBImpl.java

/**
 * //  ww  w.j  ava 2 s  .  c  o m
 * method name  : getExistingGrades
 * @param studentNo
 * @param locale
 * @return
 * PostponeDBImpl
 * return type  : List<Course>
 * 
 * purpose      : Get existing grades
 *
 * Date          :   Dec 25, 2017 10:44:04 PM
 */
public List<Course> getExistingGrades(String studentNo, Locale locale) {
    String SQL_POSTPONE_SELECT_EXISTING_GRADES = queryPostpone
            .getProperty(Constants.CONST_SQL_POSTPONE_SELECT_EXISTING_GRADES);
    RowMapper<Course> rowMapper = new RowMapper<Course>() {

        @Override
        public Course mapRow(ResultSet rs, int rowNum) throws SQLException {
            Course course = new Course();
            course.setlAbrCourseNo(rs.getString(Constants.CONST_COLMN_L_ABR_CRSNO));
            course.setCourseName(rs.getString(Constants.CONST_COLMN_COURSE_NAME));
            course.setGradeValue(rs.getString(Constants.CONST_COLMN_GRADE_VAL));
            return course;
        }
    };

    Map<String, String> namedParameterMap = new HashMap<String, String>();
    namedParameterMap.put("paramLocale", locale.getLanguage());
    namedParameterMap.put("paramStdNo", studentNo);

    return nPJdbcTemplDpsPostpone.query(SQL_POSTPONE_SELECT_EXISTING_GRADES, namedParameterMap, rowMapper);
}

From source file:com.frameworkset.platform.cms.driver.i18n.CmsLocaleManager.java

/**
 * Adds a locale to the list of available locales.<p>
 * //from   w  w w .j a  va  2 s  . c o  m
 * @param localeName the locale to add
 */
public void addAvailableLocale(String localeName) {

    Locale locale = getLocale(localeName);
    // add full variation (language / country / variant)
    if (!m_availableLocales.contains(locale)) {
        m_availableLocales.add(locale);
        //            if (CmsLog.INIT.isInfoEnabled()) {
        //                CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_I18N_CONFIG_ADD_LOCALE_1, locale));
        //            }
    }
    // add variation with only language and country
    locale = new Locale(locale.getLanguage(), locale.getCountry());
    if (!m_availableLocales.contains(locale)) {
        m_availableLocales.add(locale);
        //            if (CmsLog.INIT.isInfoEnabled()) {
        //                CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_I18N_CONFIG_ADD_LOCALE_1, locale));
        //            }
    }
    // add variation with language only
    locale = new Locale(locale.getLanguage());
    if (!m_availableLocales.contains(locale)) {
        m_availableLocales.add(locale);
        //            if (CmsLog.INIT.isInfoEnabled()) {
        //                CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_I18N_CONFIG_ADD_LOCALE_1, locale));
        //            }
    }
}

From source file:de.knowwe.rdfs.d3web.Rdf2GoPropertyHandler.java

@Override
public Collection<Message> create(OntologyCompiler compiler, Section<PropertyDeclarationType> section) {

    // get Property
    Section<PropertyType> propertySection = Sections.successor(section, PropertyType.class);
    if (propertySection == null) {
        return Messages.asList();
    }/*from  w w  w .  j a va  2s.c  o m*/
    Property<?> property = propertySection.get().getProperty(propertySection);
    if (property == null) {
        return Messages.asList();
    }

    // get NamedObject
    Section<PropertyObjectReference> namendObjectSection = Sections.successor(section,
            PropertyObjectReference.class);
    if (namendObjectSection == null) {
        return Messages.asList();
    }
    List<Identifier> objects = getObjectIdentifiers(compiler, namendObjectSection);
    if (objects.isEmpty()) {
        return Messages.asList();
    }

    Locale locale = PropertyDeclarationHandler.getLocale(section);

    // get content
    Section<PropertyContentType> contentSection = Sections.successor(section, PropertyContentType.class);
    if (contentSection == null) {
        return Messages.asList();
    }
    String content = contentSection.get().getPropertyContent(contentSection);
    if (content == null || content.trim().isEmpty()) {
        return Messages.asList();
    }

    List<Statement> statements = new ArrayList<>();
    Rdf2GoCore core = compiler.getRdf2GoCore();
    for (Identifier namedObject : objects) {
        String externalForm = Rdf2GoUtils.getCleanedExternalForm(namedObject);
        // lns:Identifier lns:has[Property] "propertyString"@Locale
        URI identifierURI = core.createlocalURI(externalForm);
        URI propertyNameURI = core.createlocalURI(getD3webPropertyAsOntologyProperty(property));

        Literal contentLiteral = Locales.isEmpty(locale) ? core.createLiteral(content)
                : core.createLanguageTaggedLiteral(content, locale.getLanguage());
        Rdf2GoUtils.addStatement(core, identifierURI, propertyNameURI, contentLiteral, statements);
        core.addStatements(section, Rdf2GoUtils.toArray(statements));
    }

    return Messages.asList();
}