1/** 2 * Translation tool 3 */ 4(function (global) { 5 6 function extend(destination, source) { 7 8 if (!destination || !source) return destination; 9 10 for (var field in source) { 11 if (destination[field] === source[field]) continue; 12 destination[field] = source[field]; 13 } 14 15 return destination; 16 } 17 18 19 var i18n = { 20 21 __data: {}, 22 23 register: function (key, data) { 24 25 switch (arguments.length) { 26 case 1: 27 extend(this.__data, key); 28 break; 29 case 2: 30 this.__data[key] = data; 31 break; 32 } 33 }, 34 get: function (key) { 35 36 var args = arguments.length == 1 ? [] : Array.prototype.slice.call(arguments, 1); 37 38 if (!this.__data[key]) { 39 return this.printf(key, args); 40 } 41 42 return this.printf(String(this.__data[key]), args); 43 }, 44 45 key: function (key) { 46 return this.__data[key] ? this.__data[key] : null; 47 }, 48 49 printf: function () { 50 // From: http://phpjs.org/functions 51 // + original by: Ash Searle (http://hexmen.com/blog/) 52 // + namespaced by: Michael White (http://getsprink.com) 53 // + tweaked by: Jack 54 // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) 55 // + input by: Paulo Freitas 56 // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) 57 // + input by: Brett Zamir (http://brett-zamir.me) 58 // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) 59 // + improved by: Dj 60 // + improved by: Allidylls 61 // * example 1: sprintf("%01.2f", 123.1); 62 // * returns 1: 123.10 63 // * example 2: sprintf("[%10s]", 'monkey'); 64 // * returns 2: '[ monkey]' 65 // * example 3: sprintf("[%'#10s]", 'monkey'); 66 // * returns 3: '[####monkey]' 67 // * example 4: sprintf("%d", 123456789012345); 68 // * returns 4: '123456789012345' 69 var regex = /%%|%(\d+\$)?([-+\'#0 ]*)(\*\d+\$|\*|\d+)?(\.(\*\d+\$|\*|\d+))?([scboxXuideEfFgG])/g; 70 var a = arguments, 71 i = 0, 72 format = a[i++]; 73 74 // pad() 75 var pad = function (str, len, chr, leftJustify) { 76 if (!chr) { 77 chr = ' '; 78 } 79 var padding = (str.length >= len) ? '' : Array(1 + len - str.length >>> 0).join(chr); 80 return leftJustify ? str + padding : padding + str; 81 }; 82 83 // justify() 84 var justify = function (value, prefix, leftJustify, minWidth, zeroPad, customPadChar) { 85 var diff = minWidth - value.length; 86 if (diff > 0) { 87 if (leftJustify || !zeroPad) { 88 value = pad(value, minWidth, customPadChar, leftJustify); 89 } else { 90 value = value.slice(0, prefix.length) + pad('', diff, '0', true) + value.slice(prefix.length); 91 } 92 } 93 return value; 94 }; 95 96 // formatBaseX() 97 var formatBaseX = function (value, base, prefix, leftJustify, minWidth, precision, zeroPad) { 98 // Note: casts negative numbers to positive ones 99 var number = value >>> 0; 100 prefix = prefix && number && { 101 '2': '0b', 102 '8': '0', 103 '16': '0x' 104 }[base] || ''; 105 value = prefix + pad(number.toString(base), precision || 0, '0', false); 106 return justify(value, prefix, leftJustify, minWidth, zeroPad); 107 }; 108 109 // formatString() 110 var formatString = function (value, leftJustify, minWidth, precision, zeroPad, customPadChar) { 111 if (precision != null) { 112 value = value.slice(0, precision); 113 } 114 return justify(value, '', leftJustify, minWidth, zeroPad, customPadChar); 115 }; 116 117 // doFormat() 118 var doFormat = function (substring, valueIndex, flags, minWidth, _, precision, type) { 119 var number; 120 var prefix; 121 var method; 122 var textTransform; 123 var value; 124 125 if (substring === '%%') { 126 return '%'; 127 } 128 129 // parse flags 130 var leftJustify = false, 131 positivePrefix = '', 132 zeroPad = false, 133 prefixBaseX = false, 134 customPadChar = ' '; 135 var flagsl = flags.length; 136 for (var j = 0; flags && j < flagsl; j++) { 137 switch (flags.charAt(j)) { 138 case ' ': 139 positivePrefix = ' '; 140 break; 141 case '+': 142 positivePrefix = '+'; 143 break; 144 case '-': 145 leftJustify = true; 146 break;
vendor: 3,960 bytes, lines 147-255
147 case "'": 148 customPadChar = flags.charAt(j + 1); 149 break; 150 case '0': 151 zeroPad = true; 152 break; 153 case '#': 154 prefixBaseX = true; 155 break; 156 } 157 } 158 159 // parameters may be null, undefined, empty-string or real valued 160 // we want to ignore null, undefined and empty-string values 161 if (!minWidth) { 162 minWidth = 0; 163 } else if (minWidth === '*') { 164 minWidth = +a[i++]; 165 } else if (minWidth.charAt(0) == '*') { 166 minWidth = +a[minWidth.slice(1, -1)]; 167 } else { 168 minWidth = +minWidth; 169 } 170 171 // Note: undocumented perl feature: 172 if (minWidth < 0) { 173 minWidth = -minWidth; 174 leftJustify = true; 175 } 176 177 if (!isFinite(minWidth)) { 178 throw new Error('sprintf: (minimum-)width must be finite'); 179 } 180 181 if (!precision) { 182 precision = 'fFeE'.indexOf(type) > -1 ? 6 : (type === 'd') ? 0 : undefined; 183 } else if (precision === '*') { 184 precision = +a[i++]; 185 } else if (precision.charAt(0) == '*') { 186 precision = +a[precision.slice(1, -1)]; 187 } else { 188 precision = +precision; 189 } 190 191 // grab value using valueIndex if required? 192 value = valueIndex ? a[valueIndex.slice(0, -1)] : a[i++]; 193 194 switch (type) { 195 case 's': 196 return formatString(String(value), leftJustify, minWidth, precision, zeroPad, customPadChar); 197 case 'c': 198 return formatString(String.fromCharCode(+value), leftJustify, minWidth, precision, zeroPad); 199 case 'b': 200 return formatBaseX(value, 2, prefixBaseX, leftJustify, minWidth, precision, zeroPad); 201 case 'o': 202 return formatBaseX(value, 8, prefixBaseX, leftJustify, minWidth, precision, zeroPad); 203 case 'x': 204 return formatBaseX(value, 16, prefixBaseX, leftJustify, minWidth, precision, zeroPad); 205 case 'X': 206 return formatBaseX(value, 16, prefixBaseX, leftJustify, minWidth, precision, zeroPad).toUpperCase(); 207 case 'u': 208 return formatBaseX(value, 10, prefixBaseX, leftJustify, minWidth, precision, zeroPad); 209 case 'i': 210 case 'd': 211 number = +value || 0; 212 number = Math.round(number - number % 1); // Plain Math.round doesn't just truncate 213 prefix = number < 0 ? '-' : positivePrefix; 214 value = prefix + pad(String(Math.abs(number)), precision, '0', false); 215 return justify(value, prefix, leftJustify, minWidth, zeroPad); 216 case 'e': 217 case 'E': 218 case 'f': // Should handle locales (as per setlocale) 219 case 'F': 220 case 'g': 221 case 'G': 222 number = +value; 223 prefix = number < 0 ? '-' : positivePrefix; 224 method = ['toExponential', 'toFixed', 'toPrecision']['efg'.indexOf(type.toLowerCase())]; 225 textTransform = ['toString', 'toUpperCase']['eEfFgG'.indexOf(type) % 2]; 226 value = prefix + Math.abs(number)[method](precision); 227 return justify(value, prefix, leftJustify, minWidth, zeroPad)[textTransform](); 228 default: 229 return substring; 230 } 231 }; 232 233 return format.replace(regex, doFormat); 234 } 235 236 }; 237 238 // AMD support 239 if (typeof define === 'function' && define.amd) { 240 define(function () { return i18n; }); 241 242 // CommonJS and Node.js module support. 243 } else if (typeof exports !== 'undefined') { 244 // Support Node.js specific `module.exports` (which can be a function) 245 if (typeof module != 'undefined' && module.exports) { 246 exports = module.exports = i18n; 247 } 248 // But always support CommonJS module 1.1.1 spec (`exports` cannot be a function) 249 exports.i18n = i18n; 250 } else { 251 // browser client 252 window.i18n = i18n; 253 } 254 255})(window);
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.