2019-01-02 10:24:12 +00:00
|
|
|
/////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// pgAdmin 4 - PostgreSQL Tools
|
|
|
|
//
|
2021-01-04 10:04:45 +00:00
|
|
|
// Copyright (C) 2013 - 2021, The pgAdmin Development Team
|
2019-01-02 10:24:12 +00:00
|
|
|
// This software is released under the PostgreSQL Licence
|
|
|
|
//
|
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
|
2018-01-12 07:29:51 +00:00
|
|
|
define(['translations'], function (translations) {
|
2017-03-15 17:10:22 +00:00
|
|
|
|
|
|
|
/***
|
|
|
|
* 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.
|
2019-10-10 06:35:28 +00:00
|
|
|
* It is slightly tweaked to work like sprintf
|
|
|
|
* ex. translate("some %s text", "cool")
|
2017-03-15 17:10:22 +00:00
|
|
|
*
|
|
|
|
* @param {String} text
|
|
|
|
*/
|
2019-10-10 06:35:28 +00:00
|
|
|
return function gettext(text) {
|
2017-03-15 17:10:22 +00:00
|
|
|
|
|
|
|
var rawTranslation = translations[text] ? translations[text] : text;
|
|
|
|
|
2019-10-10 06:35:28 +00:00
|
|
|
if(arguments.length == 1) {
|
|
|
|
return rawTranslation;
|
|
|
|
}
|
2017-03-15 17:10:22 +00:00
|
|
|
|
2019-10-10 06:35:28 +00:00
|
|
|
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;
|
|
|
|
}
|
2017-03-15 17:10:22 +00:00
|
|
|
};
|
2019-10-10 06:35:28 +00:00
|
|
|
});
|