Warning, file /frameworks/ki18n/po/sr/scripts/ki18n6/ki18n6.js was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 // kdelibs4.js of Serbian KDE translation 0002 0003 // ------------------------------ 0004 // Property getter object contains the following data attributes: 0005 // - callname: the name of the getter call as exposed to PO files 0006 // - propkey: the key of the property as used in pmap files 0007 // - overrides: dictionary of values of this property for certain phrases, 0008 // which were manually set in the PO file 0009 function Propgetter (callname, propkey) 0010 { 0011 this.callname = callname; 0012 this.propkey = propkey; 0013 this.overrides = {}; 0014 0015 this.getbase = Propgetter_getbase; 0016 0017 this.getprop = Propgetter_getprop; 0018 this.getprop_uc = Propgetter_getprop_uc; 0019 this.getform = Propgetter_getform; 0020 this.getform_uc = Propgetter_getform_uc; 0021 } 0022 0023 // Base of property/form getter methods attached to getter objects. 0024 // First the property for the given phrase is looked up in overrides, 0025 // and then in Transcript property map (read from pmap files). 0026 // If the property is not found, fallback is signalled if retself is false, 0027 // otherwise the phrase itself is returned. 0028 function Propgetter_getbase (phrase, retself) 0029 { 0030 if (phrase in this.overrides) { 0031 return this.overrides[phrase]; 0032 } 0033 else { 0034 var prop = Ts.getProp(phrase, this.propkey) 0035 if (prop != undefined) 0036 return prop; 0037 } 0038 if (retself) { 0039 return phrase; 0040 } 0041 throw Ts.fallback(); 0042 } 0043 0044 // Property getter method attached to getter objects. 0045 function Propgetter_getprop (phrase) 0046 { 0047 return this.getbase(phrase, false); 0048 } 0049 0050 // As previous, but returns the property with the first letter upcased. 0051 function Propgetter_getprop_uc (phrase) 0052 { 0053 var val = this.getprop(phrase); 0054 0055 // The second argument is indicating the number of alternatives per 0056 // alternatives directive -- in case the first letter is within 0057 // an alternatives directive, all alternatives in that directive 0058 // should be processed. 0059 return Ts.toUpperFirst(val, 2); 0060 } 0061 0062 // Form getter method attached to getter objects. 0063 function Propgetter_getform (phrase) 0064 { 0065 return this.getbase(phrase, true); 0066 } 0067 0068 // As previous, but returns the form with the first letter upcased. 0069 function Propgetter_getform_uc (phrase) 0070 { 0071 var val = this.getform(phrase); 0072 // See the comment in Propgetter_getprop_uc(). 0073 return Ts.toUpperFirst(val, 2); 0074 } 0075 0076 // ------------------------------ 0077 // Exposing property getters to PO. 0078 0079 // Contains all global property getters. 0080 var _propgetters_ = {}; 0081 0082 // Set PO calls for given property getter object. 0083 function setcalls_prop (pgetr) 0084 { 0085 // Default call. 0086 Ts.setcall(pgetr.callname, pgetr.getprop, pgetr); 0087 // "Open with $[callname %1]" 0088 0089 // Form call. 0090 Ts.setcall(pgetr.callname + "/ф", pgetr.getform, pgetr); 0091 // "Open with $[callname/ф %1]" 0092 0093 // The calls which capitalize the first letter of the value, 0094 // named as the default calls but with the first letter capitalized. 0095 // Only set if the first letter of the call name is actually lowercase. 0096 callname_uc = Ts.toUpperFirst(pgetr.callname); 0097 if (callname_uc != pgetr.callname) { 0098 Ts.setcall(callname_uc, pgetr.getprop_uc, pgetr); 0099 // "$[Callname %1] starting..." 0100 Ts.setcall(callname_uc + "/ф", pgetr.getform_uc, pgetr); 0101 // "$[Callname/ф %1] starting..." 0102 } 0103 0104 // Record getter objects globally. 0105 // Only for the original name, since the uppercase/form variants are not 0106 // used when properties are being set (when the global store is needed). 0107 _propgetters_[pgetr.callname] = pgetr; 0108 } 0109 0110 // Set property value of phrase. 0111 function setprop (phrase, pkey, pval) 0112 { 0113 // Either create new, or select existing getter. 0114 var pgetr; 0115 if (!_propgetters_[pkey]) { 0116 // Populate new getter if not already defined. 0117 pgetr = new Propgetter(pkey, pkey); 0118 // Expose calls to PO. 0119 setcalls_prop(pgetr); 0120 } 0121 else { 0122 // Get previously defined getter. 0123 pgetr = _propgetters_[pkey]; 0124 } 0125 0126 // Add the property into overrides of selected getter. 0127 pgetr.overrides[phrase] = pval; 0128 } 0129 0130 // Get property value of phrase. 0131 // Signals fallback if the property/phrase combination is not defined. 0132 function getprop (phrase, pkey) 0133 { 0134 if (_propgetters_[pkey]) { 0135 return _propgetters_[pkey].getprop(phrase); 0136 } 0137 throw Ts.fallback(); 0138 } 0139 0140 // Get form of the phrase, or phrase itself if no such form. 0141 function getform (phrase, fkey) 0142 { 0143 if (_propgetters_[fkey]) { 0144 return _propgetters_[fkey].getform(phrase); 0145 } 0146 return phrase; 0147 } 0148 0149 // Returns true if the phrase has the property. 0150 function hasprop (phrase, pkey) 0151 { 0152 pg = _propgetters_[pkey]; 0153 if (!pg) { 0154 return false; 0155 } 0156 if (!pg.overrides[phrase] && !Ts.getProp(phrase, pg.propkey)) { 0157 return false; 0158 } 0159 return true; 0160 } 0161 0162 // ------------------------------ 0163 // Predefined property getters. 0164 0165 // Call names and corresponding keys in pmap for predefined getters. 0166 // The first letter in a call name should be lowercase; for each call 0167 // another call with the first letter in uppercase will be defined, 0168 // which will upcase the first letter in the property value before 0169 // returning it. 0170 var call_name_to_prop = { 0171 // Nouns. 0172 "_изв" : "_izvor", // english original 0173 "_род" : "_rod", // gender 0174 "_број" : "_broj", // number 0175 0176 "ном" : "n", // nominative case 0177 "ген" : "g", // genitive case 0178 "дат" : "d", // dative case 0179 "аку" : "a", // accusative case 0180 "инс" : "i", // instrumental case 0181 "лок" : "l", // locative case 0182 0183 // Expressive variants. 0184 "наредбено" : "_narb", // command 0185 "списковно" : "_spis", // listed 0186 0187 // Adjectives. 0188 "ном-м" : "nm", // nominative, masculine 0189 "ген-м" : "gm", // genitive, masculine 0190 "дат-м" : "dm", // dative, masculine 0191 "аку-м" : "am", // accusative, masculine 0192 "инс-м" : "im", // instrumental, masculine 0193 "лок-м" : "lm", // locative, masculine 0194 "ном-ж" : "nz", // nominative, feminine 0195 "ген-ж" : "gz", // genitive, feminine 0196 "дат-ж" : "dz", // dative, feminine 0197 "аку-ж" : "az", // accusative, feminine 0198 "инс-ж" : "iz", // instrumental, feminine 0199 "лок-ж" : "lz", // locative, feminine 0200 "ном-с" : "ns", // nominative, neuter 0201 "ген-с" : "gs", // genitive, neuter 0202 "дат-с" : "ds", // dative, neuter 0203 "аку-с" : "as", // accusative, neuter 0204 "инс-с" : "is", // instrumental, neuter 0205 "лок-с" : "ls", // locative, neuter 0206 "ном-мк" : "nmk", // nominative, masculine, plural 0207 "ген-мк" : "gmk", // genitive, masculine, plural 0208 "дат-мк" : "dmk", // dative, masculine, plural 0209 "аку-мк" : "amk", // accusative, masculine, plural 0210 "инс-мк" : "imk", // instrumental, masculine, plural 0211 "лок-мк" : "lmk", // locative, masculine, plural 0212 "ном-жк" : "nzk", // nominative, feminine, plural 0213 "ген-жк" : "gzk", // genitive, feminine, plural 0214 "дат-жк" : "dzk", // dative, feminine, plural 0215 "аку-жк" : "azk", // accusative, feminine, plural 0216 "инс-жк" : "izk", // instrumental, feminine, plural 0217 "лок-жк" : "lzk", // locative, feminine, plural 0218 "ном-ск" : "nsk", // nominative, neuter, plural 0219 "ген-ск" : "gsk", // genitive, neuter, plural 0220 "дат-ск" : "dsk", // dative, neuter, plural 0221 "аку-ск" : "ask", // accusative, neuter, plural 0222 "инс-ск" : "isk", // instrumental, neuter, plural 0223 "лок-ск" : "lsk", // locative, neuter, plural 0224 }; 0225 0226 // Create getter objects for predefined getters. 0227 for (cname in call_name_to_prop) { 0228 // Create getter object as defined above. 0229 var pgetr = new Propgetter(cname, call_name_to_prop[cname]); 0230 // Expose calls to PO. 0231 setcalls_prop(pgetr); 0232 } 0233 0234 // Special handling for instrumental case, when used for tool application: 0235 // don't pass it along as-is if same as nominative case of the phrase, 0236 // since the sentence can get very different, yet semantically correct meaning. 0237 // Instead, pass genitive case with the preposition "by the help of". 0238 { 0239 var pgetr = new Propgetter("инс-п", "i"); 0240 0241 // Replace default getter method. 0242 pgetr.getprop = function (phrase) 0243 { 0244 var prop_ins = _propgetters_["инс"].getprop(phrase); 0245 var prop_nom = _propgetters_["ном"].getprop(phrase); 0246 if (prop_ins == prop_nom) { 0247 var prop_gen = _propgetters_["ген"].getprop(phrase); 0248 return "помоћу " + prop_gen; 0249 } 0250 else { 0251 return prop_ins; 0252 } 0253 } 0254 0255 setcalls_prop(pgetr); 0256 } 0257 0258 // ------------------------------ 0259 // Set properties of the given phrase. 0260 // The arguments to the call are the phrase, and a list of as many keys 0261 // followed by their value as desired (i.e. number of elements must be even). 0262 // Keys may also be comma-separated lists instead of a single key, in order 0263 // not to have to repeat the same value when it corresponds to several keys. 0264 // 0265 // The property keys become property getters which can be used to retrive 0266 // the value at a later point. If the getter for a given key already exists, 0267 // the new value is added into its overrides. 0268 // 0269 // Returns undefined. 0270 // 0271 function setprops (phrase, keyvals) 0272 { 0273 if (keyvals.length % 2 != 0) 0274 throw Error("Property setter given odd number of key/value elements."); 0275 0276 for (var i = 0; i < keyvals.length; i += 2) { 0277 // Several keys may be given for a single prop, comma-separated. 0278 var pkeys = keyvals[i].split(","); 0279 var pval = keyvals[i + 1]; 0280 0281 // Set the value to each property key. 0282 for (var j = 0; j < pkeys.length; j += 1) { 0283 setprop(phrase, pkeys[j], pval); 0284 } 0285 } 0286 } 0287 0288 // Manually set properties of the phrase given by the finalized msgstr 0289 // in the PO file and signal fallback. 0290 // For the rest of the behavior, see setprops() 0291 function setprops_msgstrf (/*...*/) 0292 { 0293 if (arguments.length % 2 != 0) 0294 throw Error("Msgstr property setter given odd number of arguments."); 0295 setprops(Ts.msgstrf(), arguments); 0296 throw Ts.fallback(); 0297 } 0298 Ts.setcall("својства", setprops_msgstrf); 0299 // "$[callname prop1 value1 prop2 value2 ...]" 0300 0301 // Manually set properties of the phrase given by the finalized msgstr 0302 // in the PO file and return empty string. 0303 // For the rest of the behavior, see setprops() 0304 function setprops_msgstrf_e (/*...*/) 0305 { 0306 if (arguments.length % 2 != 0) 0307 throw Error("Msgstr property setter given odd number of arguments."); 0308 setprops(Ts.msgstrf(), arguments); 0309 return ""; 0310 } 0311 Ts.setcall("својства/п", setprops_msgstrf_e); 0312 // "$[callname prop1 value1 prop2 value2 ...]" 0313 0314 // ------------------------------ 0315 // Manual plural handling. 0316 // Only first three forms, as the fourth form is most likely not needed 0317 // when the plural needs to be scripted. 0318 // The first argument should be the proper value, not the substitution string 0319 // (i.e. do not call as $[~ %1 ...] but as $[~ ^1 ...]). 0320 function plural3 (n, form0, form1, form2) 0321 { 0322 if (n % 10 == 1 && n % 100 != 11) 0323 return form0; 0324 else if (n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20)) 0325 return form1; 0326 else 0327 return form2; 0328 } 0329 Ts.setcall("множ", plural3); 0330 // "...and %2 $[callname ^2 file fila files]" 0331 0332 // ------------------------------ 0333 // General choice-by-case. 0334 function select_by_case (/* test, case1, choice1, ..., [default_choice] */) 0335 { 0336 if (arguments.length < 1) 0337 throw Error("Choice by case takes at least the test value."); 0338 0339 for (var i = 1; i < arguments.length - 1; i += 2) { 0340 if (arguments[0] == arguments[i]) { 0341 return arguments[i + 1]; 0342 } 0343 } 0344 // No case matched, see if we have a default. 0345 if ((arguments.length - 1) % 2 != 0) { 0346 return arguments[arguments.length - 1]; 0347 } else { 0348 throw Ts.fallback(); 0349 } 0350 } 0351 Ts.setcall("када", select_by_case); 0352 // "Do you want to %1 $[callname %1 open 'this bar' access 'thisu baru']" 0353 0354 // ------------------------------ 0355 // Select one of three forms according to the gender of the phrase. 0356 function select_by_gender (phrase, form_m, form_f, form_n) 0357 { 0358 // Select gender (throws fallback if phrase not found). 0359 var gender = getprop(phrase, "_род"); 0360 0361 if (gender == "м") { 0362 return form_m; 0363 } 0364 else if (gender == "ж") { 0365 return form_f; 0366 } 0367 else if (gender == "с") { 0368 return form_n; 0369 } 0370 else { 0371 throw Ts.fallback(); 0372 } 0373 } 0374 Ts.setcall("по-роду", select_by_gender); 0375 // "Delete $[callname %1 this thisa thiso] %1?" 0376 0377 // ------------------------------ 0378 // Select one of two forms according to the number of the phrase. 0379 function select_by_number (phrase, form_s, form_p) 0380 { 0381 // Select number (default to singular if not found). 0382 var number = "ј"; 0383 if (hasprop(phrase, "_број")) { 0384 number = getprop(phrase, "_број"); 0385 } 0386 0387 if (number == "к") { // plural 0388 return form_p; 0389 } else { 0390 return form_s; 0391 } 0392 } 0393 Ts.setcall("по-броју", select_by_number); 0394 // "%1 $[callname %1 waalks waalk] by the river." 0395 0396 // ------------------------------ 0397 // Select one of six forms according to the gender and number of the phrase. 0398 function select_by_number_gender (phrase, 0399 form_ms, form_fs, form_ns, // singulars 0400 form_mp, form_fp, form_np) // plurals 0401 { 0402 // Select number (default to singular if not found). 0403 var number = "ј"; 0404 if (hasprop(phrase, "_број")) { 0405 number = getprop(phrase, "_број"); 0406 } 0407 0408 if (number == "к") { // plural 0409 return select_by_gender(phrase, form_mp, form_fp, form_np); 0410 } else { 0411 return select_by_gender(phrase, form_ms, form_fs, form_ns); 0412 } 0413 } 0414 Ts.setcall("по-роду-броју", select_by_number_gender); 0415 // "Delete $[callname %1 this thisa thiso thees theesa theeso] %1?" 0416 0417 // ------------------------------ 0418 // Select one the form according to the case and gender of another argument. 0419 function select_by_case_gender (gcase, gphrase, phrase) // plurals 0420 { 0421 var gender = getprop(gphrase, "_род"); 0422 return getprop(phrase, gcase + "-" + gender); 0423 } 0424 Ts.setcall("по-падежу-роду", select_by_case_gender); 0425 // "Delete $[callname case %2 %1] [case %2]?" 0426 0427 // ------------------------------ 0428 // Object to query whether a character is one of expected letters. 0429 letter_arr = ("" 0430 + "абвгдђежзијклљмнњопрстћуфхцчџшАБВГДЂЕЖЗИЈКЛЉМНЊОПРСТЋУФХЦЧЏШ" 0431 + "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" 0432 ).split(""); 0433 letter = {}; 0434 for (var i = 0; i < letter_arr.length; ++i) { 0435 letter[letter_arr[i]] = 1; 0436 } 0437 0438 // ------------------------------ 0439 // Split phrase into words and intersections, 0440 // where words are taken as contiguous segments of letters. 0441 // The return value is a tuple of arrays of words and intersections. 0442 // There is always one more of intersections than words, so that 0443 // the original phrase can be reassembled as 0444 // intrs[0] + words[0] + ... + intrs[n - 2] + words[n - 2] + intrs[n - 1]. 0445 function split_phrase (phrase) 0446 { 0447 intrs = []; 0448 words = []; 0449 0450 var i = 0; 0451 while (i < phrase.length) { 0452 var i1 = i; 0453 while (i1 < phrase.length && !letter[phrase[i1]]) { 0454 ++i1; 0455 } 0456 intrs.push(phrase.substring(i, i1)); 0457 var i2 = i1; 0458 while (i2 < phrase.length && letter[phrase[i2]]) { 0459 ++i2; 0460 } 0461 if (i2 > i1) { 0462 words.push(phrase.substring(i1, i2)); 0463 if (i2 == phrase.length) { 0464 intrs.push(""); 0465 } 0466 } 0467 i = i2; 0468 } 0469 0470 return [words, intrs]; 0471 } 0472 0473 // ------------------------------ 0474 // Apply call to each word in the phrase. 0475 // The call must accept the word as the last argument. 0476 function apply_to_word (/* phrase, callname, ...args before word... */) 0477 { 0478 if (arguments.length < 2) 0479 throw Error("Applicator takes at least the phrase and the call name."); 0480 0481 phrase = arguments[0]; 0482 calln = arguments[1]; 0483 cargs = [calln]; 0484 for (var i = 2; i < arguments.length; ++i) { 0485 cargs.push(arguments[i]); 0486 } 0487 0488 lst = split_phrase(phrase); 0489 words = lst[0]; 0490 intrs = lst[1]; 0491 0492 nwords = []; 0493 for (var i = 0; i < words.length; ++i) { 0494 cargs.push(words[i]); 0495 nwords.push(Ts.acall.apply(Ts, cargs)); 0496 cargs.pop(); 0497 } 0498 0499 str = "" 0500 for (var i = 0; i < nwords.length; ++i) { 0501 str += intrs[i] + nwords[i]; 0502 } 0503 str += intrs[nwords.length]; 0504 0505 return str; 0506 } 0507 Ts.setcall("на-реч", apply_to_word); 0508 // "Repeat until $[callname casecall %1], and on this date..." 0509 0510 // ------------------------------ 0511 // Decline person's name into given case. 0512 // Parse name into first and last name, determine gender according to 0513 // first name, decline according to gender and assemble. 0514 // If name cannot be fully declined, returns original name if retself is true, 0515 // otherwise signals fallback. 0516 // TODO: Just delegates to ordinary getters for the time being. 0517 function decline_person_name_base (gcase, fullname, retself) 0518 { 0519 if (retself) { 0520 return getform(fullname, gcase); 0521 } 0522 else { 0523 return getprop(fullname, gcase); 0524 } 0525 } 0526 0527 // Decline person's name, signal fallback if not possible. 0528 function decline_person_name (gcase, fullname) 0529 { 0530 return decline_person_name_base(gcase, fullname, false); 0531 } 0532 Ts.setcall("именски", decline_person_name); 0533 // "You have invited $[callname case %1] to the party." 0534 0535 // Decline person's name, return as-is if not possible. 0536 function decline_person_name_nf (gcase, fullname) 0537 { 0538 return decline_person_name_base(gcase, fullname, true); 0539 } 0540 Ts.setcall("именски/ф", decline_person_name_nf); 0541 // "You have invited $[callname case %1] to the party." 0542 0543 // ------------------------------ 0544 // Match style attributes to gender of the font family name, 0545 // for the requested grammatical case. 0546 // The message must have dynamic context 'family' equal to the family name, 0547 // so that its gender can be obtained. 0548 // Style string may be composed of several space-separated attributes. 0549 // Family name and style attributes are expected in the nominative case. 0550 // Returns composed style string in the proper gender/case. 0551 function match_style_to_font (compstyle, gcase) 0552 { 0553 var family = Ts.dynctxt("family"); 0554 if (!family) { 0555 throw Ts.fallback(); 0556 } 0557 var gender = getprop(family, "_род"); 0558 var number = "" 0559 if (hasprop(family, "_број")) { 0560 number = getprop(family, "_број"); 0561 } 0562 var styles = compstyle.split(" "); 0563 var final = ""; 0564 for (var i = 0; i < styles.length; i += 1) { 0565 final += " " + getprop(styles[i], gcase + "-" + gender + number); 0566 } 0567 return final.substr(1); // to remove initial space 0568 } 0569 Ts.setcall("стил-према-фонту", match_style_to_font); 0570 0571 // ------------------------------ 0572 // Pick a phrase depending on a dynamic context field. 0573 // Input is the keyword of the context field, followed by pairs of 0574 // regex matcher on context value and corresponding phrase, 0575 // and optionally followed by default phrase in case the value does not match. 0576 // If the value does not match and default phrase is not given, 0577 // fallback is signaled. 0578 // If requested dynamic context field does not exist, fallback is signaled. 0579 function select_by_context (/* ctxt_key, 0580 valrx_1, phrase_1, ..., valrx_N, phrase_N 0581 [, default_phrase]*/) 0582 { 0583 if (arguments.length < 1) 0584 throw Error("Selector by context takes at least the context keyword."); 0585 0586 var ctxtkey = arguments[0]; 0587 var ctxtval = Ts.dynctxt(ctxtkey); 0588 0589 var phrase; 0590 for (var i = 1; i < arguments.length; i += 2) { 0591 if (ctxtval.match(RegExp(arguments[i]))) { 0592 phrase = arguments[i + 1]; 0593 break; 0594 } 0595 } 0596 if (phrase == undefined) { 0597 if (arguments.length % 2 == 0) { 0598 phrase = arguments[arguments.length - 1]; 0599 } else { 0600 throw Ts.fallback(); 0601 } 0602 } 0603 0604 return phrase; 0605 } 0606 Ts.setcall("по-контексту", select_by_context); 0607 0608 // ------------------------------ 0609 // Load property maps. 0610 Ts.loadProps("trapnakron"); 0611 // // Do not load fonts pmap if the user requested so. 0612 // if (!Ts.getConfBool("translate-fonts", true)) { 0613 // }