/** * 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; } }
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; }
/** * 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); }
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; }
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 }
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
/** * 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); }
/** * 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); }
/** * 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; }
/** 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 } }
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; }