java.util.ResourceBundle.getLocale()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(8.1k)|赞(0)|评价(0)|浏览(193)

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

ResourceBundle.getLocale介绍

[英]Gets the Locale of this ResourceBundle. In case a bundle was not found for the requested Locale, this will return the actual Locale of this resource bundle that was found after doing a fallback.
[中]获取此ResourceBundle的区域设置。如果没有为请求的区域设置找到捆绑包,这将返回执行回退后找到的此资源捆绑包的实际区域设置。

代码示例

代码示例来源:origin: SonarSource/sonarqube

public Locale getEffectiveLocale(Locale locale) {
 Locale bundleLocale = ResourceBundle.getBundle(BUNDLE_PACKAGE + "core", locale, this.classloader, this.control).getLocale();
 locale.getISO3Language();
 return bundleLocale.getLanguage().isEmpty() ? Locale.ENGLISH : bundleLocale;
}

代码示例来源:origin: languagetool-org/languagetool

private static boolean isValidBundleFor(Language lang, ResourceBundle bundle) {
  return lang.getLocale().getLanguage().equals(bundle.getLocale().getLanguage());
 }
}

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

Font getFont() {
  if (Locale.CHINESE.getLanguage()
      .equals(I18N.getResourceBundle().getLocale().getLanguage())) {
    return getChineseFont();
  }
  return font;
}

代码示例来源:origin: org.apache.commons/commons-math3

/** {@inheritDoc} */
public String getLocalizedString(final Locale locale) {
  try {
    final String path = LocalizedFormats.class.getName().replaceAll("\\.", "/");
    ResourceBundle bundle =
        ResourceBundle.getBundle("assets/" + path, locale);
    if (bundle.getLocale().getLanguage().equals(locale.getLanguage())) {
      // the value of the resource is the translated format
      return bundle.getString(toString());
    }
  } catch (MissingResourceException mre) { // NOPMD
    // do nothing here
  }
  // either the locale is not supported or the resource is unknown
  // don't translate and fall back to using the source format
  return sourceFormat;
}

代码示例来源:origin: chanjarster/weixin-java-tools

Locale bundleLocale = bundle.getLocale();
if (bundleLocale.equals(Locale.ROOT)) {
  this.locale = Locale.ENGLISH;

代码示例来源:origin: GlowstoneMC/Glowstone

@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args)
    throws IllegalArgumentException {
  if (args.length == 1) {
    return GameModeUtils.partialMatchingGameModes(args[0], getBundle(sender).getLocale());
  } else {
    return Collections.emptyList();
  }
}

代码示例来源:origin: org.freemarker/freemarker

if (format == null) {
  format = new MessageFormat(((ResourceBundle) object).getString(key));
  format.setLocale(getBundle().getLocale());
  formats.put(key, format);

代码示例来源:origin: GlowstoneMC/Glowstone

@Override
  public List<String> tabComplete(CommandSender sender, String alias, String[] args)
      throws IllegalArgumentException {
    if (args.length == 1) {
      return DIFFICULTIES.getAutoCompleteSuggestions(getBundle(sender).getLocale(), args[0]);
    }
    return super.tabComplete(sender, alias, args);
  }
}

代码示例来源:origin: GlowstoneMC/Glowstone

@Override
  public List<String> tabComplete(CommandSender sender, String alias, String[] args)
    throws IllegalArgumentException {
    if (args.length == 1) {
      return GameModeUtils.partialMatchingGameModes(args[0], getBundle(sender).getLocale());
    }
    return super.tabComplete(sender, alias, args);
  }
}

代码示例来源:origin: igniterealtime/Openfire

messageFormat.setLocale(bundle.getLocale());
messageFormat.applyPattern(value);
try {

代码示例来源:origin: RipMeApp/ripme

configSelectLangComboBox.setSelectedItem(rb.getLocale().toString());
configLogLevelCombobox.setSelectedItem(Utils.getConfigString("log.level", "Log level: Debug"));
setLogLevel(configLogLevelCombobox.getSelectedItem().toString());

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

|| (Locale.ROOT.equals(ret.getLocale()) && (!(locales.size() == 1 && locales
      .contains(Locale.ROOT))))) {
Locale nextLocale = control.getFallbackLocale(baseName, targetLocale);

代码示例来源:origin: GlowstoneMC/Glowstone

private void updateGameMode(
    CommandSender sender, Player who, GameMode gameMode, ResourceBundle bundle) {
  String gameModeName = GameModeUtils.prettyPrint(gameMode, bundle.getLocale());
  who.setGameMode(gameMode);
  if (!sender.equals(who)) {
    new LocalizedStringImpl("gamemode.done", bundle)
        .send(sender, who.getDisplayName(), gameModeName);
    bundle = getBundle(who); // switch to target's locale for gamemode.done.to-you
  }
  new LocalizedStringImpl("gamemode.done.to-you", bundle).send(who, gameModeName);
}

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

public byte[] graph(Range range, int width, int height, boolean maxHidden) throws IOException {
  // static init of the AppContext ClassLoader
  AppContextClassLoaderLeakPrevention.dummy();
  try {
    // Rq : il pourrait être envisagé de récupérer les données dans les fichiers rrd ou autre stockage
    // puis de faire des courbes en sparklines html (écrites dans la page html) ou jfreechart
    // create common part of graph definition
    final RrdGraphDef graphDef = new RrdGraphDef();
    if (Locale.CHINESE.getLanguage()
        .equals(I18N.getResourceBundle().getLocale().getLanguage())) {
      graphDef.setSmallFont(new Font(Font.MONOSPACED, Font.PLAIN, 10));
      graphDef.setLargeFont(new Font(Font.MONOSPACED, Font.BOLD, 12));
    }
    initGraphSource(graphDef, height, maxHidden, range);
    initGraphPeriodAndSize(range, width, height, graphDef);
    graphDef.setImageFormat("png");
    graphDef.setFilename("-");
    // il faut utiliser le pool pour les performances
    // et pour éviter des erreurs d'accès concurrents sur les fichiers
    // entre différentes générations de graphs et aussi avec l'écriture des données
    graphDef.setPoolUsed(true);
    return new RrdGraph(graphDef).getRrdGraphInfo().getBytes();
  } catch (final RrdException e) {
    throw createIOException(e);
  }
}

代码示例来源:origin: GlowstoneMC/Glowstone

public CommandMessages(ResourceBundle bundle, String description,
    String usageMessage, String permissionMessage) {
  this(bundle.getLocale(), bundle, description, usageMessage, permissionMessage,
      new LocalizedStringImpl(NO_SUCH_PLAYER, bundle),
      new LocalizedStringImpl(NAN, bundle),
      new LocalizedStringImpl(OFFLINE, bundle),
      new LocalizedStringImpl(NO_MATCHES, bundle),
      new LocalizedStringImpl(NOT_PHYSICAL, bundle),
      new LocalizedStringImpl(JOINER, bundle).get());
}

代码示例来源:origin: com.liferay.portal/com.liferay.portal.kernel

@Override
public Locale getLocale() {
  for (ResourceBundle resourceBundle : _resourceBundles) {
    Locale locale = resourceBundle.getLocale();
    if (locale != null) {
      return locale;
    }
  }
  return super.getLocale();
}

代码示例来源:origin: ron190/jsql-injection

public static Locale getLocaleDefault() {
  return I18n.localeDefault.getLocale();
}

代码示例来源:origin: com.liferay.portal/com.liferay.portal.kernel

public static String getString(
  ResourceBundle resourceBundle, String key, Object... arguments) {
  String value = getString(resourceBundle, key);
  if (value == null) {
    return null;
  }
  // Get the value associated with the specified key, and substitute any
  // arguments like {0}, {1}, {2}, etc. with the specified argument
  // values.
  if (ArrayUtil.isNotEmpty(arguments)) {
    MessageFormat messageFormat = new MessageFormat(
      value, resourceBundle.getLocale());
    value = messageFormat.format(arguments);
  }
  return value;
}

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

/**
 * Gets the locale for the given log record from the resource bundle.
 * If the resource bundle is using the root locale then the default locale
 * is returned.
 * @param r the log record.
 * @return null if not localized otherwise, the locale of the record.
 * @since JavaMail 1.4.5
 */
private Locale localeFor(final LogRecord r) {
  Locale l;
  final ResourceBundle rb = r.getResourceBundle();
  if (rb != null) {
    l = rb.getLocale();
    if (l == null || isEmpty(l.getLanguage())) {
      //The language of the fallback bundle (root) is unknown.
      //1. Use default locale.  Should only be wrong if the app is
      //   used with a langauge that was unintended. (unlikely)
      //2. Mark it as not localized (force null, info loss).
      //3. Use the bundle name (encoded) as an experimental language.
      l = Locale.getDefault();
    }
  } else {
    l = null;
  }
  return l;
}

代码示例来源:origin: com.sun.mail/javax.mail

/**
 * Gets the locale for the given log record from the resource bundle.
 * If the resource bundle is using the root locale then the default locale
 * is returned.
 * @param r the log record.
 * @return null if not localized otherwise, the locale of the record.
 * @since JavaMail 1.4.5
 */
private Locale localeFor(final LogRecord r) {
  Locale l;
  final ResourceBundle rb = r.getResourceBundle();
  if (rb != null) {
    l = rb.getLocale();
    if (l == null || isEmpty(l.getLanguage())) {
      //The language of the fallback bundle (root) is unknown.
      //1. Use default locale.  Should only be wrong if the app is
      //   used with a langauge that was unintended. (unlikely)
      //2. Mark it as not localized (force null, info loss).
      //3. Use the bundle name (encoded) as an experimental language.
      l = Locale.getDefault();
    }
  } else {
    l = null;
  }
  return l;
}

相关文章