MCPcopy Index your code
hub / github.com/pgadmin-org/pgadmin4 / gettextForTranslation

Function gettextForTranslation

web/regression/javascript/fake_gettext.js:12–38  ·  view source on GitHub ↗
(translations, ...replaceArgs)

Source from the content-addressed store, hash-verified

10import translations from 'translations';
11
12function gettextForTranslation(translations, ...replaceArgs) {
13 const text = replaceArgs[0];
14 let rawTranslation = translations[text] ? translations[text] : text;
15
16 if(arguments.length == 2) {
17 return rawTranslation;
18 }
19
20 try {
21 return rawTranslation.split('%s')
22 .map(function(w, i) {
23 if(i > 0) {
24 if(i < replaceArgs.length) {
25 return [replaceArgs[i], w].join('');
26 } else {
27 return ['%s', w].join('');
28 }
29 } else {
30 return w;
31 }
32 })
33 .join('');
34 } catch(e) {
35 console.error(e);
36 return rawTranslation;
37 }
38}
39
40export default function gettext(text, ...args) {
41 return gettextForTranslation(translations, text, ...args);

Callers 1

gettextFunction · 0.85

Calls 2

joinMethod · 0.80
errorMethod · 0.80

Tested by

no test coverage detected