2022-04-24 16:46:38 +02:00
|
|
|
/*
|
2024-01-23 19:23:10 +01:00
|
|
|
* I18n
|
|
|
|
*/
|
2022-04-24 16:46:38 +02:00
|
|
|
var translations;
|
2022-04-24 20:17:48 +02:00
|
|
|
var translations_data;
|
2022-04-24 16:46:38 +02:00
|
|
|
|
2024-09-21 18:31:42 +02:00
|
|
|
function _(string, ...extra_args) {
|
2024-01-23 19:23:10 +01:00
|
|
|
var translated = translations ? translations.gettext(string) : string;
|
2024-09-21 18:31:42 +02:00
|
|
|
translated = translated !== "" ? translated : string;
|
|
|
|
if (extra_args)
|
|
|
|
translated = translated.replace(/%[sd]/g, () => extra_args.shift());
|
|
|
|
return translated;
|
2022-04-24 16:46:38 +02:00
|
|
|
}
|
|
|
|
|
2024-09-21 18:31:42 +02:00
|
|
|
function ngettext(singular, plural, n, ...extra_args) {
|
|
|
|
var translated = translations
|
2024-01-23 19:23:10 +01:00
|
|
|
? translations.ngettext(singular, plural, n)
|
|
|
|
: n > 1
|
|
|
|
? plural
|
|
|
|
: singular;
|
2024-09-21 18:31:42 +02:00
|
|
|
if (extra_args)
|
|
|
|
translated = translated.replace(/%[sd]/g, () => extra_args.shift());
|
|
|
|
return translated;
|
2022-04-24 16:46:38 +02:00
|
|
|
}
|
|
|
|
|
2024-01-23 19:23:10 +01:00
|
|
|
$(document).ready(function () {
|
2022-04-24 16:46:38 +02:00
|
|
|
// Load Gettext translations
|
2024-01-23 19:23:10 +01:00
|
|
|
translations = babel.Translations.load(
|
|
|
|
translations_data ? translations_data : {}
|
|
|
|
).install();
|
2022-04-24 16:46:38 +02:00
|
|
|
});
|