Example usage for java.util Locale Locale

List of usage examples for java.util Locale Locale

Introduction

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

Prototype

public Locale(String language) 

Source Link

Document

Construct a locale from a language code.

Usage

From source file:it.imtech.bookimporter.BookUtilityTest.java

/**
 * Test of getOrderedLanguages method, of class BookUtility.
 *//* w w  w.  ja  va2  s  .  c om*/
public void testGetOrderedLanguages() {
    System.out.println("Test Ordering configuration languages: method -> getOrderedLanguages");
    TreeMap<String, String> en = new TreeMap<String, String>();
    en.put("English", "en");
    en.put("German", "de");
    en.put("Italian", "it");

    TreeMap<String, String> it = new TreeMap<String, String>();
    it.put("Inglese", "en");
    it.put("Italiano", "it");
    it.put("Tedesco", "de");

    TreeMap<String, String> de = new TreeMap<String, String>();
    de.put("Deutsch", "de");
    de.put("English", "en");
    de.put("Italienisch", "it");

    try {
        CustomClassLoader loader = new CustomClassLoader();

        Locale locale = new Locale("en");
        ResourceBundle bundle = ResourceBundle.getBundle(RESOURCES, locale, loader);
        XMLConfiguration config = new XMLConfiguration(new File(DEBUG_XML));
        TreeMap<String, String> result = BookUtility.getOrderedLanguages(config, bundle);
        assertEquals(en, result);

        locale = new Locale("it");
        bundle = ResourceBundle.getBundle(RESOURCES, locale, loader);
        config = new XMLConfiguration(new File(DEBUG_XML));
        result = BookUtility.getOrderedLanguages(config, bundle);
        assertEquals(it, result);

        locale = new Locale("de");
        bundle = ResourceBundle.getBundle(RESOURCES, locale, loader);
        config = new XMLConfiguration(new File(DEBUG_XML));
        result = BookUtility.getOrderedLanguages(config, bundle);
        assertEquals(de, result);
    } catch (ConfigurationException e) {
        fail("Ordering Language Test failed: ConfigurationException:- " + e.getMessage());
    }
}

From source file:br.com.mv.modulo.WebConfig.java

@Bean
@Override//from   w  ww. ja v a2s.co m
public LocaleResolver localeResolver() {
    SessionLocaleResolver slr = new SessionLocaleResolver();
    slr.setDefaultLocale(new Locale("pt-BR"));
    return slr;
}

From source file:fi.helsinki.opintoni.util.CoursePageUriBuilderTest.java

@Test
public void thatSwedishUrisAreLocalized() {
    LocaleContextHolder.setLocale(new Locale("sv"));

    CoursePageCourseImplementation coursePage = createCoursePage();
    assertThat(coursePageUriBuilder.getLocalizedUri(coursePage)).isEqualTo("http://courses.helsinki.fi/sv/123");
}

From source file:org.smigo.user.UserSetLocaleResolver.java

@Override
public Locale resolveLocale(HttpServletRequest req) {
    final Principal userPrincipal = req.getUserPrincipal();
    if (userPrincipal != null) {
        User user = userDao.getUsersByUsername(userPrincipal.getName()).get(0);
        if (user.getLocale() != null) {
            return user.getLocale();
        }/*from   w  w  w  . j av a2  s .c o m*/
    }

    final String subDomain = req.getServerName().split("\\.")[0];
    for (Language language : Language.values()) {
        if (language.getLocale().getLanguage().equals(subDomain)) {
            return new Locale(subDomain);
        }
    }

    return req.getLocale() == null ? Locale.ENGLISH : req.getLocale();
}

From source file:org.openehealth.coala.beans.LocaleHandler.java

/**
 * Changes the locale//from   w w w. j a  va2s .co  m
 * @return 
 */
public String changeLocale() {
    FacesContext.getCurrentInstance().getViewRoot().setLocale(new Locale(locale));
    return null;
}

From source file:net.sourceforge.fenixedu.presentationTier.docs.thesis.ApproveJuryDocument.java

@Override
protected void fillGeneric() {
    super.fillGeneric();

    Thesis thesis = getThesis();/*from  w  w  w . j  a  v a  2  s. c om*/

    final ThesisEvaluationParticipant thesisEvaluationParticipant = thesis.getProposalApprover();
    final String author;
    final String date;
    final String ccAuthor;
    final String ccDate;
    if (thesisEvaluationParticipant == null) {
        author = date = ccAuthor = ccDate = StringUtils.EMPTY;
    } else {
        final Person person = thesisEvaluationParticipant.getPerson();
        if (person != null && person.hasRole(RoleType.SCIENTIFIC_COUNCIL)) {
            author = date = StringUtils.EMPTY;
            ccAuthor = thesisEvaluationParticipant.getPersonName();
            ccDate = String.format(new Locale("pt"), "%1$td de %1$tB de %1$tY", thesis.getApproval().toDate());
        } else {
            ccAuthor = ccDate = StringUtils.EMPTY;
            author = thesisEvaluationParticipant.getPersonName();
            date = String.format(new Locale("pt"), "%1$td de %1$tB de %1$tY", thesis.getApproval().toDate());
        }
    }

    addParameter("author", author);
    addParameter("date", date);
    addParameter("ccAuthor", ccAuthor);
    addParameter("ccDate", ccDate);
}

From source file:se.vgregion.portal.medcontrol.MedControlViewControllerTest.java

@Before
public void setUp() throws Exception {
    mockRenderRequest = new MockRenderRequest();
    mockRenderResponse = new MockRenderResponse();
    mockRenderResponse.setLocale(new Locale("sv"));
    mockPortletConfig = new MockPortletConfig();
    mockPortletConfig.setResourceBundle(new Locale("sv"), new ResourceBundleMock());
    medControlViewController = new MedControlViewController();
    mockDeviationService = new DeviationServiceMock();
    medControlViewController.setDeviationService(mockDeviationService);
}

From source file:org.ng200.openolympus.controller.TranslationController.java

@RequestMapping(value = "/translation")
public Map<String, String> strings(WebRequest webRequest, @RequestParam("lang") String lang) {
    if (webRequest.checkNotModified(this.messageSource.getLastModified())) {
        return null;
    }/*from   ww  w . ja  v a 2 s. c o  m*/
    final HashMap<String, String> map = new HashMap<>();
    for (final Entry<Object, Object> e : this.messageSource.getKeys(new Locale(lang)).entrySet()) {
        map.put(e.getKey().toString(), e.getValue().toString());
    }
    return map;
}

From source file:com.seajas.search.utilities.spring.security.UsernamePasswordLanguageAuthenticationFilter.java

/**
 * Set the user details, where we explicitly set the user language, if provided.
 * //from ww w  . j  ava  2 s  .c om
 * @param request
 * @param authRequest
 */
@Override
protected void setDetails(HttpServletRequest request, UsernamePasswordAuthenticationToken authRequest) {
    if (!StringUtils.isEmpty(request.getParameter(SPRING_SECURITY_FORM_LANGUAGE_KEY))) {
        if (logger.isDebugEnabled())
            logger.debug("Requested login session language is '"
                    + request.getParameter(SPRING_SECURITY_FORM_LANGUAGE_KEY) + "'");

        WebUtils.setSessionAttribute(request, AcceptHeaderSessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME,
                new Locale(request.getParameter(SPRING_SECURITY_FORM_LANGUAGE_KEY)));
    }
}

From source file:fi.helsinki.opintoni.integration.unisport.UnisportRestClient.java

@Override
public Optional<UnisportUser> getUnisportUserByPrincipal(String username) {
    UnisportUser unisportUser = null;/*from ww  w  .j  a va2s  . c om*/
    try {
        unisportUser = restTemplate
                .exchange("{baseUrl}/api/v1/{locale}/ext/opintoni/authorization?eppn={userName}",
                        HttpMethod.GET, null, new ParameterizedTypeReference<UnisportUser>() {
                        }, baseUrl, new Locale("en"), username)
                .getBody();

    } catch (HttpStatusCodeException e) {
        if (!e.getStatusCode().equals(HttpStatus.NOT_FOUND)) {
            throw e;
        }
    }
    return Optional.ofNullable(unisportUser);
}