Package arc.util

Class TextFormatter

java.lang.Object
arc.util.TextFormatter

public class TextFormatter extends Object
TextFormatter is used by I18NBundle to perform argument replacement.
  • Constructor Details

    • TextFormatter

      public TextFormatter(Locale locale, boolean useMessageFormat)
  • Method Details

    • format

      public String format(String pattern, Object... args)
      Formats the given pattern replacing its placeholders with the actual arguments specified by args.

      If this TextFormatter has been instantiated with TextFormatter(locale, true) MessageFormat is used to process the pattern, meaning that the actual arguments are properly localized with the locale of this TextFormatter.

      On the contrary, if this TextFormatter has been instantiated with TextFormatter(locale, false) pattern's placeholders are expected to be in the simplified form {0}, {1}, {2} and so on and they will be replaced with the corresponding object from args converted to a string with toString(), so without taking into account the locale.

      In both cases, there's only one simple escaping rule, i.e. a left curly bracket must be doubled if you want it to be part of your string.

      It's worth noting that the rules for using single quotes within MessageFormat patterns have shown to be somewhat confusing. In particular, it isn't always obvious to localizers whether single quotes need to be doubled or not. For this very reason we decided to offer the simpler escaping rule above without limiting the expressive power of message format patterns. So, if you're used to MessageFormat's syntax, remember that with TextFormatter single quotes never need to be escaped!

      Parameters:
      pattern - the pattern
      args - the arguments
      Returns:
      the formatted pattern
      Throws:
      IllegalArgumentException - if the pattern is invalid