1/** 2 * DESCRIPTION: 3 * get translated texts based on an external json file 4 * 5 * USAGE: 6 * // when needed. this is quick. 7 * var translation = new Translation(); 8 * var translatedText = translation.get("label.core.search") 9 * //with parameter if first key not found 10 * var translatedText = translation.getDefault({key: "label.core.search", alt: "label.core.search_alternate_key"}) 11 * 12 * //with Parameter 13 * var translatedText = translation.get("label.core.search", ['45', '100']) 14 * //with parameter if first key not found 15 * var translatedText = translation.getDefault({key: "label.core.search", alt: "label.core.search_alternate_key"}, ["foo", "bar"]) 16 */ 17 18function Translation() { 19} 20 21Translation.prototype.fillmsgwithparams = function (message, paramArray) { 22 var usedmessage = message; 23 if (paramArray && paramArray.length > 0) { 24 for (var i = 0; i < paramArray.length; i++) { 25 //search for {0} or {1} or ... and replace it with the values from the array 26 var regExString = new RegExp("\\{" + i + "\\}", "g"); 27 usedmessage = usedmessage.replace(regExString, paramArray[i]); 28 } 29 } 30 return usedmessage; 31}; 32 33Translation.prototype.getvalue = function (key) { 34 var translated = PEGASOS_TEXTS[key]; 35 36 if ((typeof(translated) === "undefined" && ('PEGASOS_TEXTS_DEFAULT' in window)) || ($("#showECDEVMessages").length > 0)) { 37 // try default 38 translated = PEGASOS_TEXTS_DEFAULT[key]; 39 } 40 41 if ($("#showMessageKeys").length > 0) { 42 return key + "@js"; 43 } 44 45 return translated; 46}; 47 48Translation.prototype.generatemessage = function (key, alt, paramArray) { 49 50 /* CK this happens if resources.js is not loaded quick enough */ 51 if (!('PEGASOS_TEXTS' in window)) { 52 return "== NOT INITIALISED: " + key + "@js =="; 53 } 54 55 var translated = Translation.prototype.getvalue(key); 56 if (typeof(translated) === "undefined" && typeof(alt) !== "undefined") { 57 translated = Translation.prototype.getvalue(alt); 58 } 59 60 if (typeof(translated) === "undefined") { 61 translated = "== MISSING KEY: " + key + "@js =="; 62 LOG.warn(translated); 63 if (typeof(alt) !== "undefined") { 64 LOG.warn("== MISSING KEY: " + alt + "@js =="); 65 } 66 return translated; 67 } 68 69 translated = Translation.prototype.fillmsgwithparams(translated, paramArray); 70 return translated; 71}; 72 73Translation.prototype.get = function (key, paramArray) { 74 return Translation.prototype.generatemessage(key, undefined, paramArray); 75}; 76 77Translation.prototype.getDefault = function (keys, paramArray) { 78 return Translation.prototype.generatemessage(keys.key, keys.alt, paramArray); 79};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.