Java Code Examples for java.util.Locale#getScript()

The following examples show how to use java.util.Locale#getScript() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
private Locale mapChineseLocale(Locale locale) {
    if (locale.getLanguage() == "zh") {
        switch (locale.getScript()) {
            case "Hans":
                return Locale.CHINA;
            case "Hant":
                return Locale.TAIWAN;
            case "":
                // no script, guess from country code.
                switch (locale.getCountry()) {
                    case "":
                    case "CN":
                    case "SG":
                        return Locale.CHINA;
                    case "HK":
                    case "MO":
                    case "TW":
                        return Locale.TAIWAN;
                }
                break;
        }
    }

    // no need to map
    return locale;
}
 
Example 2
private static String resourceBundleSuffixFor(Locale locale) {
	String suffix = "";
	if (Locale.ROOT != locale) {
		if (!locale.getLanguage().isEmpty()) {
			suffix += "_" + locale.getLanguage();
		}
		if (!locale.getScript().isEmpty()) {
			suffix += "_" + locale.getScript();
		}
		if (!locale.getCountry().isEmpty()) {
			suffix += "_" + locale.getCountry();
		}
		if (!locale.getVariant().isEmpty()) {
			suffix += "_" + locale.getVariant();
		}
	}
	suffix += ".properties";
	return suffix;
}
 
Example 3
Source Project: android_9.0.0_r45   File: LocaleList.java    License: Apache License 2.0 5 votes vote down vote up
private static String getLikelyScript(Locale locale) {
    final String script = locale.getScript();
    if (!script.isEmpty()) {
        return script;
    } else {
        // TODO: Cache the results if this proves to be too slow
        return ULocale.addLikelySubtags(ULocale.forLocale(locale)).getScript();
    }
}
 
Example 4
@SuppressLint("NewApi")
private Locale checkChineseLocale(Locale locale) {
    if ("zh".equals(locale.getLanguage())) {
        String country = locale.getCountry();
        if ("CN".equals(country) || "TW".equals(country)) {
            return null;
        } else {
            String script = locale.getScript();
            if ("Hans".equals(script)) {
                return SIMPLIFIED_CHINESE;
            } else if ("Hant".equals(script)) {
                return TRADITIONAL_CHINESE;
            } else {
                VayLog.w(TAG, String.format("Unknown zh locale script: %s. Falling back to trying countries...", script));
                if ("SG".equals(country)) {
                    return SIMPLIFIED_CHINESE;
                } else if ("HK".equals(country) || "MO".equals(country)) {
                    return TRADITIONAL_CHINESE;
                } else {
                    VayLog.w(TAG, String.format("Unknown zh locale: %s. Falling back to zh-Hans-CN...", locale.toLanguageTag()));
                    return SIMPLIFIED_CHINESE;
                }
            }
        }
    } else {
        return null;
    }
}
 
Example 5
Source Project: Maying   File: ShadowsocksApplication.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressLint("NewApi")
private Locale checkChineseLocale(Locale locale) {
    if ("zh".equals(locale.getLanguage())) {
        String country = locale.getCountry();
        if ("CN".equals(country) || "TW".equals(country)) {
            return null;
        } else {
            String script = locale.getScript();
            if ("Hans".equals(script)) {
                return SIMPLIFIED_CHINESE;
            } else if ("Hant".equals(script)) {
                return TRADITIONAL_CHINESE;
            } else {
                VayLog.w(TAG, String.format("Unknown zh locale script: %s. Falling back to trying countries...", script));
                if ("SG".equals(country)) {
                    return SIMPLIFIED_CHINESE;
                } else if ("HK".equals(country) || "MO".equals(country)) {
                    return TRADITIONAL_CHINESE;
                } else {
                    VayLog.w(TAG, String.format("Unknown zh locale: %s. Falling back to zh-Hans-CN...", locale.toLanguageTag()));
                    return SIMPLIFIED_CHINESE;
                }
            }
        }
    } else {
        return null;
    }
}
 
Example 6
Source Project: j2objc   File: ULocale.java    License: Apache License 2.0 5 votes vote down vote up
public static boolean isOriginalDefaultLocale(Locale loc) {
    String script = loc.getScript();
    return loc.getLanguage().equals(getSystemProperty("user.language"))
            && loc.getCountry().equals(getSystemProperty("user.country"))
            && loc.getVariant().equals(getSystemProperty("user.variant"))
            && script.equals(getSystemProperty("user.script"));
}