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:io.cfp.auth.service.EmailingService.java

private String getTemplatePath(final String emailTemplate, final Locale locale) {
    String language = locale.getLanguage();
    if (!"fr".equals(language)) {
        language = "en";
    }/*from w ww  . j  a  va  2 s .c  o  m*/
    return "mails/" + language + "/" + emailTemplate;
}

From source file:codes.thischwa.c5c.impl.FilemanagerMessageResolver.java

@Override
public String getMessage(Locale locale, FilemanagerException.Key key) throws IllegalArgumentException {
    String lang = locale.getLanguage().toLowerCase();
    if (!messageStore.containsKey(lang)) {
        logger.warn("Language [{}] not supported, take the default.", lang);
        lang = PropertiesLoader.getDefaultLocale().getLanguage().toLowerCase();
    }//w  ww. j a va 2  s  .c  o m
    Map<String, String> messages = messageStore.get(lang);
    if (!messages.containsKey(key.getPropertyName()))
        throw new IllegalArgumentException("Message key not found: " + key.getPropertyName());
    return messages.get(key.getPropertyName());
}

From source file:com.nominanuda.springsoy.SoyViewResolver.java

public View resolveViewName(String viewName, Locale locale) throws Exception {
    return soySource.hasFunction(viewName, locale.getLanguage()) ? new SoyView(viewName,
            soySource.getSoyTofu(locale.getLanguage()), soySource.getBundle(locale.getLanguage())) : null;
}

From source file:com.sample.application.email.srv.EmailTemplateRepositoryImp.java

@Override
public String getContent(String template, Locale locale, Map<String, String> parameters) {

    String templateName = template + ((locale == null ? "" : "-" + locale.getLanguage()));

    Context ctx = new Context();
    ctx.setVariables(parameters);//from   www  . j a  va 2  s .c  o m

    return this.templateEngine.process(emailTemplates.getTemplateMap().get(templateName).getContentFileName(),
            ctx);
}

From source file:com.manydesigns.portofino.i18n.ResourceBundleManager.java

protected String getBundleName(String baseName, Locale locale) {
    String language = locale.getLanguage();
    String country = locale.getCountry();
    String variant = locale.getVariant();

    if (StringUtils.isBlank(language) && StringUtils.isBlank(country) && StringUtils.isBlank(variant)) {
        return baseName;
    }//from  w  w  w  .  j a  v a2 s  . co  m

    String name = baseName + "_";
    if (!StringUtils.isBlank(variant)) {
        name += language + "_" + country + "_" + variant;
    } else if (!StringUtils.isBlank(country)) {
        name += language + "_" + country;
    } else {
        name += language;
    }
    return name;
}

From source file:countries.ListCountry.java

/** Create Map with country code and languages. */
public void initLanguageMap() {

    for (Locale locale : getAvailableLocales()) {
        if (!isBlank(locale.getDisplayCountry())) {
            languagesOfCountries.put(locale.getCountry(), locale.getLanguage());
        }/*w w  w  .ja v a2s .c  o  m*/
    }
}

From source file:fi.helsinki.opintoni.service.converter.CourseRecommendationConverter.java

private String getRecommendedCourseTitle(LeikiCourseRecommendation leikiCourseRecommendation, Locale locale) {
    return leikiCourseRecommendation.tags.stream()
            .filter(tag -> tag.name.equals(LEIKI_LANG_TAG_PREFIX + locale.getLanguage())).findFirst()
            .flatMap(tag -> tag.values.stream().findFirst()).orElse(leikiCourseRecommendation.title);
}

From source file:it.tidalwave.northernwind.core.impl.model.DefaultRequestLocaleManager.java

/*******************************************************************************************************************
 *
 * {@inheritDoc}//from  w  ww .  j a v a 2s . co  m
 *
 ******************************************************************************************************************/
@Override
@Nonnull
public List<String> getLocaleSuffixes() {
    final List<String> suffixes = new ArrayList<>();
    suffixes.add("");

    for (final Locale locale : getLocales()) {
        suffixes.add("_" + locale.getLanguage());
    }

    return suffixes;
}

From source file:com.isalnikov.controller.MessageController.java

@RequestMapping(value = { "/message/{code}" }, method = RequestMethod.GET)
@ResponseBody/*from ww w  . j  ava 2s.  c  om*/
public ResponseEntity index(@PathVariable("code") String code, Locale locale) {

    String result = messageSource.getMessage(code, new Object[] {}, locale);
    System.out.println(String.format("%s  :  %s", locale.getLanguage(), result));

    String res = String.format("%s  :  %s", locale.getLanguage(), messageHelper.getMessage(code));

    HttpHeaders headers = new HttpHeaders();
    headers.add("Content-type", "application/json;charset=UTF-8");
    ResponseEntity responseEntity = new ResponseEntity<>(res, headers, HttpStatus.OK);
    return responseEntity;
}

From source file:com.qcadoo.customTranslation.internal.CustomTranslationResolverImpl.java

@Override
public String getCustomTranslation(final String key, final Locale locale, final String[] args) {
    String translation = customTranslationCacheService.getCustomTranslation(key, locale.getLanguage());

    if (translation == null) {
        return null;
    } else {//from ww w .j  a  v a  2  s  .c  om
        translation = translation.replace("'", "''");

        Object[] argsToUse = args;

        if (!ObjectUtils.isEmpty(argsToUse)) {
            argsToUse = ArrayUtils.EMPTY_OBJECT_ARRAY;
        }

        MessageFormat messageFormat = new MessageFormat(translation);

        return messageFormat.format(argsToUse);
    }
}