Java 8 Locale - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 Locale class.

This code example shows how to use the following methods:getCountry, getDisplayCountry, getDisplayLanguage, getDisplayName, getISO3Country
    /** 
     * helper method to display Locale info 
     */ 
    private static void printLocale(Locale loc) {
        System.out.println();
        System.out.println(loc.getDisplayName());
        System.out.println(loc.getCountry());
        System.out.println(loc.getLanguage());
        System.out.println(loc.getDisplayCountry());
        System.out.println(loc.getDisplayLanguage());
        System.out.println(loc.getDisplayName());
        System.out.println(loc.getISO3Country());
        System.out.println(loc.getISO3Language());
    } 
} 
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getCountry, getLanguage
 
  @Test(dependsOnMethods = { "testDbOpenWithBackSlash" }) 
  public void testChangeLocale() throws IOException { 
    database = new OObjectDatabaseTx(url);
    database.open("admin", "admin");
    database.getStorage().getConfiguration().setLocaleLanguage(Locale.ENGLISH.getLanguage());
    database.getStorage().getConfiguration().setLocaleCountry(Locale.ENGLISH.getCountry());
    database.getStorage().getConfiguration().update();
    database.close();
  } 
 
  @Test(dependsOnMethods = { "testChangeLocale" }) 
  public void testRoles() throws IOException { 
    database = new OObjectDatabaseTx(url);
    database.open("admin", "admin");
    database.query(new OSQLSynchQuery<ORole>("select from ORole where name = 'admin'"));
    database.close();
  } 
 
  @Test(dependsOnMethods = { "testChangeLocale" }) 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setDefault
            input.close();
        } 
    } 
 
    private void setLocale(String code) {
        Locale locale = new Locale(code);
        Locale.setDefault(locale);
        Configuration config = new Configuration();
        config.locale = locale;
        mResources.updateConfiguration(config, mResources.getDisplayMetrics());
    } 
 
    private void assertResource(int resId, boolean ewo, boolean ew) throws Throwable {
        boolean expected = mWithOverlay ? ew : ewo;
        boolean actual = mResources.getBoolean(resId);
        assertEquals(expected, actual);
    } 
 
    private void assertResource(int resId, String ewo, String ew) throws Throwable {
        String expected = mWithOverlay ? ew : ewo;
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getCountry, getLanguage, getVariant
	 *  
	 * @param locale the locale for which a resource bundle is desired 
	 * @return a <code>List</code> of candidate <code>Locale</code>s for the given <code>locale</code> 
	 * @exception NullPointerException if <code>locale</code> is <code>null</code> */ 
	private static List<Locale> getCandidateLocales (Locale locale) {
		String language = locale.getLanguage();
		String country = locale.getCountry();
		String variant = locale.getVariant();
 
		List<Locale> locales = new ArrayList<Locale>(4);
		if (variant.length() > 0) {
			locales.add(locale);
		} 
		if (country.length() > 0) {
			locales.add((locales.size() == 0) ? locale : new Locale(language, country));
		} 
		if (language.length() > 0) {
			locales.add((locales.size() == 0) ? locale : new Locale(language));
		} 
		locales.add(Locale.ROOT);

7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getCountry, getDisplayCountry, getDisplayLanguage, getDisplayName, getDisplayVariant
import java.util.MissingResourceException; 
 
public class LocaleTest extends junit.framework.TestCase {
    // http://b/2611311; if there's no display language/country/variant, use the raw codes. 
    public void test_getDisplayName_invalid() throws Exception { 
        Locale invalid = new Locale("AaBbCc", "DdEeFf", "GgHhIi");
 
        assertEquals("aabbcc", invalid.getLanguage());
        assertEquals("DDEEFF", invalid.getCountry());
        assertEquals("GgHhIi", invalid.getVariant());
 
        // Android using icu4c < 49.2 returned empty strings for display language, country, 
        // and variant, but a display name made up of the raw strings. 
        // Newer releases return slightly different results, but no less unreasonable. 
        assertEquals("aabbcc", invalid.getDisplayLanguage());
        assertEquals("", invalid.getDisplayCountry());
        assertEquals("DDEEFF_GGHHII", invalid.getDisplayVariant());
        assertEquals("aabbcc (DDEEFF,DDEEFF_GGHHII)", invalid.getDisplayName());
    } 
 

7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getCountry, getLanguage, getVariant
		Assert.notNull(extension, "Extension must not be null");
 
		Resource resource = null;
 
		if (locale != null) {
			String lang = locale.getLanguage();
			String country = locale.getCountry();
			String variant = locale.getVariant();
 
			// Check for file with language, country and variant localization. 
			if (variant.length() > 0) {
				String location =
						name + this.separator + lang + this.separator + country + this.separator + variant + extension;
				resource = this.resourceLoader.getResource(location);
			} 
 
			// Check for file with language and country localization. 
			if ((resource == null || !resource.exists()) && country.length() > 0) {
				String location = name + this.separator + lang + this.separator + country + extension;
				resource = this.resourceLoader.getResource(location);
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
    		if (tokens.hasMoreElements()) {
    			variant = tokens.nextToken();
    		} 
    	} 
    	 
    	Locale l = new Locale(language, country, variant);
    	locales.put(code, l);
    	return l;
    } 
	 
	public static String getCurrencyCode(Locale locale)
	{ 
		String code;
		if (currencyCodes.containsKey(locale)) {
			code = currencyCodes.get(locale);
		} else { 
			code = Currency.getInstance(locale).getCurrencyCode();
			currencyCodes.put(locale, code);
		} 
		return code;
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getCountry, getLanguage, getVariant
     * @param locale the message locale to use 
     * @param <T> the bundle type 
     * @return the bundle 
     */ 
    public static <T> T getBundle(Class<T> type, Locale locale) {
        String language = locale.getLanguage();
        String country = locale.getCountry();
        String variant = locale.getVariant();
 
        Class<? extends T> bundleClass = null;
        if (variant != null && variant.length() > 0)
            try { 
                bundleClass = Class.forName(join(type.getName(), "$bundle", language, country, variant), true,
                        type.getClassLoader()).asSubclass(type);
            } catch (ClassNotFoundException e) {
                // ignore 
            } 
        if (bundleClass == null && country != null && country.length() > 0)
            try { 
                bundleClass = Class.forName(join(type.getName(), "$bundle", language, country, null), true,
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
        } else { 
            Locale locale;
            if (entry.language == null) {
                locale = new Locale(entry.iso);
            } else { 
                locale = new Locale(entry.language, entry.iso);
            } 
            String[] tz = TimeZones.forLocale(locale);
            if (tz.length == 0) return null;
            return tz[0];
        } 
    } 
 
    /** 
     * Given a GSM Mobile Country Code, returns 
     * an ISO two-character country code if available. 
     * Returns "" if unavailable. 
     */ 
    public static String
    countryCodeForMcc(int mcc)
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
            return null; 
        if (value.length() == 2) {
            return new Locale(value);
        } 
        if (value.length() == 5) {
            return new Locale(value.substring(0, 2), value.substring(3, 5));
        } 
        if (value.length() == 8) {
            return new Locale(value.substring(0, 2), value.substring(3, 5), value.substring(6, 8));
        } 
        return null; 
    } 
} 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java

Related Java 8 Locale Questions & Answers:

See Code Examples for Java 8 Locale Methods: