java.util.Locale#getLanguage ( )源码实例Demo

下面列出了java.util.Locale#getLanguage ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: openboard   文件: DictionaryInfoUtils.java
/**
 * Helper method to return a dictionary res id for a locale, or 0 if none.
 * @param res resources for the app
 * @param locale dictionary locale
 * @return main dictionary resource id
 */
public static int getMainDictionaryResourceIdIfAvailableForLocale(final Resources res,
        final Locale locale) {
    int resId;
    // Try to find main_language_country dictionary.
    if (!locale.getCountry().isEmpty()) {
        final String dictLanguageCountry = MAIN_DICT_PREFIX
                + locale.toString().toLowerCase(Locale.ROOT) + DECODER_DICT_SUFFIX;
        if ((resId = res.getIdentifier(
                dictLanguageCountry, "raw", RESOURCE_PACKAGE_NAME)) != 0) {
            return resId;
        }
    }

    // Try to find main_language dictionary.
    final String dictLanguage = MAIN_DICT_PREFIX + locale.getLanguage() + DECODER_DICT_SUFFIX;
    if ((resId = res.getIdentifier(dictLanguage, "raw", RESOURCE_PACKAGE_NAME)) != 0) {
        return resId;
    }

    // Not found, return 0
    return 0;
}
 
源代码2 项目: Time4A   文件: EastAsianST.java
@Override
public String getDisplayName(Locale locale) {
    String lang = locale.getLanguage();

    if (lang.equals("zh")) {
        return locale.getCountry().equals("TW") ? "節氣" : "节气";
    } else if (lang.equals("ko")) {
        return "절기";
    } else if (lang.equals("vi")) {
        return "tiết khí";
    } else if (lang.equals("ja")) {
        return "節気";
    } else if (lang.isEmpty()) {
        return "jieqi";
    } else {
        return "jiéqì"; // pinyin
    }
}
 
源代码3 项目: Viewer   文件: CommonUtil.java
public static String getLanguageEnv() {  
       Locale l = Locale.getDefault();
       String language = l.getLanguage();
       String country = l.getCountry().toLowerCase();
       if ("zh".equalsIgnoreCase(language)) {  
           if ("cn".equals(country)) {
               language = "zh-CN";  
           } else if ("tw".equals(country)) {  
               language = "zh-TW";  
           }  
       }
       return language;  
}
 
源代码4 项目: XposedSmsCode   文件: Utils.java
private static String getLanguagePath() {
    Locale locale = Locale.getDefault();
    String language = locale.getLanguage();
    String country = locale.getCountry();
    String result = "en";
    if ("zh".equals(language)) {
        if ("CN".equalsIgnoreCase(country)) {
            result = "zh-CN";
        } else if ("HK".equalsIgnoreCase(country) || "TW".equalsIgnoreCase(country)) {
            result = "zh-TW";
        }
    }
    return result;
}
 
private String createLocalePath(Locale locale) {
    String language = locale.getLanguage();
    String country = locale.getCountry();
    String variant = locale.getVariant();
    String localePath = null;
    if (!variant.equals("")) {
        localePath = "_" + language + "/_" + country + "/_" + variant;
    } else if (!country.equals("")) {
        localePath = "_" + language + "/_" + country;
    } else {
        localePath = "_" + language;
    }

    return localePath;
}
 
源代码6 项目: Telegram   文件: LocaleController.java
public void recreateFormatters() {
    Locale locale = currentLocale;
    if (locale == null) {
        locale = Locale.getDefault();
    }
    String lang = locale.getLanguage();
    if (lang == null) {
        lang = "en";
    }
    lang = lang.toLowerCase();
    isRTL = lang.length() == 2 && (lang.equals("ar") || lang.equals("fa") || lang.equals("he") || lang.equals("iw")) ||
            lang.startsWith("ar_") || lang.startsWith("fa_") || lang.startsWith("he_") || lang.startsWith("iw_")
            || currentLocaleInfo != null && currentLocaleInfo.isRtl;
    nameDisplayOrder = lang.equals("ko") ? 2 : 1;

    formatterDayMonth = createFormatter(locale, getStringInternal("formatterMonth", R.string.formatterMonth), "dd MMM");
    formatterYear = createFormatter(locale, getStringInternal("formatterYear", R.string.formatterYear), "dd.MM.yy");
    formatterYearMax = createFormatter(locale, getStringInternal("formatterYearMax", R.string.formatterYearMax), "dd.MM.yyyy");
    chatDate = createFormatter(locale, getStringInternal("chatDate", R.string.chatDate), "d MMMM");
    chatFullDate = createFormatter(locale, getStringInternal("chatFullDate", R.string.chatFullDate), "d MMMM yyyy");
    formatterWeek = createFormatter(locale, getStringInternal("formatterWeek", R.string.formatterWeek), "EEE");
    formatterScheduleDay = createFormatter(locale, getStringInternal("formatDateSchedule", R.string.formatDateSchedule), "MMM d");
    formatterScheduleYear = createFormatter(locale, getStringInternal("formatDateScheduleYear", R.string.formatDateScheduleYear), "MMM d yyyy");
    formatterDay = createFormatter(lang.toLowerCase().equals("ar") || lang.toLowerCase().equals("ko") ? locale : Locale.US, is24HourFormat ? getStringInternal("formatterDay24H", R.string.formatterDay24H) : getStringInternal("formatterDay12H", R.string.formatterDay12H), is24HourFormat ? "HH:mm" : "h:mm a");
    formatterStats = createFormatter(locale, is24HourFormat ? getStringInternal("formatterStats24H", R.string.formatterStats24H) : getStringInternal("formatterStats12H", R.string.formatterStats12H), is24HourFormat ? "MMM dd yyyy, HH:mm" : "MMM dd yyyy, h:mm a");
    formatterBannedUntil = createFormatter(locale, is24HourFormat ? getStringInternal("formatterBannedUntil24H", R.string.formatterBannedUntil24H) : getStringInternal("formatterBannedUntil12H", R.string.formatterBannedUntil12H), is24HourFormat ? "MMM dd yyyy, HH:mm" : "MMM dd yyyy, h:mm a");
    formatterBannedUntilThisYear = createFormatter(locale, is24HourFormat ? getStringInternal("formatterBannedUntilThisYear24H", R.string.formatterBannedUntilThisYear24H) : getStringInternal("formatterBannedUntilThisYear12H", R.string.formatterBannedUntilThisYear12H), is24HourFormat ? "MMM dd, HH:mm" : "MMM dd, h:mm a");
    formatterScheduleSend[0] = createFormatter(locale, getStringInternal("SendTodayAt", R.string.SendTodayAt), "'Send today at' HH:mm");
    formatterScheduleSend[1] = createFormatter(locale, getStringInternal("SendDayAt", R.string.SendDayAt), "'Send on' MMM d 'at' HH:mm");
    formatterScheduleSend[2] = createFormatter(locale, getStringInternal("SendDayYearAt", R.string.SendDayYearAt), "'Send on' MMM d yyyy 'at' HH:mm");
    formatterScheduleSend[3] = createFormatter(locale, getStringInternal("RemindTodayAt", R.string.RemindTodayAt), "'Remind today at' HH:mm");
    formatterScheduleSend[4] = createFormatter(locale, getStringInternal("RemindDayAt", R.string.RemindDayAt), "'Remind on' MMM d 'at' HH:mm");
    formatterScheduleSend[5] = createFormatter(locale, getStringInternal("RemindDayYearAt", R.string.RemindDayYearAt), "'Remind on' MMM d yyyy 'at' HH:mm");
}
 
源代码7 项目: albert   文件: UserSessionUtil.java
public static String getSysLanguage(){
       Locale locale = LocaleContextHolder.getLocale(); 
	if(locale != null){
		return locale.getLanguage() + "_" + locale.getCountry();
	} else {
		return Constants.LOCALE_LANGUAGE.en_US;
	}
}
 
源代码8 项目: jdk8u_jdk   文件: ExecutableInputMethodManager.java
private String createLocalePath(Locale locale) {
    String language = locale.getLanguage();
    String country = locale.getCountry();
    String variant = locale.getVariant();
    String localePath = null;
    if (!variant.equals("")) {
        localePath = "_" + language + "/_" + country + "/_" + variant;
    } else if (!country.equals("")) {
        localePath = "_" + language + "/_" + country;
    } else {
        localePath = "_" + language;
    }

    return localePath;
}
 
源代码9 项目: ganttproject   文件: AboutDialog2.java
private static ListItem createTranslationsPage() {
  StringBuilder builder = new StringBuilder();
  for (Locale l : GanttLanguage.getInstance().getAvailableLocales()) {
    String language = GanttLanguage.getInstance().formatLanguageAndCountry(l);
    String translatorsKey = "about.translations."
        + (Strings.isNullOrEmpty(l.getCountry()) ? l.getLanguage() : l.getLanguage() + "_" + l.getCountry());
    String translators = GanttLanguage.getInstance().getText(translatorsKey);
    if (translators == null) {
      continue;
    }
    builder.append(GanttLanguage.getInstance().formatText("about.translations.entry", language, translators));
  }
  return createHtmlPage("translations", i18n("translations"), GanttLanguage.getInstance().formatText("about.translations", builder.toString()));
}
 
源代码10 项目: monero-wallet-android-app   文件: DisplayHelper.java
/**
 * 获取当前国家的语言
 *
 * @param context
 * @return
 */
public static String getCurCountryLan(Context context) {
    Configuration config = context.getResources().getConfiguration();
    Locale sysLocale;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        sysLocale = config.getLocales().get(0);
    } else {
        //noinspection deprecation
        sysLocale = config.locale;
    }
    return sysLocale.getLanguage()
            + "-"
            + sysLocale.getCountry();
}
 
源代码11 项目: jvm-sandbox-repeater   文件: LocaleHandle.java
public LocaleHandle(Object o) {
    try {
        Locale locale = (Locale) o;
        this.language = locale.getLanguage();
        this.country = locale.getCountry();
        this.variant = locale.getVariant();
    } catch (Throwable t) {
        // ignore
    }
}
 
源代码12 项目: olat   文件: RichTextConfiguration.java
/**
 * Set the language for editor interface. If no translation can be found, the system fallbacks to EN
 * 
 * @param loc
 */
public void setLanguage(Locale loc) {
    // tiny does not support country or vairant codes, only language code
    String langKey = loc.getLanguage();
    ClasspathMediaResource resource = new ClasspathMediaResource(this.getClass(), "_static/js/tinymce/langs/" + langKey + ".js");
    if (resource.getInputStream() == null) {
        // fallback to EN
        langKey = "en";
    }
    setQuotedConfigValue(LANGUAGE, langKey);
}
 
源代码13 项目: jdk8u-jdk   文件: TrueTypeFont.java
static String getCodePage() {

        if (defaultCodePage != null) {
            return defaultCodePage;
        }

        if (FontUtilities.isWindows) {
            defaultCodePage =
                (String)java.security.AccessController.doPrivileged(
                   new sun.security.action.GetPropertyAction("file.encoding"));
        } else {
            if (languages.length != codePages.length) {
                throw new InternalError("wrong code pages array length");
            }
            Locale locale = sun.awt.SunToolkit.getStartupLocale();

            String language = locale.getLanguage();
            if (language != null) {
                if (language.equals("zh")) {
                    String country = locale.getCountry();
                    if (country != null) {
                        language = language + "_" + country;
                    }
                }
                for (int i=0; i<languages.length;i++) {
                    for (int l=0;l<languages[i].length; l++) {
                        if (language.equals(languages[i][l])) {
                            defaultCodePage = codePages[i];
                            return defaultCodePage;
                        }
                    }
                }
            }
        }
        if (defaultCodePage == null) {
            defaultCodePage = "";
        }
        return defaultCodePage;
    }
 
源代码14 项目: Time4A   文件: CalendarText.java
@Override
public boolean supportsLanguage(Locale language) {

    String lang = language.getLanguage();

    for (Locale test : DateFormatSymbols.getAvailableLocales()) {
        if (test.getLanguage().equals(lang)) {
            return true;
        }
    }

    return false;

}
 
源代码15 项目: molgenis   文件: LabelFormatFactory.java
@Override
public Format getFormat(String name, String arguments, Locale locale) {
  return new LabelFormat(locale.getLanguage());
}
 
源代码16 项目: BigApp_Discuz_Android   文件: OtherUtils.java
/**
 * @param context if null, use the default format
 *                (Mozilla/5.0 (Linux; U; Android %s) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 %sSafari/534.30).
 * @return
 */
public static String getUserAgent(Context context) {
    String webUserAgent = null;
    if (context != null) {
        try {
            Class sysResCls = Class.forName("com.android.internal.R$string");
            Field webUserAgentField = sysResCls.getDeclaredField("web_user_agent");
            Integer resId = (Integer) webUserAgentField.get(null);
            webUserAgent = context.getString(resId);
        } catch (Throwable ignored) {
        }
    }
    if (TextUtils.isEmpty(webUserAgent)) {
        webUserAgent = "Mozilla/5.0 (Linux; U; Android %s) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 %sSafari/533.1";
    }

    Locale locale = Locale.getDefault();
    StringBuffer buffer = new StringBuffer();
    // Add version
    final String version = Build.VERSION.RELEASE;
    if (version.length() > 0) {
        buffer.append(version);
    } else {
        // default to "1.0"
        buffer.append("1.0");
    }
    buffer.append("; ");
    final String language = locale.getLanguage();
    if (language != null) {
        buffer.append(language.toLowerCase());
        final String country = locale.getCountry();
        if (country != null) {
            buffer.append("-");
            buffer.append(country.toLowerCase());
        }
    } else {
        // default to "en"
        buffer.append("en");
    }
    // add the model for the release build
    if ("REL".equals(Build.VERSION.CODENAME)) {
        final String model = Build.MODEL;
        if (model.length() > 0) {
            buffer.append("; ");
            buffer.append(model);
        }
    }
    final String id = Build.ID;
    if (id.length() > 0) {
        buffer.append(" Build/");
        buffer.append(id);
    }
    return String.format(webUserAgent, buffer, "Mobile ");
}
 
源代码17 项目: okhttp-OkGo   文件: HttpHeaders.java
/**
 * User-Agent: Mozilla/5.0 (Linux; U; Android 5.0.2; zh-cn; Redmi Note 3 Build/LRX22G) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Mobile Safari/537.36
 */
public static String getUserAgent() {
    if (TextUtils.isEmpty(userAgent)) {
        String webUserAgent = null;
        try {
            Class<?> sysResCls = Class.forName("com.android.internal.R$string");
            Field webUserAgentField = sysResCls.getDeclaredField("web_user_agent");
            Integer resId = (Integer) webUserAgentField.get(null);
            webUserAgent = OkGo.getInstance().getContext().getString(resId);
        } catch (Exception e) {
            // We have nothing to do
        }
        if (TextUtils.isEmpty(webUserAgent)) {
            webUserAgent = "okhttp-okgo/jeasonlzy";
        }

        Locale locale = Locale.getDefault();
        StringBuffer buffer = new StringBuffer();
        // Add version
        final String version = Build.VERSION.RELEASE;
        if (version.length() > 0) {
            buffer.append(version);
        } else {
            // default to "1.0"
            buffer.append("1.0");
        }
        buffer.append("; ");
        final String language = locale.getLanguage();
        if (language != null) {
            buffer.append(language.toLowerCase(locale));
            final String country = locale.getCountry();
            if (!TextUtils.isEmpty(country)) {
                buffer.append("-");
                buffer.append(country.toLowerCase(locale));
            }
        } else {
            // default to "en"
            buffer.append("en");
        }
        // add the model for the release build
        if ("REL".equals(Build.VERSION.CODENAME)) {
            final String model = Build.MODEL;
            if (model.length() > 0) {
                buffer.append("; ");
                buffer.append(model);
            }
        }
        final String id = Build.ID;
        if (id.length() > 0) {
            buffer.append(" Build/");
            buffer.append(id);
        }
        userAgent = String.format(webUserAgent, buffer, "Mobile ");
        return userAgent;
    }
    return userAgent;
}
 
源代码18 项目: audit4j-core   文件: StringUtils.java
/**
 * Determine the RFC 3066 compliant language tag, as used for the HTTP
 * "Accept-Language" header.
 * 
 * @param locale
 *            the Locale to transform to a language tag
 * @return the RFC 3066 compliant language tag as String
 */
public static String toLanguageTag(Locale locale) {
    return locale.getLanguage() + (hasText(locale.getCountry()) ? "-" + locale.getCountry() : "");
}
 
源代码19 项目: development   文件: UserNotificationIT.java
/**
 * Sets the default locale and returns the matching postfix.
 * 
 * @param locale
 *            new default locale.
 * @return matching postfix.
 */
private String setLocale(Locale locale) {
	Locale.setDefault(locale);
	return "_" + locale.getLanguage();
}
 
源代码20 项目: org.openhab.ui.habot   文件: ChatReply.java
/**
 * Constructs a ChatReply for the specified {@link Locale}
 *
 * @param locale the locale
 */
public ChatReply(Locale locale) {
    this.language = locale.getLanguage();
}