Example usage for java.util Locale toString

List of usage examples for java.util Locale toString

Introduction

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

Prototype

@Override
public final String toString() 

Source Link

Document

Returns a string representation of this Locale object, consisting of language, country, variant, script, and extensions as below:
language + "_" + country + "_" + (variant + "_#" | "#") + script + "_" + extensions
Language is always lower case, country is always upper case, script is always title case, and extensions are always lower case.

Usage

From source file:DecimalFormatDemo.java

static public void localizedFormat(String pattern, double value, Locale loc) {
    NumberFormat nf = NumberFormat.getNumberInstance(loc);
    DecimalFormat df = (DecimalFormat) nf;
    df.applyPattern(pattern);/*from w  w  w .j a  va 2s  .  c  o  m*/
    String output = df.format(value);
    System.out.println(pattern + "  " + output + "  " + loc.toString());
}

From source file:com.salesmanager.core.util.www.ajax.CustomerUtil.java

public static void setGeoLocationCustomerInformation(String country, String region, String city,
        String language) {//from   w w w  . j ava 2  s  .c  o m

    HttpServletRequest req = WebContextFactory.get().getHttpServletRequest();
    HttpSession session = WebContextFactory.get().getSession();

    try {

        log.info("Setting LOCALE Country -> " + country + " region -> " + region + " city -> " + city);

        if (!StringUtils.isBlank(country)) {

            CountryDescription desc = CountryUtil.getCountryByIsoCode(country, req.getLocale());

            if (desc != null) {

                log.info(" Country Description -> " + desc.getCountryName());

                Customer customer = SessionUtil.getCustomer(req);
                if (customer == null) {
                    customer = new Customer();
                }
                customer.setCountryName(desc.getCountryName());
                customer.setCustomerBillingCountryName(desc.getCountryName());
                customer.setCustomerBillingCountryId(desc.getId().getCountryId());
                customer.setCustomerCountryId(desc.getId().getCountryId());

                // get the zone
                Zone zone = CountryUtil.getZoneCodeByCode(region, req.getLocale());
                if (zone != null) {
                    customer.setCustomerBillingZoneId(zone.getZoneId());
                    customer.setStateProvinceName(zone.getZoneName());
                    customer.setCustomerZoneId(zone.getZoneId());
                    customer.setCustomerState(zone.getZoneName());
                }

                MerchantStore store = SessionUtil.getMerchantStore(req);
                if (store != null) {
                    customer.setMerchantId(store.getMerchantId());
                }

                // set Locale
                Locale locale = LocaleUtil.getLocale(req);
                log.info("Actual locale (" + locale.toString());
                String l = locale.getLanguage();

                locale = new Locale(l, country);
                log.info("Setting locale (" + l + "_" + country + ")");
                log.info("New locale (" + locale.toString() + ")");

                LocaleUtil.setLocale(req, locale);

                customer.setLocale(locale);
                customer.setCustomerLang(locale.getLanguage());

                SessionUtil.setCustomer(customer, req);

            } else {
                log.info("Setting default locale (1)");
                Locale locale = LocaleUtil.getDefaultLocale();
                LocaleUtil.setLocale(req, locale);
            }

        }

    } catch (Exception e) {
        log.error(e);
    }
}

From source file:org.apache.roller.weblogger.util.I18nMessages.java

/**
 * Get an instance for a given locale./*from  www.  j  a  va2 s  . com*/
 */
public static I18nMessages getMessages(Locale locale) {

    log.debug("request for messages in locale = " + locale.toString());

    // check if we already have a message utils created for that locale
    I18nMessages messages = messagesMap.get(locale);

    // if no utils for that language yet then construct
    if (messages == null) {
        messages = new I18nMessages(locale);

        // keep a reference to it
        messagesMap.put(messages.getLocale(), messages);
    }

    return messages;
}

From source file:com.hack23.cia.service.impl.ConfigurationManagerImpl.java

/**
 * Gets the supported locales language data.
 *
 * @return the supported locales language data
 *//*from   w w  w.  j  a v  a2s .  c  o  m*/
private static List<LanguageData> getSupportedLocalesLanguageData() {
    final List<LanguageData> languages = new ArrayList<>();

    for (final Locale locale : SimpleDateFormat.getAvailableLocales()) {
        if (locale.getDisplayCountry(Locale.ENGLISH).length() == 0 && !StringUtils.isEmpty(locale.toString())
                && locale.toString().trim().length() == EXPECTED_LOCALE_LENGTH) {
            languages.add(new LanguageData().withCreatedDate(new Date()).withLanguageCode(locale.toString())
                    .withLanguageName(locale.getDisplayName(Locale.ENGLISH)).withLanguageEnabled(false));

        }
    }

    return languages;
}

From source file:SimpleDateFormatDemo.java

static public void displayDate(Locale currentLocale) {

    Date today;//from   w  w w . j a v  a 2 s . c  o m
    String result;
    SimpleDateFormat formatter;

    formatter = new SimpleDateFormat("EEE d MMM yy", currentLocale);
    today = new Date();
    result = formatter.format(today);

    System.out.println("Locale: " + currentLocale.toString());
    System.out.println("Result: " + result);
}

From source file:com.kenshoo.freemarker.view.FreeMarkerOnlineView.java

private static List<SelectionOption> toLocaleSelectionOptions(Map<String, Locale> localeMap) {
    ArrayList<SelectionOption> selectionOptions = new ArrayList<SelectionOption>(localeMap.size());
    for (Map.Entry<String, Locale> ent : localeMap.entrySet()) {
        Locale locale = ent.getValue();
        selectionOptions.add(new SelectionOption(ent.getKey(),
                truncate(locale.getDisplayName(Locale.US), 18) + "; " + locale.toString()));
    }//from   ww w.j  a  v a 2  s.c o  m
    Collections.sort(selectionOptions);
    return selectionOptions;
}

From source file:DateUtil.java

/**
 * Gets date pattern without time symbols according to given locale and date style
 *
 * @param locale    Locale to searh pattern for
 * @param dateStyle Date style to search pattern by
 * @return Date pattern without time symbols
 *///from w w  w. j a  v  a 2  s .com
public static String getDatePattern(Locale locale, int dateStyle) {
    String id = locale.toString() + "+" + dateStyle;
    String pattern = (String) patterns.get(id);
    if (pattern == null) {
        SimpleDateFormat format = (SimpleDateFormat) DateFormat.getDateInstance(dateStyle, locale);
        pattern = format.toPattern();
        patterns.put(id, pattern);
    }
    return pattern;
}

From source file:NumberFormatDemo.java

static public void displayPercent(Locale currentLocale) {

    Double percent = new Double(0.75);
    NumberFormat percentFormatter;
    String percentOut;//from  w  ww  .  j a  va 2 s  .co  m

    percentFormatter = NumberFormat.getPercentInstance(currentLocale);
    percentOut = percentFormatter.format(percent);
    System.out.println(percentOut + "   " + currentLocale.toString());
}

From source file:com.googlecode.jsfFlex.myFaces.LocaleUtils.java

/**
 * Converts a locale string to <code>Locale</code> class. Accepts both
 * '_' and '-' as separators for locale components.
 *
 * @param localeString string representation of a locale
 * @return Locale instance, compatible with the string representation
 *//*from w ww .  j  a v  a 2s  . c  o  m*/
public static Locale toLocale(String localeString) {
    if ((localeString == null) || (localeString.length() == 0)) {
        Locale locale = Locale.getDefault();
        if (log.isWarnEnabled())
            log.warn("Locale name in faces-config.xml null or empty, setting locale to default locale : "
                    + locale.toString());
        return locale;
    }

    int separatorCountry = localeString.indexOf('_');
    char separator;
    if (separatorCountry >= 0) {
        separator = '_';
    } else {
        separatorCountry = localeString.indexOf('-');
        separator = '-';
    }

    String language, country, variant;
    if (separatorCountry < 0) {
        language = localeString;
        country = variant = "";
    } else {
        language = localeString.substring(0, separatorCountry);

        int separatorVariant = localeString.indexOf(separator, separatorCountry + 1);
        if (separatorVariant < 0) {
            country = localeString.substring(separatorCountry + 1);
            variant = "";
        } else {
            country = localeString.substring(separatorCountry + 1, separatorVariant);
            variant = localeString.substring(separatorVariant + 1);
        }
    }

    return new Locale(language, country, variant);
}

From source file:NumberFormatDemo.java

static public void displayCurrency(Locale currentLocale) {

    Double currency = new Double(9876543.21);
    NumberFormat currencyFormatter;
    String currencyOut;//from   w  w w .j  a  v  a2s.c  o  m

    currencyFormatter = NumberFormat.getCurrencyInstance(currentLocale);
    currencyOut = currencyFormatter.format(currency);
    System.out.println(currencyOut + "   " + currentLocale.toString());
}