Closed PeterFokkinga closed 1 month ago
Hi @PeterFokkinga!
Thanks for sharing. However, the way you implemented it would make the usage of localize unsafe in HTML contexts.
There is a whole set of tests for localization, providing some examples, like this one.
At work we explicitly opted out of MessageFormat, to have more control over localizations and don't pay the message format performance penalty. For instance, we have custom localize methods for key lookup of one, some, many keys. Replacing the current implementation with MessageFormat is a no-go, as it would break existing user code.
If you want, you could create your own MessageFormatLocalizationSupport and use that. To be safe, you would need to output escape all String parameters received, before passing them down to MessageFormat.
It would be nice if LocalizationSupport not only expands simple place holders like
{0}
but also the choice format so one can display a text in proper singular or plural form based on a numerical value.Example input:
There {0,choice,0#are no new messages|1#is one new message|1< are {0} new messages} in your inbox
.A possible implementation would be to replace the current regular expression based code with a call to MessageFormat, ie