本文整理汇总了Java中java.util.Locale.getLanguage方法的典型用法代码示例。如果您正苦于以下问题:Java Locale.getLanguage方法的具体用法?Java Locale.getLanguage怎么用?Java Locale.getLanguage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.Locale
的用法示例。
在下文中一共展示了Locale.getLanguage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toBundleName
import java.util.Locale; //导入方法依赖的package包/类
@Override
protected String toBundleName(String baseName, Locale locale) {
// Convert baseName to its properties resource name for the given locale
// e.g., jdk.test.resources.MyResources -> jdk/test/resources/asia/MyResources_zh_TW
StringBuilder sb = new StringBuilder();
int index = baseName.lastIndexOf('.');
sb.append(baseName.substring(0, index))
.append(".asia")
.append(baseName.substring(index));
String lang = locale.getLanguage();
if (!lang.isEmpty()) {
sb.append('_').append(lang);
String country = locale.getCountry();
if (!country.isEmpty()) {
sb.append('_').append(country);
}
}
return sb.toString();
}
示例2: recreateFormatters
import java.util.Locale; //导入方法依赖的package包/类
public void recreateFormatters() {
Locale locale = currentLocale;
if (locale == null) {
locale = Locale.getDefault();
}
String lang = locale.getLanguage();
if (lang == null) {
lang = "en";
}
isRTL = (lang.toLowerCase().equals("ar") || lang.equalsIgnoreCase("fa") || lang.equalsIgnoreCase("fa_Fa")) ;
nameDisplayOrder = lang.toLowerCase().equals("ko") ? 2 : 1;
formatterMonth = 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");
formatterMonthYear = createFormatter(locale, getStringInternal("formatterMonthYear", R.string.formatterMonthYear), "MMMM 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");
}
示例3: setLocale
import java.util.Locale; //导入方法依赖的package包/类
/**
* Called explicitly by user to set the Content-Language and the default
* encoding
*/
public void setLocale(Locale locale) {
if (locale == null) {
return; // throw an exception?
}
// Save the locale for use by getLocale()
this.locale = locale;
// Set the contentLanguage for header output
contentLanguage = locale.getLanguage();
if ((contentLanguage != null) && (contentLanguage.length() > 0)) {
String country = locale.getCountry();
StringBuilder value = new StringBuilder(contentLanguage);
if ((country != null) && (country.length() > 0)) {
value.append('-');
value.append(country);
}
contentLanguage = value.toString();
}
}
示例4: toBundleName
import java.util.Locale; //导入方法依赖的package包/类
/**
* Changes baseName to its per-language package name and
* calls the super class implementation. For example,
* if the baseName is "sun.text.resources.FormatData" and locale is ja_JP,
* the baseName is changed to "sun.text.resources.ja.FormatData". If
* baseName contains "cldr", such as "sun.text.resources.cldr.FormatData",
* the name is changed to "sun.text.resources.cldr.jp.FormatData".
*/
@Override
public String toBundleName(String baseName, Locale locale) {
String newBaseName = baseName;
String lang = locale.getLanguage();
if (lang.length() > 0) {
if (baseName.startsWith(UTIL_RESOURCES_PACKAGE)
|| baseName.startsWith(TEXT_RESOURCES_PACKAGE)) {
// Assume the lengths are the same.
if (UTIL_RESOURCES_PACKAGE.length()
!= TEXT_RESOURCES_PACKAGE.length()) {
throw new InternalError("The resources package names have different lengths.");
}
int index = TEXT_RESOURCES_PACKAGE.length();
if (baseName.indexOf(CLDR, index) > 0) {
index += CLDR.length();
}
newBaseName = baseName.substring(0, index + 1) + lang
+ baseName.substring(index);
}
}
return super.toBundleName(newBaseName, locale);
}
示例5: fallback
import java.util.Locale; //导入方法依赖的package包/类
/**
* Fallback from the given locale name by removing the rightmost _-delimited
* element. If there is none, return the root locale ("", "", ""). If this
* is the root locale, return null. NOTE: The string "root" is not
* recognized; do not use it.
*
* @return a new Locale that is a fallback from the given locale, or null.
*/
public static Locale fallback(Locale loc) {
// Split the locale into parts and remove the rightmost part
String[] parts = new String[]
{ loc.getLanguage(), loc.getCountry(), loc.getVariant() };
int i;
for (i=2; i>=0; --i) {
if (parts[i].length() != 0) {
parts[i] = "";
break;
}
}
if (i<0) {
return null; // All parts were empty
}
return new Locale(parts[0], parts[1], parts[2]);
}
示例6: n
import java.util.Locale; //导入方法依赖的package包/类
public static String[] n(Context context) {
String[] strArr = new String[2];
try {
Locale y = y(context);
if (y != null) {
strArr[0] = y.getCountry();
strArr[1] = y.getLanguage();
}
if (TextUtils.isEmpty(strArr[0])) {
strArr[0] = "Unknown";
}
if (TextUtils.isEmpty(strArr[1])) {
strArr[1] = "Unknown";
}
} catch (Throwable e) {
bv.e(a, "error in getLocaleInfo", e);
}
return strArr;
}
示例7: LoadApplication
import java.util.Locale; //导入方法依赖的package包/类
public static void LoadApplication (Context context, ApplicationInfo runtimePackage, String[] apks)
{
synchronized (lock) {
if (context instanceof android.app.Application) {
Context = context;
}
if (!initialized) {
android.content.IntentFilter timezoneChangedFilter = new android.content.IntentFilter (
android.content.Intent.ACTION_TIMEZONE_CHANGED
);
context.registerReceiver (new mono.android.app.NotifyTimeZoneChanges (), timezoneChangedFilter);
System.loadLibrary("monodroid");
Locale locale = Locale.getDefault ();
String language = locale.getLanguage () + "-" + locale.getCountry ();
String filesDir = context.getFilesDir ().getAbsolutePath ();
String cacheDir = context.getCacheDir ().getAbsolutePath ();
String dataDir = getNativeLibraryPath (context);
ClassLoader loader = context.getClassLoader ();
Runtime.init (
language,
apks,
getNativeLibraryPath (runtimePackage),
new String[]{
filesDir,
cacheDir,
dataDir,
},
loader,
new java.io.File (
android.os.Environment.getExternalStorageDirectory (),
"Android/data/" + context.getPackageName () + "/files/.__override__").getAbsolutePath (),
MonoPackageManager_Resources.Assemblies,
context.getPackageName ());
mono.android.app.ApplicationRegistration.registerApplications ();
initialized = true;
}
}
}
示例8: toXMLName
import java.util.Locale; //导入方法依赖的package包/类
private String toXMLName(String baseName, Locale locale) {
StringBuilder sb = new StringBuilder(baseName.replace('.', '/'));
String lang = locale.getLanguage();
if (!lang.isEmpty()) {
sb.append('_').append(lang);
String country = locale.getCountry();
if (!country.isEmpty()) {
sb.append('_').append(country);
}
}
return sb.append(".xml").toString();
}
示例9: createPriceModelTag
import java.util.Locale; //导入方法依赖的package包/类
public static LocalizedBillingResource createPriceModelTag(Locale locale,
UUID objectID, String priceModelTag) {
LocalizedBillingResource localizedBillingresource = new LocalizedBillingResource(
objectID, locale.getLanguage(),
LocalizedBillingResourceType.PRICEMODEL_TAG);
localizedBillingresource.setDataType(MediaType.TEXT_PLAIN);
localizedBillingresource.setValue(priceModelTag.getBytes());
if (priceModelTag.length() > 30) {
logger.logWarn(
Log4jLogger.SYSTEM_LOG,
LogMessageIdentifier.WARN_TOO_MANY_CHARACTERS_FOR_PRICE_FROM_TAG);
}
return localizedBillingresource;
}
示例10: getI18nTraduction
import java.util.Locale; //导入方法依赖的package包/类
/**
* Renvoi la valeur d'un traduction (langue default si plus d'une traduction)
*
* @param i18n
* @param locale
* @return la valeur d'un traduction par une locale
*/
public String getI18nTraduction(I18n i18n, Locale locale) {
String codLangue = null;
if (locale != null) {
codLangue = locale.getLanguage();
}
return getI18nTraduction(i18n, codLangue);
}
示例11: RefCapablePropertyResourceBundle
import java.util.Locale; //导入方法依赖的package包/类
private RefCapablePropertyResourceBundle(String baseName,
PropertyResourceBundle wrappedBundle, ClassLoader loader) {
this.baseName = baseName;
this.wrappedBundle = wrappedBundle;
Locale locale = wrappedBundle.getLocale();
this.loader = loader;
language = locale.getLanguage();
country = locale.getCountry();
variant = locale.getVariant();
if (language.length() < 1) language = null;
if (country.length() < 1) country = null;
if (variant.length() < 1) variant = null;
}
示例12: getStopwords
import java.util.Locale; //导入方法依赖的package包/类
/**
* The stopwords for the parsed language or <code>null</code> if none are defined
* @param lang the {@link Local} representing the language or <code>null</code> to get the default stopwords
* @return the stopwords or <code>null</code> if none are configured for this language
*/
public Map<String,Collection<String>> getStopwords(Locale lang){
final String key = lang == null ? "default" : lang.getLanguage();
final Map<String,Collection<String>> stopwords;
if(stopwordLists.containsKey(key)){
stopwords = stopwordLists.get(key);
} else {
stopwords = parseStopwords(stopword.get(key), lang);
stopwordLists.put(key, stopwords); //no list for this language present
}
return stopwords;
}
示例13: getLanguageOnSpacebarFormatType
import java.util.Locale; //导入方法依赖的package包/类
public static int getLanguageOnSpacebarFormatType(
@Nonnull final RichInputMethodSubtype subtype) {
if (subtype.isNoLanguage()) {
return FORMAT_TYPE_FULL_LOCALE;
}
// Only this subtype is enabled and equals to the system locale.
if (sEnabledSubtypes.size() < 2 && sIsSystemLanguageSameAsInputLanguage) {
return FORMAT_TYPE_NONE;
}
final Locale locale = subtype.getLocale();
if (locale == null) {
return FORMAT_TYPE_NONE;
}
final String keyboardLanguage = locale.getLanguage();
final String keyboardLayout = subtype.getKeyboardLayoutSetName();
int sameLanguageAndLayoutCount = 0;
for (final InputMethodSubtype ims : sEnabledSubtypes) {
final String language = SubtypeLocaleUtils.getSubtypeLocale(ims).getLanguage();
if (keyboardLanguage.equals(language) && keyboardLayout.equals(
SubtypeLocaleUtils.getKeyboardLayoutSetName(ims))) {
sameLanguageAndLayoutCount++;
}
}
// Display full locale name only when there are multiple subtypes that have the same
// locale and keyboard layout. Otherwise displaying language name is enough.
return sameLanguageAndLayoutCount > 1 ? FORMAT_TYPE_FULL_LOCALE
: FORMAT_TYPE_LANGUAGE_ONLY;
}
示例14: isZh
import java.util.Locale; //导入方法依赖的package包/类
public boolean isZh() {
Locale locale = getResources().getConfiguration().locale;
String language = locale.getLanguage();
if (language.endsWith("zh"))
return true;
else
return false;
}
示例15: prependToAcceptLanguagesIfNecessary
import java.util.Locale; //导入方法依赖的package包/类
/**
* Get the language code for the default locales and prepend it to the Accept-Language string
* if it isn't already present. The logic should match PrependToAcceptLanguagesIfNecessary in
* chrome/browser/android/preferences/pref_service_bridge.cc
* @param locales A comma separated string that represents a list of default locales.
* @param acceptLanguages The default language list for the language of the user's locales.
* @return An updated language list.
*/
@VisibleForTesting
static String prependToAcceptLanguagesIfNecessary(String locales, String acceptLanguages) {
String localeStrings = locales + "," + acceptLanguages;
String[] localeList = localeStrings.split(",");
ArrayList<Locale> uniqueList = new ArrayList<>();
for (String localeString : localeList) {
Locale locale = LocaleUtils.forLanguageTag(localeString);
if (uniqueList.contains(locale) || locale.getLanguage().isEmpty()) {
continue;
}
uniqueList.add(locale);
}
// If language is not in the accept languages list, also add language code.
// A language code should only be inserted after the last languageTag that
// contains that language.
// This will work with the IDS_ACCEPT_LANGUAGE localized strings bundled
// with Chrome but may fail on arbitrary lists of language tags due to
// differences in case and whitespace.
HashSet<String> seenLanguages = new HashSet<>();
ArrayList<String> outputList = new ArrayList<>();
for (int i = uniqueList.size() - 1; i >= 0; i--) {
Locale localeAdd = uniqueList.get(i);
String languageAdd = localeAdd.getLanguage();
String countryAdd = localeAdd.getCountry();
if (!seenLanguages.contains(languageAdd)) {
seenLanguages.add(languageAdd);
outputList.add(languageAdd);
}
if (!countryAdd.isEmpty()) {
outputList.add(LocaleUtils.toLanguageTag(localeAdd));
}
}
Collections.reverse(outputList);
return TextUtils.join(",", outputList);
}