本文整理汇总了Java中java.util.Locale.equals方法的典型用法代码示例。如果您正苦于以下问题:Java Locale.equals方法的具体用法?Java Locale.equals怎么用?Java Locale.equals使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.Locale
的用法示例。
在下文中一共展示了Locale.equals方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getBundleMessagesMapForKey
import java.util.Locale; //导入方法依赖的package包/类
private static Map <Locale, String> getBundleMessagesMapForKey(
final String baseName,
final String key,
final ClassLoader loader) {
Map <Locale, String> map = new HashMap <Locale, String> ();
List <Locale> list = new ArrayList <Locale> ();
list.add(new Locale(StringUtils.EMPTY_STRING));
list.addAll(Arrays.asList(Locale.getAvailableLocales()));
for(Locale locale : list) {
ResourceBundle bundle = loadBundle(baseName, locale, loader);
if(bundle!=null && locale.equals(bundle.getLocale()) && !map.containsKey(bundle.getLocale())) {
map.put(locale, getBundleMessage(baseName, locale, loader, key));
}
}
return map;
}
示例2: setLocale
import java.util.Locale; //导入方法依赖的package包/类
/**
* Sets the current <code>Locale</code> of this
* <code>ImageReader</code> to the given value. A value of
* <code>null</code> removes any previous setting, and indicates
* that the reader should localize as it sees fit.
*
* @param locale the desired <code>Locale</code>, or
* <code>null</code>.
*
* @exception IllegalArgumentException if <code>locale</code> is
* non-<code>null</code> but is not one of the values returned by
* <code>getAvailableLocales</code>.
*
* @see #getLocale
*/
public void setLocale(Locale locale) {
if (locale != null) {
Locale[] locales = getAvailableLocales();
boolean found = false;
if (locales != null) {
for (int i = 0; i < locales.length; i++) {
if (locale.equals(locales[i])) {
found = true;
break;
}
}
}
if (!found) {
throw new IllegalArgumentException("Invalid locale!");
}
}
this.locale = locale;
}
示例3: isSystemLocaleSameAsLocaleOfAllEnabledSubtypesOfEnabledImes
import java.util.Locale; //导入方法依赖的package包/类
public boolean isSystemLocaleSameAsLocaleOfAllEnabledSubtypesOfEnabledImes() {
final Locale systemLocale = mContext.getResources().getConfiguration().locale;
final Set<InputMethodSubtype> enabledSubtypesOfEnabledImes = new HashSet<>();
final InputMethodManager inputMethodManager = getInputMethodManager();
final List<InputMethodInfo> enabledInputMethodInfoList =
inputMethodManager.getEnabledInputMethodList();
for (final InputMethodInfo info : enabledInputMethodInfoList) {
final List<InputMethodSubtype> enabledSubtypes =
inputMethodManager.getEnabledInputMethodSubtypeList(
info, true /* allowsImplicitlySelectedSubtypes */);
if (enabledSubtypes.isEmpty()) {
// An IME with no subtypes is found.
return false;
}
enabledSubtypesOfEnabledImes.addAll(enabledSubtypes);
}
for (final InputMethodSubtype subtype : enabledSubtypesOfEnabledImes) {
if (!subtype.isAuxiliary() && !subtype.getLocale().isEmpty()
&& !systemLocale.equals(SubtypeLocaleUtils.getSubtypeLocale(subtype))) {
return false;
}
}
return true;
}
示例4: onResume
import java.util.Locale; //导入方法依赖的package包/类
@Override
public void onResume() {
super.onResume();
LocaleManager.getInstance()
.correctLocale(getContext(), getResources(), getResources().getConfiguration());
if (cachedLocale == null) {
cachedLocale = Locale.getDefault();
} else {
Locale newLocale = LocaleManager.getInstance().getCurrentLocale(getActivity().getApplicationContext());
if (newLocale == null) {
// Using system locale:
newLocale = Locale.getDefault();
}
if (!newLocale.equals(cachedLocale)) {
cachedLocale = newLocale;
applyLocale();
}
}
}
示例5: main
import java.util.Locale; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
int errors = 0;
for (String loctag : args) {
Locale locale = Locale.forLanguageTag(loctag);
if (locale.equals(Locale.ROOT)) {
continue;
}
ResourceBundle rb = ResourceBundle.getBundle("jdk.test.resources.MyResources", locale);
String tag = locale.toLanguageTag(); // normalized
String value = rb.getString("key");
System.out.println("locale = " + tag + ", value = " + value);
if (!value.startsWith(tag + ':')) {
errors++;
}
}
if (errors > 0) {
throw new RuntimeException(errors + " errors");
}
}
示例6: readMarketplaceNames
import java.util.Locale; //导入方法依赖的package包/类
public Map<String, String> readMarketplaceNames(Locale locale,
long periodEnd) {
SqlQuery sqlQuery = new SqlQuery(QUERY_MARKETPLACE_NAMES);
sqlQuery.setDate(1, new Date(periodEnd));
DataSet dataSet = ds.executeQueryForRawData(sqlQuery);
HashMap<String, String> marketplaceIdMap = new HashMap<String, String>();
while (dataSet.next()) {
Locale loc = new Locale(dataSet.getString("locale"));
String mpId = dataSet.getString("marketplaceid");
String mpName = dataSet.getString("value");
if (null != locale && locale.equals(loc)) {
marketplaceIdMap.put(mpId, mpName);
} else if (defaultLocale.equals(loc)
&& null == marketplaceIdMap.get(mpId)) {
marketplaceIdMap.put(mpId, mpName);
}
}
return marketplaceIdMap;
}
示例7: readServiceNames
import java.util.Locale; //导入方法依赖的package包/类
public Map<String, String> readServiceNames(Locale locale, long periodEnd) {
SqlQuery sqlQuery = new SqlQuery(QUERY_SERVICE_NAMES);
sqlQuery.setDate(1, new Date(periodEnd));
DataSet dataSet = ds.executeQueryForRawData(sqlQuery);
HashMap<String, String> marketplaceIdMap = new HashMap<String, String>();
while (dataSet.next()) {
Locale loc = new Locale(dataSet.getString("locale"));
String servId = dataSet.getString("productid");
String servName = dataSet.getString("value");
if (null != locale && locale.equals(loc)) {
marketplaceIdMap.put(servId, servName);
} else if (defaultLocale.equals(loc)
&& null == marketplaceIdMap.get(servId)) {
marketplaceIdMap.put(servId, servName);
}
}
return marketplaceIdMap;
}
示例8: main
import java.util.Locale; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
int errors = 0;
for (String loctag : args) {
Locale locale = Locale.forLanguageTag(loctag);
if (locale.equals(Locale.ROOT)) {
continue;
}
ResourceBundle rb = ResourceBundle.getBundle("jdk.test.resources.MyResources",
locale);
String tag = locale.toLanguageTag(); // normalized
String value = rb.getString("key");
System.out.println(rb.getBaseBundleName() + ": locale = " + tag + ", value = " + value);
if (!value.startsWith(tag + ':')) {
System.out.println("ERROR: " + value + " expected: " + tag);
errors++;
}
// inaccessible bundles
try {
ResourceBundle.getBundle("jdk.test.internal.resources.Foo", locale);
System.out.println("ERROR: jdk.test.internal.resources.Foo should not be accessible");
errors++;
} catch (MissingResourceException e) {
e.printStackTrace();
Throwable cause = e.getCause();
System.out.println("Expected: " +
(cause != null ? cause.getMessage() : e.getMessage()));
}
}
if (errors > 0) {
throw new RuntimeException(errors + " errors");
}
}
示例9: loadZoneStrings
import java.util.Locale; //导入方法依赖的package包/类
private static String[][] loadZoneStrings(Locale locale) {
// If the provider is a TimeZoneNameProviderImpl, call its getZoneStrings
// in order to avoid per-ID retrieval.
LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(TimeZoneNameProvider.class, locale);
TimeZoneNameProvider provider = adapter.getTimeZoneNameProvider();
if (provider instanceof TimeZoneNameProviderImpl) {
String[][] zoneStrings = ((TimeZoneNameProviderImpl)provider).getZoneStrings(locale);
if (zoneStrings.length == 0 && locale.equals(Locale.ROOT)) {
// Unlike other *Name provider, zoneStrings search won't do the fallback
// name search. If the ResourceBundle found for the root locale contains no
// zoneStrings, just use the one for English, assuming English bundle
// contains all the tzids and their names.
zoneStrings= getZoneStrings(Locale.ENGLISH);
}
return zoneStrings;
}
// Performs per-ID retrieval.
Set<String> zoneIDs = LocaleProviderAdapter.forJRE().getLocaleResources(locale).getZoneIDs();
List<String[]> zones = new LinkedList<>();
for (String key : zoneIDs) {
String[] names = retrieveDisplayNamesImpl(key, locale);
if (names != null) {
zones.add(names);
}
}
String[][] zonesArray = new String[zones.size()][];
return zones.toArray(zonesArray);
}
示例10: getLayoutDirectionFromLocale
import java.util.Locale; //导入方法依赖的package包/类
public int getLayoutDirectionFromLocale(@Nullable Locale locale) {
if (!(locale == null || locale.equals(TextUtilsCompat.ROOT))) {
String scriptSubtag = ICUCompat.maximizeAndGetScript(locale);
if (scriptSubtag == null) {
return getLayoutDirectionFromFirstChar(locale);
}
if (scriptSubtag.equalsIgnoreCase(TextUtilsCompat.ARAB_SCRIPT_SUBTAG) || scriptSubtag.equalsIgnoreCase(TextUtilsCompat.HEBR_SCRIPT_SUBTAG)) {
return 1;
}
}
return 0;
}
示例11: getLocalValue
import java.util.Locale; //导入方法依赖的package包/类
/**
* Get the localized value of an entity's attribute
* @param entityId the id of the entity
* @param entityClass the class of the entity
* @param attributeName the name of the attribute that must be defined as Map<Locale, String>
* @param locale the locale for the value, use null for the current request locale
* @param returnNull (optional) true if null must be returned when no value is present instead of the empty string
* @return the localized value in the specified locale, or in the default configured locale if the value is not set for that locale,
* or an empty string if no value is found or null if no value is found and returnNull is true.
*/
public String getLocalValue(long entityId, Class<?> entityClass, String attributeName, Locale locale, Boolean... returnNull) {
// select color from YadaArticle_color where YadaArticle_id=123 and locale="en_US"
if (locale==null) {
locale = LocaleContextHolder.getLocale();
}
String className = entityClass.getSimpleName();
String tableName = className + "_" + attributeName;
String idColumn = className + "_id";
YadaSql yadaSql = YadaSql.instance().selectFrom("select " + attributeName + " from " + tableName)
.where(idColumn + " = :entityId").and()
.where("locale = :localeString").and()
.setParameter("entityId", entityId)
.setParameter("localeString", locale.toString());
List<?> result = yadaSql.nativeQuery(em).getResultList();
if (result.isEmpty()) {
// Try with the default locale
Locale defaultLocale = config.getDefaultLocale();
if (defaultLocale!=null && !defaultLocale.equals(locale)) {
yadaSql.setParameter("localeString", defaultLocale.toString());
result = yadaSql.nativeQuery(em).getResultList();
}
}
if (result.isEmpty()) {
if (returnNull!=null && returnNull.length>0 && Boolean.TRUE.equals(returnNull[0])) {
return null;
}
return "";
}
return (String) result.get(0);
}
示例12: setLocale
import java.util.Locale; //导入方法依赖的package包/类
/**
* Set locale to input. If input method doesn't support specified locale,
* false will be returned and its behavior is not changed.
*
* @param lang locale to input
* @return the true is returned when specified locale is supported.
*/
public boolean setLocale(Locale lang) {
if (lang.equals(locale)) {
return true;
}
// special compatibility rule for Japanese and Korean
if (locale.equals(Locale.JAPAN) && lang.equals(Locale.JAPANESE) ||
locale.equals(Locale.KOREA) && lang.equals(Locale.KOREAN)) {
return true;
}
return false;
}
示例13: intercept
import java.util.Locale; //导入方法依赖的package包/类
@Override
public String intercept(final ActionInvocation invocation) throws Exception {
HttpServletRequest request = ServletActionContext.getRequest();
HttpSession session = request.getSession(true);
Locale locale = (Locale) session.getAttribute(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE);
// Locale adminpagelocale = (Locale)
// session.getAttribute(ADMIN_PAGE_LOCALE);
// if (locale == null && adminpagelocale == null) {
if (locale == null) {
if (request.getLocale().equals(Locale.CHINA) || request.getLocale().equals(Locale.CHINESE)) {
session.setAttribute(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE, Locale.CHINA);
logger.debug("Language is set to Chinese. from IP <" + request.getRemoteAddr() + ">");
} else if (request.getLocale().equals(Locale.JAPAN) || request.getLocale().equals(Locale.JAPANESE)) {
session.setAttribute(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE, Locale.JAPAN);
logger.debug("Language is set to Japanese. from IP <" + request.getRemoteAddr() + ">");
} else {
session.setAttribute(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE, Locale.US);
logger.debug("Language is set to English.from IP <" + request.getRemoteAddr() + ">");
}
}
// else if (adminpagelocale != null) {
// session.setAttribute(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE,
// adminpagelocale);
// }
if (invocation.getAction() instanceof AbstractAdminBaseAction
&& (locale == null || !locale.equals(Locale.CHINA))) {
// 使用中文界面
// session.setAttribute(ADMIN_PAGE_LOCALE,
// session.getAttribute(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE));
session.setAttribute(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE, Locale.CHINA);
logger.debug("because access page is admin page. Language is set to Chinese. from IP <"
+ request.getRemoteAddr() + ">");
}
return invocation.invoke();
}
示例14: onSubtypeChanged
import java.util.Locale; //导入方法依赖的package包/类
public static void onSubtypeChanged(@NonNull final RichInputMethodSubtype subtype,
final boolean implicitlyEnabledSubtype, @NonNull final Locale systemLocale) {
final Locale newLocale = subtype.getLocale();
if (systemLocale.equals(newLocale)) {
sIsSystemLanguageSameAsInputLanguage = true;
return;
}
if (!systemLocale.getLanguage().equals(newLocale.getLanguage())) {
sIsSystemLanguageSameAsInputLanguage = false;
return;
}
// If the subtype is enabled explicitly, the language name should be displayed even when
// the keyboard language and the system language are equal.
sIsSystemLanguageSameAsInputLanguage = implicitlyEnabledSubtype;
}
示例15: StringManager
import java.util.Locale; //导入方法依赖的package包/类
/**
* Creates a new StringManager for a given package. This is a
* private method and all access to it is arbitrated by the
* static getManager method call so that only one StringManager
* per package will be created.
*
* @param packageName Name of package to create StringManager for.
*/
private StringManager(String packageName, Locale locale) {
String bundleName = packageName + ".LocalStrings";
ResourceBundle bnd = null;
try {
bnd = ResourceBundle.getBundle(bundleName, locale);
} catch (MissingResourceException ex) {
// Try from the current loader (that's the case for trusted apps)
// Should only be required if using a TC5 style classloader structure
// where common != shared != server
ClassLoader cl = Thread.currentThread().getContextClassLoader();
if (cl != null) {
try {
bnd = ResourceBundle.getBundle(bundleName, locale, cl);
} catch (MissingResourceException ex2) {
// Ignore
}
}
}
bundle = bnd;
// Get the actual locale, which may be different from the requested one
if (bundle != null) {
Locale bundleLocale = bundle.getLocale();
if (bundleLocale.equals(Locale.ROOT)) {
this.locale = Locale.ENGLISH;
} else {
this.locale = bundleLocale;
}
} else {
this.locale = null;
}
}