| 1 |
// kdelibs4.js of Serbian KDE translation |
| 2 |
|
| 3 |
// ------------------------------ |
| 4 |
// Property getter object contains the following data attributes: |
| 5 |
// - callname: the name of the getter call as exposed to PO files |
| 6 |
// - propkey: the key of the property as used in pmap files |
| 7 |
// - overrides: dictionary of values of this property for certain phrases, |
| 8 |
// which were manually set in the PO file |
| 9 |
function Propgetter (callname, propkey) |
| 10 |
{ |
| 11 |
this.callname = callname; |
| 12 |
this.propkey = propkey; |
| 13 |
this.overrides = {}; |
| 14 |
|
| 15 |
this.getbase = Propgetter_getbase; |
| 16 |
|
| 17 |
this.getprop = Propgetter_getprop; |
| 18 |
this.getprop_uc = Propgetter_getprop_uc; |
| 19 |
this.getform = Propgetter_getform; |
| 20 |
this.getform_uc = Propgetter_getform_uc; |
| 21 |
} |
| 22 |
|
| 23 |
// Base of property/form getter methods attached to getter objects. |
| 24 |
// First the property for the given phrase is looked up in overrides, |
| 25 |
// and then in Transcript property map (read from pmap files). |
| 26 |
// If the property is not found, fallback is signalled if retself is false, |
| 27 |
// otherwise the phrase itself is returned. |
| 28 |
function Propgetter_getbase (phrase, retself) |
| 29 |
{ |
| 30 |
if (phrase in this.overrides) { |
| 31 |
return this.overrides[phrase]; |
| 32 |
} |
| 33 |
else { |
| 34 |
var prop = Ts.getProp(phrase, this.propkey) |
| 35 |
if (prop != undefined) |
| 36 |
return prop; |
| 37 |
} |
| 38 |
if (retself) { |
| 39 |
return phrase; |
| 40 |
} |
| 41 |
throw Ts.fallback(); |
| 42 |
} |
| 43 |
|
| 44 |
// Property getter method attached to getter objects. |
| 45 |
function Propgetter_getprop (phrase) |
| 46 |
{ |
| 47 |
return this.getbase(phrase, false); |
| 48 |
} |
| 49 |
|
| 50 |
// As previous, but returns the property with the first letter upcased. |
| 51 |
function Propgetter_getprop_uc (phrase) |
| 52 |
{ |
| 53 |
var val = this.getprop(phrase); |
| 54 |
|
| 55 |
// The second argument is indicating the number of alternatives per |
| 56 |
// alternatives directive -- in case the first letter is within |
| 57 |
// an alternatives directive, all alternatives in that directive |
| 58 |
// should be processed. |
| 59 |
return Ts.toUpperFirst(val, 2); |
| 60 |
} |
| 61 |
|
| 62 |
// Form getter method attached to getter objects. |
| 63 |
function Propgetter_getform (phrase) |
| 64 |
{ |
| 65 |
return this.getbase(phrase, true); |
| 66 |
} |
| 67 |
|
| 68 |
// As previous, but returns the form with the first letter upcased. |
| 69 |
function Propgetter_getform_uc (phrase) |
| 70 |
{ |
| 71 |
var val = this.getform(phrase); |
| 72 |
// See the comment in Propgetter_getprop_uc(). |
| 73 |
return Ts.toUpperFirst(val, 2); |
| 74 |
} |
| 75 |
|
| 76 |
// ------------------------------ |
| 77 |
// Exposing property getters to PO. |
| 78 |
|
| 79 |
// Contains all global property getters. |
| 80 |
var _propgetters_ = {}; |
| 81 |
|
| 82 |
// Set PO calls for given property getter object. |
| 83 |
function setcalls_prop (pgetr) |
| 84 |
{ |
| 85 |
// Default call. |
| 86 |
Ts.setcall(pgetr.callname, pgetr.getprop, pgetr); |
| 87 |
// "Open with $[callname %1]" |
| 88 |
|
| 89 |
// Form call. |
| 90 |
Ts.setcall(pgetr.callname + "/f", pgetr.getform, pgetr); |
| 91 |
// "Open with $[callname/f %1]" |
| 92 |
|
| 93 |
// The calls which capitalize the first letter of the value, |
| 94 |
// named as the default calls but with the first letter capitalized. |
| 95 |
// Only set if the first letter of the call name is actually lowercase. |
| 96 |
callname_uc = Ts.toUpperFirst(pgetr.callname); |
| 97 |
if (callname_uc != pgetr.callname) { |
| 98 |
Ts.setcall(callname_uc, pgetr.getprop_uc, pgetr); |
| 99 |
// "$[Callname %1] starting..." |
| 100 |
Ts.setcall(callname_uc + "/f", pgetr.getform_uc, pgetr); |
| 101 |
// "$[Callname/f %1] starting..." |
| 102 |
} |
| 103 |
|
| 104 |
// Record getter objects globally. |
| 105 |
// Only for the original name, since the uppercase/form variants are not |
| 106 |
// used when properties are being set (when the global store is needed). |
| 107 |
_propgetters_[pgetr.callname] = pgetr; |
| 108 |
} |
| 109 |
|
| 110 |
// Set property value of phrase. |
| 111 |
function setprop (phrase, pkey, pval) |
| 112 |
{ |
| 113 |
// Either create new, or select existing getter. |
| 114 |
var pgetr; |
| 115 |
if (!_propgetters_[pkey]) { |
| 116 |
// Populate new getter if not already defined. |
| 117 |
pgetr = new Propgetter(pkey, pkey); |
| 118 |
// Expose calls to PO. |
| 119 |
setcalls_prop(pgetr); |
| 120 |
} |
| 121 |
else { |
| 122 |
// Get previously defined getter. |
| 123 |
pgetr = _propgetters_[pkey]; |
| 124 |
} |
| 125 |
|
| 126 |
// Add the property into overrides of selected getter. |
| 127 |
pgetr.overrides[phrase] = pval; |
| 128 |
} |
| 129 |
|
| 130 |
// Get property value of phrase. |
| 131 |
// Signals fallback if the property/phrase combination is not defined. |
| 132 |
function getprop (phrase, pkey) |
| 133 |
{ |
| 134 |
if (_propgetters_[pkey]) { |
| 135 |
return _propgetters_[pkey].getprop(phrase); |
| 136 |
} |
| 137 |
throw Ts.fallback(); |
| 138 |
} |
| 139 |
|
| 140 |
// Get form of the phrase, or phrase itself if no such form. |
| 141 |
function getform (phrase, fkey) |
| 142 |
{ |
| 143 |
if (_propgetters_[fkey]) { |
| 144 |
return _propgetters_[fkey].getform(phrase); |
| 145 |
} |
| 146 |
return phrase; |
| 147 |
} |
| 148 |
|
| 149 |
// Returns true if the phrase has the property. |
| 150 |
function hasprop (phrase, pkey) |
| 151 |
{ |
| 152 |
pg = _propgetters_[pkey]; |
| 153 |
if (!pg) { |
| 154 |
return false; |
| 155 |
} |
| 156 |
if (!pg.overrides[phrase] && !Ts.getProp(phrase, pg.propkey)) { |
| 157 |
return false; |
| 158 |
} |
| 159 |
return true; |
| 160 |
} |
| 161 |
|
| 162 |
// ------------------------------ |
| 163 |
// Predefined property getters. |
| 164 |
|
| 165 |
// Call names and corresponding keys in pmap for predefined getters. |
| 166 |
// The first letter in a call name should be lowercase; for each call |
| 167 |
// another call with the first letter in uppercase will be defined, |
| 168 |
// which will upcase the first letter in the property value before |
| 169 |
// returning it. |
| 170 |
var call_name_to_prop = { |
| 171 |
// Nouns. |
| 172 |
"_izv" : "_izvor", // english original |
| 173 |
"_rod" : "_rod", // gender |
| 174 |
"_broj" : "_broj", // number |
| 175 |
|
| 176 |
"nom" : "n", // nominative case |
| 177 |
"gen" : "g", // genitive case |
| 178 |
"dat" : "d", // dative case |
| 179 |
"aku" : "a", // accusative case |
| 180 |
"ins" : "i", // instrumental case |
| 181 |
"lok" : "l", // locative case |
| 182 |
|
| 183 |
// Expressive variants. |
| 184 |
"naredbeno" : "_narb", // command |
| 185 |
"spiskovno" : "_spis", // listed |
| 186 |
|
| 187 |
// Adjectives. |
| 188 |
"nom-m" : "nm", // nominative, masculine |
| 189 |
"gen-m" : "gm", // genitive, masculine |
| 190 |
"dat-m" : "dm", // dative, masculine |
| 191 |
"aku-m" : "am", // accusative, masculine |
| 192 |
"ins-m" : "im", // instrumental, masculine |
| 193 |
"lok-m" : "lm", // locative, masculine |
| 194 |
"nom-ž" : "nz", // nominative, feminine |
| 195 |
"gen-ž" : "gz", // genitive, feminine |
| 196 |
"dat-ž" : "dz", // dative, feminine |
| 197 |
"aku-ž" : "az", // accusative, feminine |
| 198 |
"ins-ž" : "iz", // instrumental, feminine |
| 199 |
"lok-ž" : "lz", // locative, feminine |
| 200 |
"nom-s" : "ns", // nominative, neuter |
| 201 |
"gen-s" : "gs", // genitive, neuter |
| 202 |
"dat-s" : "ds", // dative, neuter |
| 203 |
"aku-s" : "as", // accusative, neuter |
| 204 |
"ins-s" : "is", // instrumental, neuter |
| 205 |
"lok-s" : "ls", // locative, neuter |
| 206 |
"nom-mk" : "nmk", // nominative, masculine, plural |
| 207 |
"gen-mk" : "gmk", // genitive, masculine, plural |
| 208 |
"dat-mk" : "dmk", // dative, masculine, plural |
| 209 |
"aku-mk" : "amk", // accusative, masculine, plural |
| 210 |
"ins-mk" : "imk", // instrumental, masculine, plural |
| 211 |
"lok-mk" : "lmk", // locative, masculine, plural |
| 212 |
"nom-žk" : "nzk", // nominative, feminine, plural |
| 213 |
"gen-žk" : "gzk", // genitive, feminine, plural |
| 214 |
"dat-žk" : "dzk", // dative, feminine, plural |
| 215 |
"aku-žk" : "azk", // accusative, feminine, plural |
| 216 |
"ins-žk" : "izk", // instrumental, feminine, plural |
| 217 |
"lok-žk" : "lzk", // locative, feminine, plural |
| 218 |
"nom-sk" : "nsk", // nominative, neuter, plural |
| 219 |
"gen-sk" : "gsk", // genitive, neuter, plural |
| 220 |
"dat-sk" : "dsk", // dative, neuter, plural |
| 221 |
"aku-sk" : "ask", // accusative, neuter, plural |
| 222 |
"ins-sk" : "isk", // instrumental, neuter, plural |
| 223 |
"lok-sk" : "lsk", // locative, neuter, plural |
| 224 |
}; |
| 225 |
|
| 226 |
// Create getter objects for predefined getters. |
| 227 |
for (cname in call_name_to_prop) { |
| 228 |
// Create getter object as defined above. |
| 229 |
var pgetr = new Propgetter(cname, call_name_to_prop[cname]); |
| 230 |
// Expose calls to PO. |
| 231 |
setcalls_prop(pgetr); |
| 232 |
} |
| 233 |
|
| 234 |
// Special handling for instrumental case, when used for tool application: |
| 235 |
// don't pass it along as-is if same as nominative case of the phrase, |
| 236 |
// since the sentence can get very different, yet semantically correct meaning. |
| 237 |
// Instead, pass genitive case with the preposition "by the help of". |
| 238 |
{ |
| 239 |
var pgetr = new Propgetter("ins-p", "i"); |
| 240 |
|
| 241 |
// Replace default getter method. |
| 242 |
pgetr.getprop = function (phrase) |
| 243 |
{ |
| 244 |
var prop_ins = _propgetters_["ins"].getprop(phrase); |
| 245 |
var prop_nom = _propgetters_["nom"].getprop(phrase); |
| 246 |
if (prop_ins == prop_nom) { |
| 247 |
var prop_gen = _propgetters_["gen"].getprop(phrase); |
| 248 |
return "pomoću " + prop_gen; |
| 249 |
} |
| 250 |
else { |
| 251 |
return prop_ins; |
| 252 |
} |
| 253 |
} |
| 254 |
|
| 255 |
setcalls_prop(pgetr); |
| 256 |
} |
| 257 |
|
| 258 |
// ------------------------------ |
| 259 |
// Set properties of the given phrase. |
| 260 |
// The arguments to the call are the phrase, and a list of as many keys |
| 261 |
// followed by their value as desired (i.e. number of elements must be even). |
| 262 |
// Keys may also be comma-separated lists instead of a single key, in order |
| 263 |
// not to have to repeat the same value when it corresponds to several keys. |
| 264 |
// |
| 265 |
// The property keys become property getters which can be used to retrive |
| 266 |
// the value at a later point. If the getter for a given key already exists, |
| 267 |
// the new value is added into its overrides. |
| 268 |
// |
| 269 |
// Returns undefined. |
| 270 |
// |
| 271 |
function setprops (phrase, keyvals) |
| 272 |
{ |
| 273 |
if (keyvals.length % 2 != 0) |
| 274 |
throw Error("Property setter given odd number of key/value elements."); |
| 275 |
|
| 276 |
for (var i = 0; i < keyvals.length; i += 2) { |
| 277 |
// Several keys may be given for a single prop, comma-separated. |
| 278 |
var pkeys = keyvals[i].split(","); |
| 279 |
var pval = keyvals[i + 1]; |
| 280 |
|
| 281 |
// Set the value to each property key. |
| 282 |
for (var j = 0; j < pkeys.length; j += 1) { |
| 283 |
setprop(phrase, pkeys[j], pval); |
| 284 |
} |
| 285 |
} |
| 286 |
} |
| 287 |
|
| 288 |
// Manually set properties of the phrase given by the finalized msgstr |
| 289 |
// in the PO file and signal fallback. |
| 290 |
// For the rest of the behavior, see setprops() |
| 291 |
function setprops_msgstrf (/*...*/) |
| 292 |
{ |
| 293 |
if (arguments.length % 2 != 0) |
| 294 |
throw Error("Msgstr property setter given odd number of arguments."); |
| 295 |
setprops(Ts.msgstrf(), arguments); |
| 296 |
throw Ts.fallback(); |
| 297 |
} |
| 298 |
Ts.setcall("svojstva", setprops_msgstrf); |
| 299 |
// "$[callname prop1 value1 prop2 value2 ...]" |
| 300 |
|
| 301 |
// Manually set properties of the phrase given by the finalized msgstr |
| 302 |
// in the PO file and return empty string. |
| 303 |
// For the rest of the behavior, see setprops() |
| 304 |
function setprops_msgstrf_e (/*...*/) |
| 305 |
{ |
| 306 |
if (arguments.length % 2 != 0) |
| 307 |
throw Error("Msgstr property setter given odd number of arguments."); |
| 308 |
setprops(Ts.msgstrf(), arguments); |
| 309 |
return ""; |
| 310 |
} |
| 311 |
Ts.setcall("svojstva/p", setprops_msgstrf_e); |
| 312 |
// "$[callname prop1 value1 prop2 value2 ...]" |
| 313 |
|
| 314 |
// ------------------------------ |
| 315 |
// Manual plural handling. |
| 316 |
// Only first three forms, as the fourth form is most likely not needed |
| 317 |
// when the plural needs to be scripted. |
| 318 |
// The first argument should be the proper value, not the substitution string |
| 319 |
// (i.e. do not call as $[~ %1 ...] but as $[~ ^1 ...]). |
| 320 |
function plural3 (n, form0, form1, form2) |
| 321 |
{ |
| 322 |
if (n % 10 == 1 && n % 100 != 11) |
| 323 |
return form0; |
| 324 |
else if (n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20)) |
| 325 |
return form1; |
| 326 |
else |
| 327 |
return form2; |
| 328 |
} |
| 329 |
Ts.setcall("množ", plural3); |
| 330 |
// "...and %2 $[callname ^2 file fila files]" |
| 331 |
|
| 332 |
// ------------------------------ |
| 333 |
// General choice-by-case. |
| 334 |
function select_by_case (/* test, case1, choice1, ..., [default_choice] */) |
| 335 |
{ |
| 336 |
if (arguments.length < 1) |
| 337 |
throw Error("Choice by case takes at least the test value."); |
| 338 |
|
| 339 |
for (var i = 1; i < arguments.length - 1; i += 2) { |
| 340 |
if (arguments[0] == arguments[i]) { |
| 341 |
return arguments[i + 1]; |
| 342 |
} |
| 343 |
} |
| 344 |
// No case matched, see if we have a default. |
| 345 |
if ((arguments.length - 1) % 2 != 0) { |
| 346 |
return arguments[arguments.length - 1]; |
| 347 |
} else { |
| 348 |
throw Ts.fallback(); |
| 349 |
} |
| 350 |
} |
| 351 |
Ts.setcall("kada", select_by_case); |
| 352 |
// "Do you want to %1 $[callname %1 open 'this bar' access 'thisu baru']" |
| 353 |
|
| 354 |
// ------------------------------ |
| 355 |
// Select one of three forms according to the gender of the phrase. |
| 356 |
function select_by_gender (phrase, form_m, form_f, form_n) |
| 357 |
{ |
| 358 |
// Select gender (throws fallback if phrase not found). |
| 359 |
var gender = getprop(phrase, "_rod"); |
| 360 |
|
| 361 |
if (gender == "m") { |
| 362 |
return form_m; |
| 363 |
} |
| 364 |
else if (gender == "ž") { |
| 365 |
return form_f; |
| 366 |
} |
| 367 |
else if (gender == "s") { |
| 368 |
return form_n; |
| 369 |
} |
| 370 |
else { |
| 371 |
throw Ts.fallback(); |
| 372 |
} |
| 373 |
} |
| 374 |
Ts.setcall("po-rodu", select_by_gender); |
| 375 |
// "Delete $[callname %1 this thisa thiso] %1?" |
| 376 |
|
| 377 |
// ------------------------------ |
| 378 |
// Select one of two forms according to the number of the phrase. |
| 379 |
function select_by_number (phrase, form_s, form_p) |
| 380 |
{ |
| 381 |
// Select number (default to singular if not found). |
| 382 |
var number = "j"; |
| 383 |
if (hasprop(phrase, "_broj")) { |
| 384 |
number = getprop(phrase, "_broj"); |
| 385 |
} |
| 386 |
|
| 387 |
if (number == "k") { // plural |
| 388 |
return form_p; |
| 389 |
} else { |
| 390 |
return form_s; |
| 391 |
} |
| 392 |
} |
| 393 |
Ts.setcall("po-broju", select_by_number); |
| 394 |
// "%1 $[callname %1 waalks waalk] by the river." |
| 395 |
|
| 396 |
// ------------------------------ |
| 397 |
// Select one of six forms according to the gender and number of the phrase. |
| 398 |
function select_by_number_gender (phrase, |
| 399 |
form_ms, form_fs, form_ns, // singulars |
| 400 |
form_mp, form_fp, form_np) // plurals |
| 401 |
{ |
| 402 |
// Select number (default to singular if not found). |
| 403 |
var number = "j"; |
| 404 |
if (hasprop(phrase, "_broj")) { |
| 405 |
number = getprop(phrase, "_broj"); |
| 406 |
} |
| 407 |
|
| 408 |
if (number == "k") { // plural |
| 409 |
return select_by_gender(phrase, form_mp, form_fp, form_np); |
| 410 |
} else { |
| 411 |
return select_by_gender(phrase, form_ms, form_fs, form_ns); |
| 412 |
} |
| 413 |
} |
| 414 |
Ts.setcall("po-rodu-broju", select_by_number_gender); |
| 415 |
// "Delete $[callname %1 this thisa thiso thees theesa theeso] %1?" |
| 416 |
|
| 417 |
// ------------------------------ |
| 418 |
// Select one the form according to the case and gender of another argument. |
| 419 |
function select_by_case_gender (gcase, gphrase, phrase) // plurals |
| 420 |
{ |
| 421 |
var gender = getprop(gphrase, "_rod"); |
| 422 |
return getprop(phrase, gcase + "-" + gender); |
| 423 |
} |
| 424 |
Ts.setcall("po-padežu-rodu", select_by_case_gender); |
| 425 |
// "Delete $[callname case %2 %1] [case %2]?" |
| 426 |
|
| 427 |
// ------------------------------ |
| 428 |
// Object to query whether a character is one of expected letters. |
| 429 |
letter_arr = ("" |
| 430 |
+ "abvgdđežzijklljmnnjoprstćufhcčdžšABVGDĐEŽZIJKLLJMNNJOPRSTĆUFHCČDŽŠ" |
| 431 |
+ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" |
| 432 |
).split(""); |
| 433 |
letter = {}; |
| 434 |
for (var i = 0; i < letter_arr.length; ++i) { |
| 435 |
letter[letter_arr[i]] = 1; |
| 436 |
} |
| 437 |
|
| 438 |
// ------------------------------ |
| 439 |
// Split phrase into words and intersections, |
| 440 |
// where words are taken as contiguous segments of letters. |
| 441 |
// The return value is a tuple of arrays of words and intersections. |
| 442 |
// There is always one more of intersections than words, so that |
| 443 |
// the original phrase can be reassembled as |
| 444 |
// intrs[0] + words[0] + ... + intrs[n - 2] + words[n - 2] + intrs[n - 1]. |
| 445 |
function split_phrase (phrase) |
| 446 |
{ |
| 447 |
intrs = []; |
| 448 |
words = []; |
| 449 |
|
| 450 |
var i = 0; |
| 451 |
while (i < phrase.length) { |
| 452 |
var i1 = i; |
| 453 |
while (i1 < phrase.length && !letter[phrase[i1]]) { |
| 454 |
++i1; |
| 455 |
} |
| 456 |
intrs.push(phrase.substring(i, i1)); |
| 457 |
var i2 = i1; |
| 458 |
while (i2 < phrase.length && letter[phrase[i2]]) { |
| 459 |
++i2; |
| 460 |
} |
| 461 |
if (i2 > i1) { |
| 462 |
words.push(phrase.substring(i1, i2)); |
| 463 |
if (i2 == phrase.length) { |
| 464 |
intrs.push(""); |
| 465 |
} |
| 466 |
} |
| 467 |
i = i2; |
| 468 |
} |
| 469 |
|
| 470 |
return [words, intrs]; |
| 471 |
} |
| 472 |
|
| 473 |
// ------------------------------ |
| 474 |
// Apply call to each word in the phrase. |
| 475 |
// The call must accept the word as the last argument. |
| 476 |
function apply_to_word (/* phrase, callname, ...args before word... */) |
| 477 |
{ |
| 478 |
if (arguments.length < 2) |
| 479 |
throw Error("Applicator takes at least the phrase and the call name."); |
| 480 |
|
| 481 |
phrase = arguments[0]; |
| 482 |
calln = arguments[1]; |
| 483 |
cargs = [calln]; |
| 484 |
for (var i = 2; i < arguments.length; ++i) { |
| 485 |
cargs.push(arguments[i]); |
| 486 |
} |
| 487 |
|
| 488 |
lst = split_phrase(phrase); |
| 489 |
words = lst[0]; |
| 490 |
intrs = lst[1]; |
| 491 |
|
| 492 |
nwords = []; |
| 493 |
for (var i = 0; i < words.length; ++i) { |
| 494 |
cargs.push(words[i]); |
| 495 |
nwords.push(Ts.acall.apply(Ts, cargs)); |
| 496 |
cargs.pop(); |
| 497 |
} |
| 498 |
|
| 499 |
str = "" |
| 500 |
for (var i = 0; i < nwords.length; ++i) { |
| 501 |
str += intrs[i] + nwords[i]; |
| 502 |
} |
| 503 |
str += intrs[nwords.length]; |
| 504 |
|
| 505 |
return str; |
| 506 |
} |
| 507 |
Ts.setcall("na-reč", apply_to_word); |
| 508 |
// "Repeat until $[callname casecall %1], and on this date..." |
| 509 |
|
| 510 |
// ------------------------------ |
| 511 |
// Decline person's name into given case. |
| 512 |
// Parse name into first and last name, determine gender according to |
| 513 |
// first name, decline according to gender and assemble. |
| 514 |
// If name cannot be fully declined, returns original name if retself is true, |
| 515 |
// otherwise signals fallback. |
| 516 |
// TODO: Just delegates to ordinary getters for the time being. |
| 517 |
function decline_person_name_base (gcase, fullname, retself) |
| 518 |
{ |
| 519 |
if (retself) { |
| 520 |
return getform(fullname, gcase); |
| 521 |
} |
| 522 |
else { |
| 523 |
return getprop(fullname, gcase); |
| 524 |
} |
| 525 |
} |
| 526 |
|
| 527 |
// Decline person's name, signal fallback if not possible. |
| 528 |
function decline_person_name (gcase, fullname) |
| 529 |
{ |
| 530 |
return decline_person_name_base(gcase, fullname, false); |
| 531 |
} |
| 532 |
Ts.setcall("imenski", decline_person_name); |
| 533 |
// "You have invited $[callname case %1] to the party." |
| 534 |
|
| 535 |
// Decline person's name, return as-is if not possible. |
| 536 |
function decline_person_name_nf (gcase, fullname) |
| 537 |
{ |
| 538 |
return decline_person_name_base(gcase, fullname, true); |
| 539 |
} |
| 540 |
Ts.setcall("imenski/f", decline_person_name_nf); |
| 541 |
// "You have invited $[callname case %1] to the party." |
| 542 |
|
| 543 |
// ------------------------------ |
| 544 |
// Match style attributes to gender of the font family name, |
| 545 |
// for the requested grammatical case. |
| 546 |
// The message must have dynamic context 'family' equal to the family name, |
| 547 |
// so that its gender can be obtained. |
| 548 |
// Style string may be composed of several space-separated attributes. |
| 549 |
// Family name and style attributes are expected in the nominative case. |
| 550 |
// Returns composed style string in the proper gender/case. |
| 551 |
function match_style_to_font (compstyle, gcase) |
| 552 |
{ |
| 553 |
var family = Ts.dynctxt("family"); |
| 554 |
if (!family) { |
| 555 |
throw Ts.fallback(); |
| 556 |
} |
| 557 |
var gender = getprop(family, "_rod"); |
| 558 |
var number = "" |
| 559 |
if (hasprop(family, "_broj")) { |
| 560 |
number = getprop(family, "_broj"); |
| 561 |
} |
| 562 |
var styles = compstyle.split(" "); |
| 563 |
var final = ""; |
| 564 |
for (var i = 0; i < styles.length; i += 1) { |
| 565 |
final += " " + getprop(styles[i], gcase + "-" + gender + number); |
| 566 |
} |
| 567 |
return final.substr(1); // to remove initial space |
| 568 |
} |
| 569 |
Ts.setcall("stil-prema-fontu", match_style_to_font); |
| 570 |
|
| 571 |
// ------------------------------ |
| 572 |
// Pick a phrase depending on a dynamic context field. |
| 573 |
// Input is the keyword of the context field, followed by pairs of |
| 574 |
// regex matcher on context value and corresponding phrase, |
| 575 |
// and optionally followed by default phrase in case the value does not match. |
| 576 |
// If the value does not match and default phrase is not given, |
| 577 |
// fallback is signaled. |
| 578 |
// If requested dynamic context field does not exist, fallback is signaled. |
| 579 |
function select_by_context (/* ctxt_key, |
| 580 |
valrx_1, phrase_1, ..., valrx_N, phrase_N |
| 581 |
[, default_phrase]*/) |
| 582 |
{ |
| 583 |
if (arguments.length < 1) |
| 584 |
throw Error("Selector by context takes at least the context keyword."); |
| 585 |
|
| 586 |
var ctxtkey = arguments[0]; |
| 587 |
var ctxtval = Ts.dynctxt(ctxtkey); |
| 588 |
|
| 589 |
var phrase; |
| 590 |
for (var i = 1; i < arguments.length; i += 2) { |
| 591 |
if (ctxtval.match(RegExp(arguments[i]))) { |
| 592 |
phrase = arguments[i + 1]; |
| 593 |
break; |
| 594 |
} |
| 595 |
} |
| 596 |
if (phrase == undefined) { |
| 597 |
if (arguments.length % 2 == 0) { |
| 598 |
phrase = arguments[arguments.length - 1]; |
| 599 |
} else { |
| 600 |
throw Ts.fallback(); |
| 601 |
} |
| 602 |
} |
| 603 |
|
| 604 |
return phrase; |
| 605 |
} |
| 606 |
Ts.setcall("po-kontekstu", select_by_context); |
| 607 |
|
| 608 |
// ------------------------------ |
| 609 |
// Load property maps. |
| 610 |
Ts.loadProps("trapnakron"); |
| 611 |
// // Do not load fonts pmap if the user requested so. |
| 612 |
// if (!Ts.getConfBool("translate-fonts", true)) { |
| 613 |
// } |