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

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

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

ResourceBundle.getString介绍

[英]Returns the named string resource from this ResourceBundle.
[中]返回此ResourceBundle中的命名字符串资源。

代码示例

代码示例来源:origin: lets-blade/blade

public String format(String key,String ... params) {
    return MessageFormat.format(resourceBundle.getString(key),params);
  }
}

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

/**
 * Gets a human readable message for the given Win32 error code.
 *
 * @return
 *      null if no such message is available.
 */
@CheckForNull
public static String getWin32ErrorMessage(int n) {
  try {
    ResourceBundle rb = ResourceBundle.getBundle("/hudson/win32errors");
    return rb.getString("error"+n);
  } catch (MissingResourceException e) {
    LOGGER.log(Level.WARNING,"Failed to find resource bundle",e);
    return null;
  }
}

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

/** Display name for the paste action. This should be
* presented as an item in a menu.
*
* @return the name of the action
*/
public String getName() {
  return NbBundle.getBundle(PasteType.class).getString("Paste");
}

代码示例来源:origin: javax.xml.bind/jaxb-api

/** Loads a string resource and formats it with specified arguments. */
static String format( String property, Object[] args ) {
  String text = ResourceBundle.getBundle(Messages.class.getName()).getString(property);
  return MessageFormat.format(text,args);
}

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

public final List<AbstractPatternRule> getRules(InputStream stream,
  Language textLanguage, Language motherTongue)
  throws ParserConfigurationException, SAXException, IOException {
 FalseFriendRuleHandler handler = new FalseFriendRuleHandler(
   textLanguage, motherTongue);
 SAXParserFactory factory = SAXParserFactory.newInstance();
 SAXParser saxParser = factory.newSAXParser();
 saxParser.getXMLReader().setFeature(
     "http://apache.org/xml/features/nonvalidating/load-external-dtd",
     false);
 saxParser.parse(stream, handler);
 List<AbstractPatternRule> rules = handler.getRules();
 // Add suggestions to each rule:
 ResourceBundle messages = ResourceBundle.getBundle(
     JLanguageTool.MESSAGE_BUNDLE, motherTongue.getLocale());
 MessageFormat msgFormat = new MessageFormat(messages.getString("false_friend_suggestion"));
 for (AbstractPatternRule rule : rules) {
  List<String> suggestions = handler.getSuggestionMap().get(rule.getId());
  if (suggestions != null) {
   String[] msg = { formatSuggestions(suggestions) };
   rule.setMessage(rule.getMessage() + " " + msgFormat.format(msg));
  }
 }
 return rules;
}

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

String getRequestByName(String requestName) {
  return ResourceBundle.getBundle(RESOURCE_BUNDLE_BASE_NAME).getString(requestName);
}

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

/**
 * Translate a text string based on our i18n files.
 * @since 3.1
 */
public static String i18n(ResourceBundle messages, String key, Object... messageArguments) {
 MessageFormat formatter = new MessageFormat("");
 formatter.applyPattern(messages.getString(key).replaceAll("'", "''"));
 return formatter.format(messageArguments);
}

代码示例来源:origin: org.marketcetera.fork/commons-i18n

public String getText(String id, String entry, Locale locale) throws MessageNotFoundException {
  try
  {
   ResourceBundle resourceBundle = this.classLoader == null ? ResourceBundle.getBundle(this.baseName, locale) : ResourceBundle.getBundle(this.baseName, locale, this.classLoader);
   
   return resourceBundle.getObject(id + "." + entry).toString();
  }
  catch (MissingResourceException e)
  {
   logger.log(Level.WARNING, MessageFormat.format(I18nUtils.INTERNAL_MESSAGES.getString("noMessageEntriesFound"), new String[] { id }));
  }
  return null;
}

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

private final String annotateName(FileObject fo) {
  String bundleName = (String) fo.getAttribute("SystemFileSystem.localizingBundle"); // NOI18N
  if (bundleName != null) {
    try {
      bundleName = Utilities.translate(bundleName);
      ResourceBundle b = NbBundle.getBundle(bundleName);
      try {
        return b.getString(fo.getPath());
      } catch (MissingResourceException ex) {
        // ignore--normal
      }
    } catch (MissingResourceException ex) {
      Exceptions.attachMessage(ex, warningMessage(bundleName, fo));
      LOG.log(Level.INFO, null, ex);
      // ignore
    }
  }
  return (String) fo.getAttribute("displayName"); // NOI18N
}

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

private void initAccessible() {
  if (nameFormat == null) {
    ResourceBundle bundle = NbBundle.getBundle(SplittedPanel.class);
    nameFormat = new MessageFormat(bundle.getString("ACS_SplittedPanel_Name"));
    nameFormat.format(
      new Object[] {
        ((firstComponent == null) || !(firstComponent instanceof Accessible)) ? null
    ResourceBundle bundle = NbBundle.getBundle(SplittedPanel.class);
    descriptionFormat = new MessageFormat(bundle.getString("ACS_SplittedPanel_Description"));
    descriptionFormat.format(
      new Object[] {
        ((firstComponent == null) || !(firstComponent instanceof Accessible)) ? null

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

if (throwex) {
  throw new IllegalArgumentException(
    MessageFormat.format(
      NbBundle.getBundle(MapFormat.class).getString("MSG_FMT_ObjectForKey"),
      new Object[] { new Integer(key) }

代码示例来源:origin: javax.xml.bind/jaxb-api

/** Loads a string resource and formats it with specified arguments. */
static String format( String property, Object[] args ) {
  String text = ResourceBundle.getBundle(Messages.class.getName()).getString(property);
  return MessageFormat.format(text,args);
}

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

/**
 * Gets the check message 'as is' from appropriate 'messages.properties'
 * file.
 *
 * @param messageBundle the bundle name.
 * @param messageKey the key of message in 'messages.properties' file.
 * @param arguments the arguments of message in 'messages.properties' file.
 * @return The message of the check with the arguments applied.
 */
private static String internalGetCheckMessage(
    String messageBundle, String messageKey, Object... arguments) {
  final ResourceBundle resourceBundle = ResourceBundle.getBundle(
      messageBundle,
      Locale.getDefault(),
      Thread.currentThread().getContextClassLoader(),
      new LocalizedMessage.Utf8Control());
  final String pattern = resourceBundle.getString(messageKey);
  final MessageFormat formatter = new MessageFormat(pattern, Locale.ROOT);
  return formatter.format(arguments);
}

代码示例来源:origin: lets-blade/blade

public String format(String key,String ... params) {
    return MessageFormat.format(resourceBundle.getString(key),params);
  }
}

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

/**
 * Returns the short description of a token for a given name.
 * @param name the name of the token ID to get
 * @return a short description
 */
public static String getShortDescription(String name) {
  if (!TOKEN_NAME_TO_VALUE.containsKey(name)) {
    throw new IllegalArgumentException(TOKEN_NAME_EXCEPTION_PREFIX + name);
  }
  final String tokenTypes =
    "com.puppycrawl.tools.checkstyle.api.tokentypes";
  final ResourceBundle bundle = ResourceBundle.getBundle(tokenTypes, Locale.ROOT);
  return bundle.getString(name);
}

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

/**
 * Gets the translated message.
 * @return the translated message
 */
public String getMessage() {
  String message = getCustomMessage();
  if (message == null) {
    try {
      // Important to use the default class loader, and not the one in
      // the GlobalProperties object. This is because the class loader in
      // the GlobalProperties is specified by the user for resolving
      // custom classes.
      final ResourceBundle resourceBundle = getBundle(bundle);
      final String pattern = resourceBundle.getString(key);
      final MessageFormat formatter = new MessageFormat(pattern, Locale.ROOT);
      message = formatter.format(args);
    }
    catch (final MissingResourceException ignored) {
      // If the Check author didn't provide i18n resource bundles
      // and logs error messages directly, this will return
      // the author's original message
      final MessageFormat formatter = new MessageFormat(key, Locale.ROOT);
      message = formatter.format(args);
    }
  }
  return message;
}

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

/** Initiating the drag */
public void dragGestureRecognized(DragGestureEvent dge) {
  // check allowed actions
  if ((dge.getDragAction() & DnDConstants.ACTION_MOVE) == 0) {
    return;
  }
  // prepare transferable and start the drag
  int index = comp.locationToIndex(dge.getDragOrigin());
  // no index, then no dragging...
  if (index < 0) {
    return;
  }
  //      System.out.println("Starting drag..."); // NOI18N
  // create our flavor for transferring the index
  myFlavor = new DataFlavor(
      String.class, NbBundle.getBundle(IndexedCustomizer.class).getString("IndexedFlavor")
    );
  try {
    dge.startDrag(DragSource.DefaultMoveDrop, new IndexTransferable(myFlavor, index), this);
    // remember the gesture
    this.dge = dge;
  } catch (InvalidDnDOperationException exc) {
    Logger.getLogger(IndexedCustomizer.class.getName()).log(Level.WARNING, null, exc);
    // PENDING notify user - cannot start the drag
  }
}

代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/openide-loaders

public String getDisplayName () {
  if (format == null) {
    format = new MessageFormat (NbBundle.getBundle (DataShadow.class).getString ("FMT_shadowName"));
  }
  String n = format.format (createArguments ());
  try {
    obj.getPrimaryFile().getFileSystem().getStatus().annotateName(n, obj.files());
  } catch (FileStateInvalidException fsie) {
    // ignore
  }
  return n;
}

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

/** Display name for the creation action. This should be
* presented as an item in a menu.
*
* @return the name of the action
*/
public String getName() {
  return NbBundle.getBundle(NewType.class).getString("Create");
}

代码示例来源:origin: javax.xml.bind/jaxb-api

/** Loads a string resource and formats it with specified arguments. */
static String format( String property, Object[] args ) {
  String text = ResourceBundle.getBundle(Messages.class.getName()).getString(property);
  return MessageFormat.format(text,args);
}

相关文章