JS translations: allow simple string formatting
This commit is contained in:
parent
da317d85d0
commit
6a0bb16517
1 changed files with 10 additions and 4 deletions
|
@ -4,17 +4,23 @@
|
||||||
var translations;
|
var translations;
|
||||||
var translations_data;
|
var translations_data;
|
||||||
|
|
||||||
function _(string) {
|
function _(string, ...extra_args) {
|
||||||
var translated = translations ? translations.gettext(string) : string;
|
var translated = translations ? translations.gettext(string) : string;
|
||||||
return translated !== "" ? translated : string;
|
translated = translated !== "" ? translated : string;
|
||||||
|
if (extra_args)
|
||||||
|
translated = translated.replace(/%[sd]/g, () => extra_args.shift());
|
||||||
|
return translated;
|
||||||
}
|
}
|
||||||
|
|
||||||
function ngettext(singular, plural, n) {
|
function ngettext(singular, plural, n, ...extra_args) {
|
||||||
return translations
|
var translated = translations
|
||||||
? translations.ngettext(singular, plural, n)
|
? translations.ngettext(singular, plural, n)
|
||||||
: n > 1
|
: n > 1
|
||||||
? plural
|
? plural
|
||||||
: singular;
|
: singular;
|
||||||
|
if (extra_args)
|
||||||
|
translated = translated.replace(/%[sd]/g, () => extra_args.shift());
|
||||||
|
return translated;
|
||||||
}
|
}
|
||||||
|
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
|
|
Loading…
Reference in a new issue