Class TextFormatter
TextFormatter is used by I18NBundle to perform argument replacement.-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
TextFormatter
-
-
Method Details
-
format
Formats the givenpatternreplacing its placeholders with the actual arguments specified byargs.If this
TextFormatterhas been instantiated withTextFormatter(locale, true)MessageFormatis used to process the pattern, meaning that the actual arguments are properly localized with the locale of thisTextFormatter.On the contrary, if this
TextFormatterhas been instantiated withTextFormatter(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 fromargsconverted to a string withtoString(), 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
MessageFormatpatterns 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 withTextFormattersingle quotes never need to be escaped!- Parameters:
pattern- the patternargs- the arguments- Returns:
- the formatted pattern
- Throws:
IllegalArgumentException- if the pattern is invalid
-