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, String country) 

Source Link

Document

Construct a locale from language and country.

Usage

From source file:eu.eubrazilcc.lvl.core.util.LocaleUtils.java

/**
 * Obtains an unmodifiable list of installed locales. This method is a wrapper around
 * {@link Locale#getAvailableLocales()}, which caches the locales and uses generics.
 * @return country names./*from  w  ww . ja va2s .  c om*/
 */
public static ImmutableList<Locale> availableLocaleList() {
    if (availableLocaleList == null) {
        synchronized (LocaleUtils.class) {
            if (availableLocaleList == null) {
                final ImmutableList.Builder<Locale> builder = new ImmutableList.Builder<Locale>();
                final String[] locales = getISOCountries();
                for (final String countryCode : locales) {
                    builder.add(new Locale("", countryCode));
                }
                availableLocaleList = builder.build();
            }
        }
    }
    return availableLocaleList;
}

From source file:com.pamarin.api.converter.JsonLocaleDeserializer.java

@Override
public Locale deserialize(JsonParser jp, DeserializationContext dc)
        throws IOException, JsonProcessingException {

    String localeCode = jp.getText();
    if (!hasText(localeCode)) {
        return null;
    }/*from   www .j  ava2  s .  c  om*/

    String[] split = StringUtils.split(localeCode, "_");

    if (split.length != 2) {
        throw new IOException("not support locale, require language and country");
    }

    if (!hasText(split[0])) {
        throw new IOException("not support locale, require language");
    }

    if (!hasText(split[1])) {
        throw new IOException("not support locale, require country");
    }

    return new Locale(split[0], split[1]);
}

From source file:com.tianjunwei.interceptor.LanguageCookieInterceptor.java

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
        throws Exception {
    String language = request.getParameter("language");
    if (language != null && language.equals("zh")) {
        Locale locale = new Locale("zh", "CN");
        (new CookieLocaleResolver()).setLocale(request, response, locale);
        request.setAttribute("language", language);
    } else if (language != null && language.equals("en")) {
        Locale locale = new Locale("en", "US");
        (new CookieLocaleResolver()).setLocale(request, response, locale);
        request.setAttribute("language", language);
    } else {//  w w w .ja v a 2s  .  c o m
        (new CookieLocaleResolver()).setLocale(request, response, LocaleContextHolder.getLocale());
        language = LocaleContextHolder.getLocale().getLanguage();
        request.setAttribute("language", language);
    }
    return true;
}

From source file:com.opensymphony.xwork2.conversion.impl.StringConverterTest.java

public void testIntegerToStringConversionPL() throws Exception {
    // given/*from   www.j av a2 s . co m*/
    StringConverter converter = new StringConverter();
    Map<String, Object> context = new HashMap<>();
    context.put(ActionContext.LOCALE, new Locale("pl", "PL"));

    // when
    Object value = converter.convertValue(context, null, null, null, Integer.MIN_VALUE, null);

    // then
    assertEquals("" + Integer.MIN_VALUE, value);
}

From source file:Main.java

/**
 * <p>Obtains the list of locales to search through when performing
 * a locale search.</p>/*  w w  w  .  j  a v a  2  s.  c  om*/
 *
 * <pre>
 * localeLookupList(Locale("fr", "CA", "xxx"), Locale("en"))
 *   = [Locale("fr","CA","xxx"), Locale("fr","CA"), Locale("fr"), Locale("en"]
 * </pre>
 *
 * <p>The result list begins with the most specific locale, then the
 * next more general and so on, finishing with the default locale.
 * The list will never contain the same locale twice.</p>
 *
 * @param locale  the locale to start from, null returns empty list
 * @param defaultLocale  the default locale to use if no other is found
 * @return the unmodifiable list of Locale objects, 0 being locale, not null
 */
public static List<Locale> localeLookupList(Locale locale, Locale defaultLocale) {
    List<Locale> list = new ArrayList<Locale>(4);
    if (locale != null) {
        list.add(locale);
        if (locale.getVariant().length() > 0) {
            list.add(new Locale(locale.getLanguage(), locale.getCountry()));
        }
        if (locale.getCountry().length() > 0) {
            list.add(new Locale(locale.getLanguage(), ""));
        }
        if (!list.contains(defaultLocale)) {
            list.add(defaultLocale);
        }
    }
    return Collections.unmodifiableList(list);
}

From source file:com.smi.travel.datalayer.view.dao.impl.HotelInboundImpl.java

@Override
public List getHotelInboundVoucher(String hotelID) {
    Session session = this.sessionFactory.openSession();
    List data = new ArrayList();
    Date thisdate = new Date();
    UtilityFunction util = new UtilityFunction();
    HotelInbound inbound = new HotelInbound();
    inbound.setSystemdate(new SimpleDateFormat("dd MMM yyyy", new Locale("us", "us")).format(thisdate));

    List<Object[]> QueryHotelList = session
            .createSQLQuery(" SELECT * FROM `hotel_inbound_info` where `hotel_inbound_info`.id = " + hotelID)
            .addScalar("hotel_ref", Hibernate.STRING).addScalar("adult", Hibernate.STRING)
            .addScalar("child", Hibernate.STRING).addScalar("infant", Hibernate.STRING)
            .addScalar("total", Hibernate.STRING).addScalar("remark", Hibernate.STRING)
            .addScalar("name", Hibernate.STRING).addScalar("checkin", Hibernate.DATE)
            .addScalar("checkout", Hibernate.DATE).addScalar("total_date", Hibernate.STRING).list();
    for (Object[] B : QueryHotelList) {
        inbound.setHotelref(util.ConvertString(B[0]));
        inbound.setAdult(util.ConvertString(B[1]));
        inbound.setChild(util.ConvertString(B[2]));
        inbound.setInfant(util.ConvertString(B[3]));
        inbound.setTotal(util.ConvertString(B[4]));
        inbound.setRemark(util.ConvertString(B[5]));
        inbound.setMeal(util.ConvertString(B[6]));
        inbound.setCheckin(new SimpleDateFormat("dd MMM yyyy", new Locale("us", "us")).format((Date) B[7]));
        inbound.setCheckout(new SimpleDateFormat("dd MMM yyyy", new Locale("us", "us")).format((Date) B[8]));
        inbound.setNight(util.ConvertString(B[9]));
    }/* w  w w .  jav a  2  s  . co  m*/
    //inbound.setCheckin((Date)B[7]);

    List<String> QueryRoomList = session.createSQLQuery(
            " SELECT * FROM `hotel_inbound_room` where `hotel_inbound_room`.booking_hotel_id = " + hotelID)
            .addScalar("room", Hibernate.STRING).list();
    for (int i = 0; i < QueryRoomList.size(); i++) {
        if (i == 0) {
            inbound.setRoom1(util.CheckNullString(QueryRoomList.get(i)));
        } else if (i == 2) {
            inbound.setRoom2(util.CheckNullString(QueryRoomList.get(i)));
        } else if (i == 3) {
            inbound.setRoom3(util.CheckNullString(QueryRoomList.get(i)));
        }
    }

    List<String> QueryRequestList = session
            .createSQLQuery(" SELECT * FROM `hotel_inbound_category` where id=  " + hotelID)
            .addScalar("cate_desc", Hibernate.STRING).list();
    for (int i = 0; i < QueryRequestList.size(); i++) {
        if (i == 0) {
            inbound.setRequest1(util.CheckNullString(QueryRequestList.get(i)));
        } else if (i == 2) {
            inbound.setRequest2(util.CheckNullString(QueryRequestList.get(i)));
        } else if (i == 3) {
            inbound.setRequest3(util.CheckNullString(QueryRequestList.get(i)));
        }
    }

    List<String> QueryPassengerList = session
            .createSQLQuery(" SELECT * FROM `hotel_inbound_payment` where id =  " + hotelID)
            .addScalar("pax_name", Hibernate.STRING).list();
    for (String B : QueryPassengerList) {
        HotelInbound inboundPass = new HotelInbound();
        inboundPass = cloneObject(inbound);
        inboundPass.setPaxname(util.ConvertString(B));
        inboundPass.setPsgremark("");
        inboundPass.setRooming("");
        inboundPass.setStatus("ok");
        inboundPass.setAge("");
        data.add(inboundPass);
    }
    if (QueryPassengerList == null) {
        data.add(inbound);
    }
    return data;
}

From source file:com.aqnote.app.wifianalyzer.wifi.band.Country.java

public Locale getCountry(@NonNull String countryCode) {
    Locale country = new Locale("", countryCode);
    int index = Collections.binarySearch(countries, country, new LocaleCountryComparator());
    if (index < 0) {
        return country;
    }//from   w w  w .j a v  a 2  s  .  co m
    return countries.get(index);
}

From source file:config.web.i18nConfig.java

@Bean(name = "sessionLocaleResolver")
public SessionLocaleResolver provideSessionLocaleResolver() {
    SessionLocaleResolver localeResolver = new SessionLocaleResolver();
    localeResolver.setDefaultLocale(new Locale("es", "ES"));
    return localeResolver;
}

From source file:com.opensymphony.xwork2.conversion.impl.NumberConverterTest.java

public void testStringToNumberConversionPL() throws Exception {
    // given/*w w  w . j  a v  a  2s .c  o  m*/
    NumberConverter converter = new NumberConverter();
    Map<String, Object> context = new HashMap<>();
    context.put(ActionContext.LOCALE, new Locale("pl", "PL"));

    SimpleFooAction foo = new SimpleFooAction();

    // when
    Object value = converter.convertValue(context, foo, null, "id", "1234", Integer.class);

    // then
    assertEquals(1234, value);
}

From source file:ch.silviowangler.dox.TranslationServiceImplIntegrationTest.java

@Test
public void readTranslation() throws NoTranslationFoundException {
    assertThat(translationService.findTranslation("Domain:company", GERMAN), is("Firma"));
    assertThat(translationService.findTranslation("Domain:company", new Locale("de", "CH")), is("Firma"));
    assertThat(translationService.findTranslation("Domain:company", ENGLISH), is("Company"));
}