JS ngettext: fix sprintf() like string format
This commit is contained in:
parent
882ba3b672
commit
71eaf6367c
1 changed files with 13 additions and 5 deletions
|
@ -4,13 +4,18 @@
|
|||
var translations;
|
||||
var translations_data;
|
||||
|
||||
function _(string, ...extra_args) {
|
||||
function ___(string) {
|
||||
return string;
|
||||
}
|
||||
|
||||
function gettext(string, ...extra_args) {
|
||||
var translated = translations ? translations.gettext(string) : string;
|
||||
translated = translated !== "" ? translated : string;
|
||||
if (extra_args)
|
||||
translated = translated.replace(/%[sd]/g, () => extra_args.shift());
|
||||
return translated;
|
||||
}
|
||||
_ = gettext;
|
||||
|
||||
function ngettext(singular, plural, n, ...extra_args) {
|
||||
var translated = translations
|
||||
|
@ -24,8 +29,11 @@ function ngettext(singular, plural, n, ...extra_args) {
|
|||
}
|
||||
|
||||
$(document).ready(function () {
|
||||
// Load Gettext translations
|
||||
translations = babel.Translations.load(
|
||||
translations_data ? translations_data : {}
|
||||
).install();
|
||||
/**
|
||||
* Load Gettext translations
|
||||
*
|
||||
* Note: do not use babel.Translations.install() method to allow customization of gettext's
|
||||
* methods and support of sprintf() like string format.
|
||||
*/
|
||||
translations = babel.Translations.load(translations_data ?? {});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue