Java Code Examples for java.util.Locale#getLanguage()
The following examples show how to use
java.util.Locale#getLanguage() .
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
Source Project: openboard File: DictionaryInfoUtils.java License: GNU General Public License v3.0 | 6 votes |
/** * 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; }
Example 2
Source Project: Time4A File: EastAsianST.java License: Apache License 2.0 | 6 votes |
@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 } }
Example 3
Source Project: Viewer File: CommonUtil.java License: Apache License 2.0 | 5 votes |
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; }
Example 4
Source Project: XposedSmsCode File: Utils.java License: GNU General Public License v3.0 | 5 votes |
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; }
Example 5
Source Project: jdk8u-dev-jdk File: ExecutableInputMethodManager.java License: GNU General Public License v2.0 | 5 votes |
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; }
Example 6
Source Project: Telegram File: LocaleController.java License: GNU General Public License v2.0 | 5 votes |
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"); }
Example 7
Source Project: albert File: UserSessionUtil.java License: MIT License | 5 votes |
public static String getSysLanguage(){ Locale locale = LocaleContextHolder.getLocale(); if(locale != null){ return locale.getLanguage() + "_" + locale.getCountry(); } else { return Constants.LOCALE_LANGUAGE.en_US; } }
Example 8
Source Project: jdk8u_jdk File: ExecutableInputMethodManager.java License: GNU General Public License v2.0 | 5 votes |
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; }
Example 9
Source Project: ganttproject File: AboutDialog2.java License: GNU General Public License v3.0 | 5 votes |
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())); }
Example 10
Source Project: monero-wallet-android-app File: DisplayHelper.java License: MIT License | 5 votes |
/** * 获取当前国家的语言 * * @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(); }
Example 11
Source Project: jvm-sandbox-repeater File: LocaleHandle.java License: Apache License 2.0 | 5 votes |
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 } }
Example 12
Source Project: olat File: RichTextConfiguration.java License: Apache License 2.0 | 5 votes |
/** * 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); }
Example 13
Source Project: jdk8u-jdk File: TrueTypeFont.java License: GNU General Public License v2.0 | 5 votes |
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; }
Example 14
Source Project: Time4A File: CalendarText.java License: Apache License 2.0 | 5 votes |
@Override public boolean supportsLanguage(Locale language) { String lang = language.getLanguage(); for (Locale test : DateFormatSymbols.getAvailableLocales()) { if (test.getLanguage().equals(lang)) { return true; } } return false; }
Example 15
Source Project: molgenis File: LabelFormatFactory.java License: GNU Lesser General Public License v3.0 | 4 votes |
@Override public Format getFormat(String name, String arguments, Locale locale) { return new LabelFormat(locale.getLanguage()); }
Example 16
Source Project: BigApp_Discuz_Android File: OtherUtils.java License: Apache License 2.0 | 4 votes |
/** * @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 "); }
Example 17
Source Project: okhttp-OkGo File: HttpHeaders.java License: Apache License 2.0 | 4 votes |
/** * 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; }
Example 18
Source Project: audit4j-core File: StringUtils.java License: Apache License 2.0 | 2 votes |
/** * 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() : ""); }
Example 19
Source Project: development File: UserNotificationIT.java License: Apache License 2.0 | 2 votes |
/** * 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(); }
Example 20
Source Project: org.openhab.ui.habot File: ChatReply.java License: Eclipse Public License 1.0 | 2 votes |
/** * Constructs a ChatReply for the specified {@link Locale} * * @param locale the locale */ public ChatReply(Locale locale) { this.language = locale.getLanguage(); }