File size: 1,301 Bytes
ae01f49 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | /////////////////////////////////////////////////////////////
//
// pgAdmin 4 - PostgreSQL Tools
//
// Copyright (C) 2013 - 2024, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
//////////////////////////////////////////////////////////////
define(['translations'], function (translations) {
/***
* This method behaves as a drop-in replacement for flask translation rendering.
* It uses the same translation file under the hood and uses flask to determine the language.
* It is slightly tweaked to work like sprintf
* ex. translate("some %s text", "cool")
*
* @param {String} text
*/
return function gettext(text) {
let rawTranslation = translations[text] ? translations[text] : text;
if(arguments.length == 1) {
return rawTranslation;
}
try {
let replaceArgs = arguments;
return rawTranslation.split('%s')
.map(function(w, i) {
if(i > 0) {
if(i < replaceArgs.length) {
return [replaceArgs[i], w].join('');
} else {
return ['%s', w].join('');
}
} else {
return w;
}
})
.join('');
} catch(e) {
console.error(e);
return rawTranslation;
}
};
});
|