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:com.doculibre.constellio.lucene.impl.SkosIndexHelperImpl.java

@Override
public List<SkosConcept> searchAltLabel(String input, Thesaurus thesaurus, Locale locale) {
    input = adjustInputWildcard(input);//from   ww w . ja v a  2 s .  c o m
    StringBuffer luceneQuery = new StringBuffer();
    luceneQuery.append(THESAURUS_ID + ":" + thesaurus.getId());
    luceneQuery.append(" AND ");
    if (locale != null) {
        String suffix = "_" + locale.getLanguage();
        luceneQuery.append(ALT_LABEL + suffix + ":" + input);
    } else {
        luceneQuery.append(ALT_LABEL + ":" + input);
    }
    return super.search(luceneQuery.toString());
}

From source file:com.doculibre.constellio.lucene.impl.SkosIndexHelperImpl.java

@Override
public List<SkosConcept> searchPrefLabel(String input, Thesaurus thesaurus, Locale locale) {
    input = adjustInputWildcard(input);//ww w.java  2s. c o m
    StringBuffer luceneQuery = new StringBuffer();
    luceneQuery.append(THESAURUS_ID + ":" + thesaurus.getId());
    luceneQuery.append(" AND ");
    if (locale != null) {
        String suffix = "_" + locale.getLanguage();
        luceneQuery.append(PREF_LABEL + suffix + ":" + input);
    } else {
        luceneQuery.append(PREF_LABEL + ":" + input);
    }
    return super.search(luceneQuery.toString());
}

From source file:com.daugherty.e2c.persistence.data.jdbc.JdbcSupplierDao.java

@Override
public Supplier loadLatest(Long id, Locale locale) {
    LOGGER.debug("Looking up latest supplier with ID " + id);
    String sql = getSql("supplier/loadLatest.sql");
    SqlParameterSource parameterSource = new MapSqlParameterSource().addValue("partyId", id)
            .addValue(SqlQueryCriteria.LANGUAGE_PARAMETER_NAME, locale.getLanguage());
    Supplier supplier = null;/*w  w w . j  av a 2  s  .  c  o  m*/
    try {
        supplier = jdbcTemplate.query(sql, parameterSource, new SupplierResultSetExtractor()).get(0);
    } catch (IndexOutOfBoundsException e) {
        throw new EmptyResultDataAccessException(1);
    }

    return supplier;
}

From source file:alfio.util.TemplateResource.java

public String getSavedName(Locale locale) {
    return name() + "_" + locale.getLanguage() + ".ms";
}

From source file:com.daugherty.e2c.persistence.data.jdbc.JdbcSupplierDao.java

@Override
public Supplier loadApproved(Long id, Locale locale) {
    LOGGER.debug("Looking up approved supplier with ID " + id);
    String sql = getSql("supplier/loadApproved.sql");
    SqlParameterSource parameterSource = new MapSqlParameterSource().addValue("partyId", id)
            .addValue(SqlQueryCriteria.LANGUAGE_PARAMETER_NAME, locale.getLanguage());
    Supplier supplier = null;/*  ww w  . j a va2 s .co m*/
    try {
        supplier = jdbcTemplate.query(sql, parameterSource, new SupplierResultSetExtractor()).get(0);
    } catch (IndexOutOfBoundsException e) {
        throw new EmptyResultDataAccessException(1);
    }

    return supplier;
}

From source file:com.jsmartframework.web.manager.BeanHelper.java

Map<String, Object> getExposeVarMapping(Field field) {
    Locale locale = WebContext.getLocale();
    String language = locale != null ? locale.getLanguage() : Locale.getDefault().getLanguage();

    Map<String, WebText.WebTextSet> localeTexts = varMappingFields.get(field);
    if (localeTexts != null) {
        if (localeTexts.containsKey(language)) {
            return localeTexts.get(language).getValues();
        }//  w w  w. j a  v a2s  . co  m
        return localeTexts.get(Locale.getDefault().getLanguage()).getValues();
    }
    return null;
}

From source file:nl.surfnet.coin.selfservice.service.impl.CsaMock.java

private String getLocale() {
    Locale locale = null;
    ServletRequestAttributes sra = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    if (sra != null) {
        HttpServletRequest request = sra.getRequest();
        if (request != null) {
            locale = RequestContextUtils.getLocale(request);
        }//from w  w  w  .ja  va2  s.  c  o  m
    }
    return locale != null ? locale.getLanguage() : "en";

}

From source file:com.stimulus.struts.BaseBean.java

protected Locale getLocale() {
    Locale locale = Locale.getDefault();
    String country = locale.getCountry();
    ActionContext context = ActionContext.getActionContext();
    if (context != null) {
        HttpServletRequest request = context.getRequest();
        if (request != null)
            locale = request.getLocale();
    }/*w w w.jav  a2 s .co  m*/
    if (locale.getCountry().length() < 1 && locale.getLanguage().length() > 0) {
        locale = new Locale(locale.getLanguage(), Locale.getDefault().getCountry());
    }
    String country2 = locale.getCountry();
    //if (locale.getCountry().equalsIgnoreCase("ZA"))
    //      locale = Locale.UK; // bug in JVM concerning date formatting in South Africa
    return locale;
}

From source file:com.erudika.scoold.utils.ScooldRequestInterceptor.java

@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
        ModelAndView modelAndView) throws Exception {

    if (modelAndView == null || StringUtils.startsWith(modelAndView.getViewName(), "redirect:")) {
        return; // skip if redirect
    }//from ww  w  .  ja v  a2  s  .  c o  m

    /*============================*
     * COMMON MODEL FOR ALL PAGES *
     *============================*/

    // Misc
    modelAndView.addObject("HOMEPAGE", HOMEPAGE);
    modelAndView.addObject("APPNAME", Config.APP_NAME);
    modelAndView.addObject("CDN_URL", CDN_URL);
    modelAndView.addObject("DESCRIPTION", Config.getConfigParam("meta_description", ""));
    modelAndView.addObject("KEYWORDS", Config.getConfigParam("meta_keywords", ""));
    modelAndView.addObject("IN_PRODUCTION", Config.IN_PRODUCTION);
    modelAndView.addObject("IN_DEVELOPMENT", !Config.IN_PRODUCTION);
    modelAndView.addObject("MAX_ITEMS_PER_PAGE", Config.MAX_ITEMS_PER_PAGE);
    modelAndView.addObject("SESSION_TIMEOUT_SEC", Config.SESSION_TIMEOUT_SEC);
    modelAndView.addObject("TOKEN_PREFIX", TOKEN_PREFIX);
    modelAndView.addObject("FB_APP_ID", Config.FB_APP_ID);
    modelAndView.addObject("GMAPS_API_KEY", Config.getConfigParam("gmaps_api_key", ""));
    modelAndView.addObject("GOOGLE_CLIENT_ID", Config.getConfigParam("google_client_id", ""));
    modelAndView.addObject("GOOGLE_ANALYTICS_ID", Config.getConfigParam("google_analytics_id", ""));
    modelAndView.addObject("includeHighlightJS", Config.getConfigBoolean("code_highlighting_enabled", true));
    modelAndView.addObject("isAjaxRequest", utils.isAjaxRequest(request));
    modelAndView.addObject("reportTypes", ReportType.values());
    modelAndView.addObject("returnto", StringUtils.removeStart(request.getRequestURI(), CONTEXT_PATH));
    // Configurable constants
    modelAndView.addObject("MAX_TEXT_LENGTH", MAX_TEXT_LENGTH);
    modelAndView.addObject("MAX_TAGS_PER_POST", MAX_TAGS_PER_POST);
    modelAndView.addObject("MAX_REPLIES_PER_POST", MAX_REPLIES_PER_POST);
    modelAndView.addObject("MAX_FAV_TAGS", MAX_FAV_TAGS);
    modelAndView.addObject("ANSWER_VOTEUP_REWARD_AUTHOR", ANSWER_VOTEUP_REWARD_AUTHOR);
    modelAndView.addObject("QUESTION_VOTEUP_REWARD_AUTHOR", QUESTION_VOTEUP_REWARD_AUTHOR);
    modelAndView.addObject("VOTEUP_REWARD_AUTHOR", VOTEUP_REWARD_AUTHOR);
    modelAndView.addObject("ANSWER_APPROVE_REWARD_AUTHOR", ANSWER_APPROVE_REWARD_AUTHOR);
    modelAndView.addObject("ANSWER_APPROVE_REWARD_VOTER", ANSWER_APPROVE_REWARD_VOTER);
    modelAndView.addObject("POST_VOTEDOWN_PENALTY_AUTHOR", POST_VOTEDOWN_PENALTY_AUTHOR);
    modelAndView.addObject("POST_VOTEDOWN_PENALTY_VOTER", POST_VOTEDOWN_PENALTY_VOTER);
    modelAndView.addObject("VOTER_IFHAS", VOTER_IFHAS);
    modelAndView.addObject("COMMENTATOR_IFHAS", COMMENTATOR_IFHAS);
    modelAndView.addObject("CRITIC_IFHAS", CRITIC_IFHAS);
    modelAndView.addObject("SUPPORTER_IFHAS", SUPPORTER_IFHAS);
    modelAndView.addObject("GOODQUESTION_IFHAS", GOODQUESTION_IFHAS);
    modelAndView.addObject("GOODANSWER_IFHAS", GOODANSWER_IFHAS);
    modelAndView.addObject("ENTHUSIAST_IFHAS", ENTHUSIAST_IFHAS);
    modelAndView.addObject("FRESHMAN_IFHAS", FRESHMAN_IFHAS);
    modelAndView.addObject("SCHOLAR_IFHAS", SCHOLAR_IFHAS);
    modelAndView.addObject("TEACHER_IFHAS", TEACHER_IFHAS);
    modelAndView.addObject("PROFESSOR_IFHAS", PROFESSOR_IFHAS);
    modelAndView.addObject("GEEK_IFHAS", GEEK_IFHAS);
    // Cookies
    modelAndView.addObject("localeCookieName", LOCALE_COOKIE);
    modelAndView.addObject("csrfCookieName", CSRF_COOKIE);
    // Paths
    modelAndView.addObject("imageslink", IMAGESLINK); // do not add context path prefix!
    modelAndView.addObject("scriptslink", SCRIPTSLINK); // do not add context path prefix!
    modelAndView.addObject("styleslink", STYLESLINK); // do not add context path prefix!
    modelAndView.addObject("peoplelink", CONTEXT_PATH + PEOPLELINK);
    modelAndView.addObject("profilelink", CONTEXT_PATH + PROFILELINK);
    modelAndView.addObject("searchlink", CONTEXT_PATH + SEARCHLINK);
    modelAndView.addObject("signinlink", CONTEXT_PATH + SIGNINLINK);
    modelAndView.addObject("signoutlink", CONTEXT_PATH + SIGNOUTLINK);
    modelAndView.addObject("aboutlink", CONTEXT_PATH + ABOUTLINK);
    modelAndView.addObject("privacylink", CONTEXT_PATH + PRIVACYLINK);
    modelAndView.addObject("termslink", CONTEXT_PATH + TERMSLINK);
    modelAndView.addObject("tagslink", CONTEXT_PATH + TAGSLINK);
    modelAndView.addObject("settingslink", CONTEXT_PATH + SETTINGSLINK);
    modelAndView.addObject("translatelink", CONTEXT_PATH + TRANSLATELINK);
    modelAndView.addObject("reportslink", CONTEXT_PATH + REPORTSLINK);
    modelAndView.addObject("adminlink", CONTEXT_PATH + ADMINLINK);
    modelAndView.addObject("votedownlink", CONTEXT_PATH + VOTEDOWNLINK);
    modelAndView.addObject("voteuplink", CONTEXT_PATH + VOTEUPLINK);
    modelAndView.addObject("questionlink", CONTEXT_PATH + QUESTIONLINK);
    modelAndView.addObject("questionslink", CONTEXT_PATH + QUESTIONSLINK);
    modelAndView.addObject("commentlink", CONTEXT_PATH + COMMENTLINK);
    modelAndView.addObject("postlink", CONTEXT_PATH + POSTLINK);
    modelAndView.addObject("revisionslink", CONTEXT_PATH + REVISIONSLINK);
    modelAndView.addObject("feedbacklink", CONTEXT_PATH + FEEDBACKLINK);
    modelAndView.addObject("languageslink", CONTEXT_PATH + LANGUAGESLINK);
    // Visual customization
    modelAndView.addObject("navbarFixedClass",
            Config.getConfigBoolean("fixed_nav", false) ? "navbar-fixed" : "none");
    modelAndView.addObject("showBranding", Config.getConfigBoolean("show_branding", true));
    modelAndView.addObject("logoUrl", Config.getConfigParam("logo_url", IMAGESLINK + "/logo.svg"));
    modelAndView.addObject("logoWidth", Config.getConfigInt("logo_width", 90));
    modelAndView.addObject("stylesheetUrl", Config.getConfigParam("stylesheet_url", STYLESLINK + "/style.css"));
    // Auth & Badges
    Profile authUser = (Profile) request.getAttribute(AUTH_USER_ATTRIBUTE);
    modelAndView.addObject("infoStripMsg",
            authUser == null ? Config.getConfigParam("welcome_message", "") : "");
    modelAndView.addObject("authenticated", authUser != null);
    modelAndView.addObject("canComment", utils.canComment(authUser, request));
    modelAndView.addObject("isMod", utils.isMod(authUser));
    modelAndView.addObject("isAdmin", utils.isAdmin(authUser));
    modelAndView.addObject("utils", Utils.getInstance());
    modelAndView.addObject("scooldUtils", utils);
    modelAndView.addObject("authUser", authUser);
    modelAndView.addObject("badgelist", utils.checkForBadges(authUser, request));
    modelAndView.addObject("request", request);
    // Spaces
    modelAndView.addObject("currentSpace",
            utils.getValidSpaceId(authUser, getCookieValue(request, SPACE_COOKIE)));
    // Language
    Locale currentLocale = utils.getCurrentLocale(utils.getLanguageCode(request), request);
    modelAndView.addObject("currentLocale", currentLocale);
    modelAndView.addObject("lang", utils.getLang(currentLocale));
    modelAndView.addObject("langDirection", utils.isLanguageRTL(currentLocale.getLanguage()) ? "RTL" : "LTR");
    // Pagination
    // check for AJAX pagination requests
    if (utils.isAjaxRequest(request) && (utils.param(request, "page") || utils.param(request, "page1")
            || utils.param(request, "page2"))) {
        modelAndView.setViewName("pagination"); // switch to page fragment view
    }
    // CSP, HSTS, etc, headers. See https://securityheaders.com
    utils.setSecurityHeaders(request, response);

    // default metadata for social meta tags
    if (!modelAndView.getModel().containsKey("title")) {
        modelAndView.addObject("title", Config.APP_NAME);
    }
    if (!modelAndView.getModel().containsKey("description")) {
        modelAndView.addObject("description", Config.getConfigParam("meta_description", ""));
    }
    if (!modelAndView.getModel().containsKey("ogimage")) {
        modelAndView.addObject("ogimage", IMAGESLINK + "/logowhite.png");
    }
}

From source file:LocaleMap.java

/**
 * Gets an object based on the given locale. An automatic fallback mechanism is used:
 * if nothing is found for language-COUNTRY-variant, then language-COUNTRY is searched,
 * the language, and finally "" (empty string). If nothing is found null is returned.
 *///w  w w. j a  v a2  s  .c o  m
public Object get(Locale locale) {
    if (map.size() == 0)
        return null;

    String full = getFullKey(locale);

    if (!searchMap.containsKey(full)) {
        if (map.containsKey(full)) {
            Object object = map.get(full);
            searchMap.put(full, object);
            return object;
        }

        String altKey = locale.getLanguage() + '-' + locale.getCountry();
        Object object = map.get(altKey);
        if (object != null) {
            searchMap.put(full, object);
            return object;
        }

        altKey = locale.getLanguage();
        object = map.get(altKey);
        if (object != null) {
            searchMap.put(full, object);
            return object;
        }

        object = map.get("");
        if (object != null) {
            searchMap.put(full, object);
            return object;
        }

        searchMap.put(full, NO_RESULT);
    }

    Object result = searchMap.get(full);
    return result == NO_RESULT ? null : result;
}