final long secSoFar = ((currentTime - startTime) / 1000); if (secSoFar > 0) { progress = timeWords(secSoFar) + " ${so_far}"; final long secRemaining = (fraction > 0) ? (long) ((1.0 / fraction - 1.0) * secSoFar) : 0; if (secRemaining > 0) { final String remaining = timeWords(secRemaining) + " ${remaining}"; if (progress.length() > 0) { progress = remaining + ", " + progress; progress = NL + " " + progress + ", " + timeWords(total) + " ${total}"; progress = NL + " ${Finished_in} " + timeWords(total) + " ${total}"; String message = " ${progress}: " + percent + "% ${complete_at} " + (new Date()) + progress; message = Localize.filter(message, LogMonitor.class); return message;
/** * Construct for localized messages. * * @param clazz Name of client class that requires localization * @param resourceBundleName Name of ResourceBundle to be used for * localizing messages. If null, then Class<Foo> is assumed to have * property files Foo.properties, Foo_es.properties, etc. * @param locale Locale to use for localization. If null, then will use * default Locale. */ public Localize(final Class<?> clazz, final String resourceBundleName, final Locale locale) { this.clazz = clazz; this.resourceBundleName = resourceBundleName; resourceBundle = getResourceBundle(clazz, resourceBundleName, locale); this.locale = locale; }
/** * Get the best localized message from a Throwable that may contain other Throwables as a cause. * * @param throwable a Throwable that may contain other Throwables as a cause. * @return best localized message, unwrapping as necessary. */ public static String getMessage(final Throwable throwable) { if (throwable.getCause() == null) { final String localizedMessage = throwable.getLocalizedMessage(); if (localizedMessage != null) { return localizedMessage; } final String message = throwable.getMessage(); if (message != null) { return message; } return throwable.toString(); } final String causeToString = throwable.getCause().toString(); final String localized = throwable.getLocalizedMessage(); if (localized == null || localized.equals(causeToString)) { return getMessage(throwable.getCause()); } return localized; }
final Localize dfault = new Localize(LocalizeTest.class); final String sDefault = dfault.format("msg1", 3.14, 42); assert "A number 3.14000 here, and another #42".equals(sDefault) : sDefault; final Localize fr = new Localize(LocalizeTest.class, null, Locale.FRENCH); final int i = 42; final String sFr = fr.format("msg1", 3.14, i); assert "Un nombre 3,14000 ici, et un autre #42".equals(sFr) || "Un nombre 3.14000 ici, et un autre #42".equals(sFr) : sFr; final Localize alt = new Localize(LocalizeTest.class, "LocalizeTestAlt"); final String s = alt.format("msg1", 3.14, 42); assert "A custom file with number 3.14000, and another #42".equals(s) : s; final Localize alt = new Localize(LocalizeTest.class, "LocalizeTestAlt"); final String s = alt.format("No property just a format with number %g.", 3.14); assert "No property just a format with number 3.14000.".equals(s) : s; final Localize alt = new Localize(LocalizeTest.class, "DoesNotExist"); final String s = alt.format("A number %g.", 3.14); assert "A number 3.14000.".equals(s) : s; final Localize alt = new Localize(LocalizeTest.class); final String s = alt.format("Ignored number.", 3.14); assert "Ignored number.".equals(s);
String words = timeWords(seconds); assert (words.equals("9 minutes 29 seconds")) : words; String words = timeWords(seconds); assert (words.equals("10 minutes")) : words; String words = timeWords(seconds); assert (words.equals("11 minutes")) : words; String words = timeWords(seconds); assert (words.equals("9 hours 29 minutes")) : words; String words = timeWords(seconds); assert (words.equals("9 hours 31 minutes")) : words; String words = timeWords(seconds); assert (words.equals("11 hours")) : words; String words = timeWords(seconds); assert (words.equals("9 days 12 hours")) : words; String words = timeWords(seconds); assert (words.equals("10 days")) : words; String words = timeWords(seconds); assert (words.equals("11 days")) : words; String words = timeWords(seconds); assert (words.equals("2 hours")) : words;
assert "ioe".equals(Localize.getMessage(ioException)); assert "ioe".equals(Localize.getMessage(e)); assert better.equals(Localize.getMessage(e)): Localize.getMessage(e); assert "ioe".equals(Localize.getMessage(e)); assert "foo".equals(Localize.getMessage(e)); assert "foo".equals(Localize.getMessage(e)); assert "java.lang.IllegalArgumentException".equals(Localize.getMessage(e)) :Localize.getMessage(e); assert "java.lang.IllegalArgumentException".equals(Localize.getMessage(e)) :Localize.getMessage(e);
currentLocale+" from "+cl); return filter(message, catalog);
message = Localize.filter(message, record.getResourceBundle());