public static String format(String message, Object... args) { return format(message, null, args); } }
private String formatMessage(final String message) { long howMany = valueContext.current().value().map(SelectedItems::stream).map(Stream::count).orElse(0L); return MessageFormatterUtils.format(message, howMany, howMany); } }
/** * @deprecated since 5.4.4. Use {@link #get(String, java.util.List)} instead. */ @Deprecated public String get(String key, List args, String basename) { final String translation = translationService.translate(localeProvider, basename, new String[]{key}); Object[] argsArray = new Object[args.size()]; return MessageFormatterUtils.format(translation, localeProvider.getLocale(), args.toArray(argsArray)); }
public String get(String key, List args) { Object[] argsArray = new Object[args.size()]; return MessageFormatterUtils.format(this.get(key), localeProvider.getLocale(), args.toArray(argsArray)); }
public String translate(String key, Object... args) { final String msg = translationService.translate(localeProvider, new String[]{key}); if (args.length > 0) { return MessageFormatterUtils.format(msg, localeProvider.getLocale(), args); } else { return msg; } } }
@Test public void validMessageWithDoubledSingleQuote() { // GIVEN // WHEN String s = MessageFormatterUtils.format("There''{0,choice,0#re no files|1#s one file|1<re {0} files}.", Locale.ENGLISH, 3); // THEN assertEquals("There're 3 files.", s); }
@Test public void invalidMessageWithDoubledSingleQuoteAfterChoice() { // GIVEN // WHEN String s = MessageFormatterUtils.format("There{0,choice,0#''re no files|1# is one file|1< are {0,choice,2# many|3# more than many} files}.", 0); // THEN // should not throw IllegalArgumentException assertEquals("There{0,choice,0#''re no files|1# is one file|1< are {0,choice,2# many|3# more than many} files}.", s); }
@Test public void invalidMessageWithSingleQuotes() { // GIVEN // WHEN String s = MessageFormatterUtils.format("ab {0'}' cd", 0); // THEN // should not throw IllegalArgumentException assertEquals("ab {0'}' cd", s); }