java.util.Locale.toString()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(9.1k)|赞(0)|评价(0)|浏览(173)

本文整理了Java中java.util.Locale.toString()方法的一些代码示例,展示了Locale.toString()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Locale.toString()方法的具体详情如下:
包路径:java.util.Locale
类名称:Locale
方法名:toString

Locale.toString介绍

[英]Returns the string representation of this Locale. It consists of the language code, country code and variant separated by underscores. If the language is missing the string begins with an underscore. If the country is missing there are 2 underscores between the language and the variant. The variant cannot stand alone without a language and/or country code: in this case this method would return the empty string.

Examples: "en", "en_US", "_US", "en__POSIX", "en_US_POSIX"
[中]返回此区域设置的字符串表示形式。它由语言代码、国家代码和用下划线分隔的变体组成。如果语言缺失,则字符串以下划线开头。如果缺少国家,则语言和变体之间有2个下划线。如果没有语言和/或国家/地区代码,变体无法独立存在:在这种情况下,此方法将返回空字符串。
示例:“en”、“en_US”、“en_US”、“en_POSIX”、“en_US POSIX”

代码示例

代码示例来源:origin: spring-projects/spring-framework

@Override
protected String resolveCodeWithoutArguments(String code, Locale locale) {
  return this.messages.get(code + '_' + locale.toString());
}

代码示例来源:origin: org.netbeans.api/org-openide-util

/** Creates new LocaleIterator for given locale.
* @param locale given Locale
*/
public LocaleIterator(Locale locale) {
  this.locale = this.initLocale = locale;
  if (locale.equals(Locale.getDefault())) {
    defaultInProgress = true;
  }
  current = '_' + locale.toString();
  if (brandingToken == null) {
    branding = null;
  } else {
    branding = "_" + brandingToken; // NOI18N
  }
  //System.err.println("Constructed: " + this);
}

代码示例来源:origin: alipay/sofa-rpc

String encoding = Locale.getDefault().toString();
if (encoding == null || encoding.length() == 0) {
  encoding = Locale.ENGLISH.toString();
  name = "sofa-rpc/" + filename + "_" + Locale.ENGLISH.toString() + ".properties";
    LOG_CODES.put((String) entry.getKey(), (String) entry.getValue());
  NOTE = LOG_CODES.get(NOTE_CODE) == null ? "" : LOG_CODES.get(NOTE_CODE);
} catch (Exception e) {
  LOGGER.error("初始化日志码失败:" + name, e);

代码示例来源:origin: org.springframework/spring-context

@Override
protected String resolveCodeWithoutArguments(String code, Locale locale) {
  return this.messages.get(code + '_' + locale.toString());
}

代码示例来源:origin: alipay/sofa-rpc

String encoding = Locale.getDefault().toString();
if (encoding == null || encoding.length() == 0) {
  encoding = Locale.ENGLISH.toString();
  name = "sofa-rpc/" + filename + "_" + Locale.ENGLISH.toString() + ".properties";
    LOG_CODES.put((String) entry.getKey(), (String) entry.getValue());
  NOTE = LOG_CODES.get(NOTE_CODE) == null ? "" : LOG_CODES.get(NOTE_CODE);
} catch (Exception e) {
  LOGGER.error("初始化日志码失败:" + name, e);

代码示例来源:origin: robovm/robovm

/**
 * Returns the name of this locale's country, localized to {@code locale}.
 * Returns the empty string if this locale does not correspond to a specific
 * country.
 */
public String getDisplayCountry(Locale locale) {
  if (countryCode.isEmpty()) {
    return "";
  }
  String result = ICU.getDisplayCountryNative(toString(), locale.toString());
  if (result == null) { // TODO: do we need to do this, or does ICU do it for us?
    result = ICU.getDisplayCountryNative(toString(), Locale.getDefault().toString());
  }
  return result;
}

代码示例来源:origin: spring-projects/spring-framework

@Override
@Nullable
protected MessageFormat resolveCode(String code, Locale locale) {
  String key = code + '_' + locale.toString();
  String msg = this.messages.get(key);
  if (msg == null) {
    return null;
  }
  synchronized (this.cachedMessageFormats) {
    MessageFormat messageFormat = this.cachedMessageFormats.get(key);
    if (messageFormat == null) {
      messageFormat = createMessageFormat(msg, locale);
      this.cachedMessageFormats.put(key, messageFormat);
    }
    return messageFormat;
  }
}

代码示例来源:origin: javax.el/javax.el-api

locale = Locale.getDefault();
ResourceBundle rb = null;
if (null == (rb = (ResourceBundle)
    threadMap.get(locale.toString()))) {
  rb = ResourceBundle.getBundle("javax.el.PrivateMessages",
                 locale);
  threadMap.put(locale.toString(), rb);

代码示例来源:origin: robovm/robovm

/**
 * Returns the full variant name in the specified {@code Locale} for the variant code
 * of this {@code Locale}. If there is no matching variant name, the variant code is
 * returned.
 */
public String getDisplayVariant(Locale locale) {
  if (variantCode.length() == 0) {
    return variantCode;
  }
  String result = ICU.getDisplayVariantNative(toString(), locale.toString());
  if (result == null) { // TODO: do we need to do this, or does ICU do it for us?
    result = ICU.getDisplayVariantNative(toString(), Locale.getDefault().toString());
  }
  return result;
}

代码示例来源:origin: org.springframework/spring-context

@Override
@Nullable
protected MessageFormat resolveCode(String code, Locale locale) {
  String key = code + '_' + locale.toString();
  String msg = this.messages.get(key);
  if (msg == null) {
    return null;
  }
  synchronized (this.cachedMessageFormats) {
    MessageFormat messageFormat = this.cachedMessageFormats.get(key);
    if (messageFormat == null) {
      messageFormat = createMessageFormat(msg, locale);
      this.cachedMessageFormats.put(key, messageFormat);
    }
    return messageFormat;
  }
}

代码示例来源:origin: stackoverflow.com

dataPairToTableRow(
      envStrings[ii],
      environment.get(envStrings[ii])));
  String suffix = "";
  Locale locale = sortableLocale[ii].getLocale();
  if (locale.equals(Locale.getDefault())) {
    prefix = "<b>";
    suffix = "</b>";
      locale.toString() +
      suffix,
      prefix +
    getOutputWidgetForContent(sb.toString()));
Locale.getDefault();
int border = 5;
JPanel p = new JPanel(new BorderLayout());
return locale.toString();
SortableLocale locale2 = (SortableLocale) object2;
return locale.toString().compareTo(
    locale2.toString());

代码示例来源:origin: dropwizard/dropwizard

Locale detectLocale(HttpHeaders headers) {
  final List<Locale> languages;
  try {
    languages = headers.getAcceptableLanguages();
  } catch (HeaderValueException e) {
    throw new WebApplicationException(e.getMessage(), Response.Status.BAD_REQUEST);
  }
  for (Locale locale : languages) {
    if (!locale.toString().contains("*")) { // Freemarker doesn't do wildcards well
      return locale;
    }
  }
  return Locale.getDefault();
}

代码示例来源:origin: org.apache.poi/poi

public static String getPrefixForLocale( Locale locale ) {
  String localeString = locale.toString().toLowerCase(locale);
  String result = localePrefixes.get( localeString );
  if( result == null ) {
    result = localePrefixes.get( localeString.substring( 0, 2 ) );
    if( result ==  null ) {
      Locale parentLocale = new Locale(localeString.substring( 0, 2 ));
      logger.log( POILogger.ERROR, "Unable to find prefix for " + locale + "(" + locale.getDisplayName(Locale.ROOT) + ") or " 
          + localeString.substring( 0, 2 ) + "(" + parentLocale.getDisplayName(Locale.ROOT) + ")" );
      return "";
    }
  }
  return result;
}

代码示例来源:origin: camunda/camunda-bpm-platform

private DateTimeFormatter getFormatter(Locale locale) {
  locale = (locale == null ? Locale.getDefault() : locale);
  String key = Integer.toString(iType + (iDateStyle << 4) + (iTimeStyle << 8)) + locale.toString();
  DateTimeFormatter f = null;
  synchronized (cCache) {
    f = cCache.get(key);
    if (f == null) {
      String pattern = getPattern(locale);
      f = DateTimeFormat.forPattern(pattern);
      cCache.put(key, f);
    }
  }
  return f;
}

代码示例来源:origin: facebook/facebook-android-sdk

private static HttpURLConnection createConnection(URL url) throws IOException {
  HttpURLConnection connection;
  connection = (HttpURLConnection) url.openConnection();
  connection.setRequestProperty(USER_AGENT_HEADER, getUserAgent());
  connection.setRequestProperty(ACCEPT_LANGUAGE_HEADER, Locale.getDefault().toString());
  connection.setChunkedStreamingMode(0);
  return connection;
}

代码示例来源:origin: BroadleafCommerce/BroadleafCommerce

/**
   * Provides a cached approach for creating NumberFormat instances. More performant
   * than creating a new one each time.
   *
   * @param locale   the Locale
   * @param currency the Currency
   * @return either a new NumberFormat instance, or one taken from the cache
   */
  public static NumberFormat getNumberFormatFromCache(Locale locale, Currency currency) {
    String key = locale.toString() + currency.getCurrencyCode();
    if (!FORMAT_CACHE.containsKey(key)) {
      NumberFormat format = NumberFormat.getCurrencyInstance(locale);
      format.setCurrency(currency);
      FORMAT_CACHE.put(key, format);
    }
    return FORMAT_CACHE.get(key);
  }
}

代码示例来源:origin: javax.el/el-api

locale = Locale.getDefault();
ResourceBundle rb = null;
if (null == (rb = (ResourceBundle)
threadMap.get(locale.toString()))) {
  rb = ResourceBundle.getBundle("javax.el.PrivateMessages",
                 locale);
  threadMap.put(locale.toString(), rb);

代码示例来源:origin: robovm/robovm

/**
 * Returns the name of this locale's language, localized to {@code locale}.
 * If the language name is unknown, the language code is returned.
 */
public String getDisplayLanguage(Locale locale) {
  if (languageCode.isEmpty()) {
    return "";
  }
  // http://b/8049507 --- frameworks/base should use fil_PH instead of tl_PH.
  // Until then, we're stuck covering their tracks, making it look like they're
  // using "fil" when they're not.
  String localeString = toString();
  if (languageCode.equals("tl")) {
    localeString = toNewString("fil", countryCode, variantCode);
  }
  String result = ICU.getDisplayLanguageNative(localeString, locale.toString());
  if (result == null) { // TODO: do we need to do this, or does ICU do it for us?
    result = ICU.getDisplayLanguageNative(localeString, Locale.getDefault().toString());
  }
  return result;
}

代码示例来源:origin: jenkinsci/jenkins

String bundleKey = baseName + ":" + locale.toString();
JSONObject bundleJSON = bundles.get(bundleKey);

代码示例来源:origin: org.xworker/xworker_core

public static UtilResource getInstance(Locale locale){
  if(locale == null){
    locale = Locale.getDefault();
  }
  
  UtilResource res = resouceCache.get(locale.toString());
  if(res == null){
    res = new UtilResource(locale);
    resouceCache.put(locale.toString(), res);
  }
  
  return res;
}

相关文章