silverstripe/silverstripe-framework — pull request #3180 by colymba (2014-06-01 17:36:37+00:00)
Title: API New JS sprintf and inject replacement functions

Working with some JS translations I had issues with the current `sprintf` function where the resulting translation would be garbled.

Example:
Source string: `%s at Start and %s at finish via %%s`
Expected: `5 at Strat and 6 at finish via %%s`
sprintf output: `s at Start and 5 at finish via %6`

This happens every time a replacement is at the start of the string. Which is quite often I would imagine.

This PR rewrites the current `sprintf` function with Regex which fixes those strange behaviours. Also escaped %%s are not replace any more.

Also introduced is a new `inject` function that hopefully would replace `sprintf` overtime. Basically a JS implementation of how the current injection works in the PHP i18n class. Substitutions are marked with variables `{var}` and the replacements are taken from an object passed as argument `{var: 8}`.