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:Main.java

private static String constructLink(Locale locale, String path) {
    String domain = locale.getCountry().toLowerCase();

    // ISO-3166-to-TLD exceptions...
    if (domain.equals("us")) {
        domain = "com";
    } else if (domain.equals("ao")) {
        domain = "it.ao";
    } else if (domain.equals("gb")) {
        domain = "co.uk";
    } else {//from  w  w  w  . j a va  2s.  c  om
        for (int i = 0; i < DOT_COM.length; i++) {
            if (domain.equals(DOT_COM[i])) {
                domain = "com." + domain;
                break;
            }
        }
        for (int i = 0; i < DOT_CO.length; i++) {
            if (domain.equals(DOT_CO[i])) {
                domain = "co." + domain;
                break;
            }
        }
        if (locale.toString().equals(Locale.CANADA_FRENCH.toString())) {
            path += "?hl=fr";
        }
    }

    return "http://m.google." + domain + path;
}

From source file:org.kepler.configuration.CommonsConfigurationReader.java

/**
 * return true if the designator on the file matches the locale exactly
 *///from  w w  w. j  a  v a 2s  . c  om
private static boolean checkLocaleDesignator(File f, Locale l) {
    String designator = getLocaleDesignator(f);

    //System.out.println("designator: " + designator);
    //System.out.println("locale: " + l.toString());
    //System.out.println("File: " + f.getName());

    if (designator == null && l.toString().equals("en_US")) { //if there is no designator and the locale is en_US, use the file
        return true;
    }

    //the designator is not null, see if this file matches the designator
    if (designator != null && designator.equals(l.toString())) { //load this file!
        return true;
    }

    return false;
}

From source file:org.brushingbits.jnap.common.seo.SeoStringUtil.java

/**
 * /* w w  w.j  a  va  2s.  c o m*/
 * @param src
 * @param locale
 * @return
 */
public static String makeSeoFriendly(String src, Locale locale) {
    String seoFriendlyText = src.trim();

    // normalize
    seoFriendlyText = Normalizer.normalize(src, Form.NFD);

    // try to remove stop words if locale is specified
    if (locale != null) {
        SeoStopWordCleaner wordCleaner = null;
        for (SeoStopWordCleaner cleaner : seoStopWordCleaners) {
            if (ArrayUtils.contains(cleaner.getSupportedLocales(), locale)) {
                wordCleaner = cleaner;
                break;
            }
        }
        if (wordCleaner == null) {
            logger.warn(MessageFormat.format(
                    "A locale was specified ({0}) but no " + "SeoStopWordCleaner was found for it",
                    locale.toString()));
        } else {
            seoFriendlyText = wordCleaner.clean(seoFriendlyText);
        }
    }

    // replace duplicated spaces with a single one
    seoFriendlyText = seoFriendlyText.replaceAll("[\\s]{2,}", " ");

    // replace spaces with '-'
    seoFriendlyText = seoFriendlyText.replaceAll("[\\s]", "-");

    // remove remaining non-latin characters
    seoFriendlyText = seoFriendlyText.replaceAll("[^\\w-]", StringUtils.EMPTY);

    // convert to lowercase (using english locale rules) and return
    return seoFriendlyText.toLowerCase(Locale.ENGLISH);
}

From source file:org.microg.gms.auth.login.LoginActivity.java

private static String buildUrl(String tmpl, Locale locale) {
    return Uri.parse(EMBEDDED_SETUP_URL).buildUpon().appendQueryParameter("source", "android")
            .appendQueryParameter("xoauth_display_name", "Android Device")
            .appendQueryParameter("lang", locale.getLanguage())
            .appendQueryParameter("cc", locale.getCountry().toLowerCase(Locale.US))
            .appendQueryParameter("langCountry", locale.toString().toLowerCase(Locale.US))
            .appendQueryParameter("hl", locale.toString().replace("_", "-")).appendQueryParameter("tmpl", tmpl)
            .build().toString();//  w  w  w  . jav  a 2s  .  c o  m
}

From source file:org.eclipse.e4.tools.services.impl.ResourceBundleHelper.java

/**
 * This method searches for the {@link ResourceBundle} in a modified way by inspecting the configuration option 
 * <code>equinox.root.locale</code>. 
 * <p>//from w  w w.  j  av  a2  s  .co  m
 * If the value for this system property is set to an empty String the default search order for ResourceBundles is used:
 * <ul>
 * <li>bn + Ls + "_" + Cs + "_" + Vs</li>
 * <li>bn + Ls + "_" + Cs</li>
 * <li>bn + Ls</li>
 * <li>bn + Ld + "_" + Cd + "_" + Vd</li>
 * <li>bn + Ld + "_" + Cd</li>
 * <li>bn + Ld</li>
 * <li>bn</li>
 * </ul>
 * Where bn is this bundle's localization basename, Ls, Cs and Vs are the specified locale (language, country, variant) and 
 * Ld, Cd and Vd are the default locale (language, country, variant).
 * </p>
 * <p>
 * If Ls equals the value of <code>equinox.root.locale</code> then the following search order is used:
 * <ul>
 * <li>bn + Ls + "_" + Cs + "_" + Vs</li>
 * <li>bn + Ls + "_" + Cs</li>
 * <li>bn + Ls</li>
 * <li>bn</li>
 * <li>bn + Ld + "_" + Cd + "_" + Vd</li>
 * <li>bn + Ld + "_" + Cd</li>
 * <li>bn + Ld</li>
 * <li>bn</li>
 * </ul>
 * </p>
 * If <code>equinox.root.locale=en</code> and en_XX or en is asked for then this allows the root file to be used instead of 
 * falling back to the default locale.
 * 
  * @param baseName the base name of the resource bundle, a fully qualified class name
  * @param locale the locale for which a resource bundle is desired
  * @param loader the class loader from which to load the resource bundle
  * @return a resource bundle for the given base name and locale
 * 
 * @see ResourceBundle#getBundle(String, Locale, ClassLoader)
 */
public static ResourceBundle getEquinoxResourceBundle(String baseName, Locale locale, ClassLoader loader) {
    ResourceBundle resourceBundle = null;

    String equinoxLocale = getEquinoxRootLocale();
    //if the equinox.root.locale is not empty and the specified locale equals the equinox.root.locale
    // -> use the special search order
    if (equinoxLocale.length() > 0 && locale.toString().startsWith(equinoxLocale)) {
        //there is a equinox.root.locale configured that matches the specified locale 
        //so the special search order is used
        //to achieve this we first search without a fallback to the default locale
        try {
            resourceBundle = ResourceBundle.getBundle(baseName, locale, loader,
                    ResourceBundle.Control.getNoFallbackControl(Control.FORMAT_DEFAULT));
        } catch (MissingResourceException e) {
            //do nothing
        }
        //if there is no ResourceBundle found for that path, we will now search for the default locale ResourceBundle
        if (resourceBundle == null) {
            try {
                resourceBundle = ResourceBundle.getBundle(baseName, Locale.getDefault(), loader,
                        ResourceBundle.Control.getNoFallbackControl(Control.FORMAT_DEFAULT));
            } catch (MissingResourceException e) {
                //do nothing
            }
        }
    } else {
        //there is either no equinox.root.locale configured or it does not match the specified locale
        // -> use the default search order
        try {
            resourceBundle = ResourceBundle.getBundle(baseName, locale, loader);
        } catch (MissingResourceException e) {
            //do nothing
        }
    }

    return resourceBundle;
}

From source file:org.lareferencia.xoai.I18nUtil.java

/**
 * Get the i18n message string for a given key and locale
 *
 * @param key/*from w  w w. j  a v a  2s  .c om*/
 *        String - name of the key to get the message for
 * @param locale
 *        Locale, to get the message for
 *
 * @return message
 *         String of the message
 */
public static String getMessage(String key, Locale locale) {
    if (locale == null) {
        locale = DEFAULTLOCALE;
    }
    ResourceBundle.Control control = ResourceBundle.Control
            .getNoFallbackControl(ResourceBundle.Control.FORMAT_DEFAULT);

    ResourceBundle messages = ResourceBundle.getBundle("Messages", locale, control);
    try {
        String message = messages.getString(key.trim());
        return message;
    } catch (MissingResourceException e) {
        log.error("'" + key + "' translation undefined in locale '" + locale.toString() + "'");
        return key;
    }
}

From source file:com.opensymphony.xwork2.util.LocalizedTextUtil.java

/**
 * Creates a key to used for lookup/storing in the bundle misses cache.
 *
 * @param aBundleName the name of the bundle (usually it's FQN classname).
 * @param locale      the locale.//ww w.  ja v a  2s  .  co m
 * @return the key to use for lookup/storing in the bundle misses cache.
 */
private static String createMissesKey(String aBundleName, Locale locale) {
    return aBundleName + "_" + locale.toString();
}

From source file:org.eclipse.e4.tools.services.impl.ResourceBundleHelper.java

/**
 * This method searches for the {@link ResourceBundle} in a modified way by inspecting the configuration option 
 * <code>equinox.root.locale</code>.
 * <p><b>Note: This method will only search for ResourceBundles based on properties files.</b></p>
 * <p>//w  ww. j  a  v  a  2s  .c o m
 * If the value for this system property is set to an empty String the default search order for ResourceBundles is used:
 * <ul>
 * <li>bn + Ls + "_" + Cs + "_" + Vs</li>
 * <li>bn + Ls + "_" + Cs</li>
 * <li>bn + Ls</li>
 * <li>bn + Ld + "_" + Cd + "_" + Vd</li>
 * <li>bn + Ld + "_" + Cd</li>
 * <li>bn + Ld</li>
 * <li>bn</li>
 * </ul>
 * Where bn is this bundle's localization basename, Ls, Cs and Vs are the specified locale (language, country, variant) and 
 * Ld, Cd and Vd are the default locale (language, country, variant).
 * </p>
 * <p>
 * If Ls equals the value of <code>equinox.root.locale</code> then the following search order is used:
 * <ul>
 * <li>bn + Ls + "_" + Cs + "_" + Vs</li>
 * <li>bn + Ls + "_" + Cs</li>
 * <li>bn + Ls</li>
 * <li>bn</li>
 * <li>bn + Ld + "_" + Cd + "_" + Vd</li>
 * <li>bn + Ld + "_" + Cd</li>
 * <li>bn + Ld</li>
 * <li>bn</li>
 * </ul>
 * </p>
 * If <code>equinox.root.locale=en</code> and en_XX or en is asked for then this allows the root file to be used instead of 
 * falling back to the default locale.
 * 
  * @param baseName the base name of the resource bundle, a fully qualified class name
  * @param locale the locale for which a resource bundle is desired
 * @param withFallback The {@link Control} that uses the default locale fallback on searching for resource bundles.
 * @param withoutFallback The {@link Control} that doesn't use the default locale fallback on searching for resource bundles.
  * @return a resource bundle for the given base name and locale
 * 
 * @see ResourceBundle#getBundle(String, Locale, Control)
 */
public static ResourceBundle getEquinoxResourceBundle(String baseName, Locale locale, Control withFallback,
        Control withoutFallback) {
    ResourceBundle resourceBundle = null;

    String equinoxLocale = getEquinoxRootLocale();
    //if the equinox.root.locale is not empty and the specified locale equals the equinox.root.locale
    // -> use the special search order
    if (equinoxLocale.length() > 0 && locale.toString().startsWith(equinoxLocale)) {
        //there is a equinox.root.locale configured that matches the specified locale 
        //so the special search order is used
        //to achieve this we first search without a fallback to the default locale
        try {
            resourceBundle = ResourceBundle.getBundle(baseName, locale, withoutFallback);
        } catch (MissingResourceException e) {
            //do nothing
        }
        //if there is no ResourceBundle found for that path, we will now search for the default locale ResourceBundle
        if (resourceBundle == null) {
            try {
                resourceBundle = ResourceBundle.getBundle(baseName, Locale.getDefault(), withoutFallback);
            } catch (MissingResourceException e) {
                //do nothing
            }
        }
    } else {
        //there is either no equinox.root.locale configured or it does not match the specified locale
        // -> use the default search order
        try {
            resourceBundle = ResourceBundle.getBundle(baseName, locale, withFallback);
        } catch (MissingResourceException e) {
            //do nothing
        }
    }

    return resourceBundle;
}

From source file:com.heliosphere.demeter.base.resource.bundle.ResourceBundleManager.java

/**
 * Refresh all the resource bundles already handled by the
 * {@link ResourceBundleManager} for the given {@link Locale}.
 * <p>//w  ww .  ja v a2s .c o  m
 * @param locale {@link Locale} corresponding to the new language to use.
 */
@SuppressWarnings("nls")
private static final void refresh(final Locale locale) {
    if (NAMES.isEmpty()) {
        ResourceBundleManager.locale = locale;
    }

    for (Class<? extends IBundle> bundleClass : NAMES.keySet()) {
        final ResourceBundle bundle = ResourceBundle.getBundle(NAMES.get(bundleClass), locale);
        if (bundle != null && bundle.getLocale().getLanguage() != locale.getLanguage()) {
            log.error("Bundle cannot be found [name=" + NAMES.get(bundleClass) + ", locale=" + locale.toString()
                    + "]. Using default one [name=" + NAMES.get(bundleClass) + ", locale="
                    + getLocale().toString() + "]");
            ResourceBundleManager.locale = english;
        } else {
            ResourceBundleManager.locale = locale;
        }

        BUNDLES.clear();
        register(bundleClass, bundle);
    }
}

From source file:com.heliosphere.athena.base.resource.bundle.ResourceBundleManager.java

/**
 * Refresh all the resource bundles already handled by the
 * {@link ResourceBundleManager} for the given {@link Locale}.
 * <p>/*from w  w  w .  ja  v a  2s  .  com*/
 * @param locale {@link Locale} corresponding to the new language to use.
 */
@SuppressWarnings("nls")
private static final void refresh(final Locale locale) {
    if (NAMES.isEmpty()) {
        ResourceBundleManager.locale = locale;
    }

    for (Class<? extends IBundle> bundleClass : NAMES.keySet()) {
        final ResourceBundle bundle = ResourceBundle.getBundle(NAMES.get(bundleClass), locale);
        if (bundle != null && !bundle.getLocale().getLanguage().equals(locale.getLanguage())) {
            log.error("Bundle cannot be found [name=" + NAMES.get(bundleClass) + ", locale=" + locale.toString()
                    + "]. Using default one [name=" + NAMES.get(bundleClass) + ", locale="
                    + getLocale().toString() + "]");
            ResourceBundleManager.locale = english;
        } else {
            ResourceBundleManager.locale = locale;
        }

        BUNDLES.clear();
        register(bundleClass, bundle);
    }
}