Add sprintf implementation to JavaScript
Word order differs across languages, so we need a way to pass parameters to translated texts. For example
// bad
_('There are') + `<strong>${num_users}</strong>` + _(' users in ') + `<strong>${project}</strong>.`;
// good
sprintf(_('There are %1$s users in %2$s', [`<strong>${num_users}</strong>`,`<strong>${project}</strong>`]);
// better
sprintf(_('There are %{num_users} users in %{project}', { num_users: `<strong>${num_users}</strong>`, project: `<strong>${project}</strong>` });
We already have Jed.sprintf
available which is an outdated version of sprintf.js.
-
underscore.string will remove
sprintf
in the next major release in favor of sprintf.js - lodash will not add it
- jQuery doesn't seem to have it and we want to get rid of jQuery anyway (https://gitlab.com/gitlab-org/gitlab-ce/issues/23022)
So I suggest we stick with sprintf.js.