From 7619aa5ebdbd12b10c9bda9876a0f04c6703184a Mon Sep 17 00:00:00 2001 From: "J. T. L" Date: Fri, 23 Mar 2018 11:10:10 -0400 Subject: [PATCH 1/2] Add eslint --- .eslintignore | 1 + .eslintrc.json | 9 +++++++++ package.json | 6 ++++-- 3 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 .eslintignore create mode 100644 .eslintrc.json diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 00000000..07e6e472 --- /dev/null +++ b/.eslintignore @@ -0,0 +1 @@ +/node_modules diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 00000000..ea971285 --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,9 @@ +{ + "extends": "@darkskyapp", + "rules": { + "global-require": "off", + "max-len": "off", + "multiline-comment-style": ["error", "separate-lines"], + "no-unused-vars": ["error", {"args": "none"}] + } +} diff --git a/package.json b/package.json index 69f521c4..ffb07452 100644 --- a/package.json +++ b/package.json @@ -242,9 +242,11 @@ "url": "git://github.com/darkskyapp/translations" }, "scripts": { - "test": "mocha --reporter dot --check-leaks" + "test": "eslint . && mocha --reporter dot" }, "devDependencies": { - "mocha": "*" + "@darkskyapp/eslint-config": "^1.1.1", + "eslint": "^4.19.1", + "mocha": "^5.0.5" } } From dce57e50c992ea8754a49e1ac43531dabc64a827 Mon Sep 17 00:00:00 2001 From: "J. T. L" Date: Fri, 23 Mar 2018 11:12:28 -0400 Subject: [PATCH 2/2] Fix linter errors --- .gitignore | 9 +- index.js | 6 +- lib/lang/ar.js | 14 +- lib/lang/az.js | 10 +- lib/lang/be.js | 16 +- lib/lang/bg.js | 20 +- lib/lang/bs.js | 16 +- lib/lang/ca.js | 10 +- lib/lang/cs.js | 453 ++++++++++++++++++------------------- lib/lang/da.js | 30 +-- lib/lang/de.js | 39 ++-- lib/lang/el.js | 17 +- lib/lang/en.js | 22 +- lib/lang/es.js | 10 +- lib/lang/et.js | 20 +- lib/lang/fi.js | 20 +- lib/lang/fr.js | 14 +- lib/lang/hr.js | 28 ++- lib/lang/hu.js | 13 +- lib/lang/id.js | 16 +- lib/lang/is.js | 21 +- lib/lang/it.js | 25 +-- lib/lang/ja.js | 2 +- lib/lang/ka.js | 2 +- lib/lang/ko.js | 2 +- lib/lang/kw.js | 50 +++-- lib/lang/nl.js | 20 +- lib/lang/no.js | 28 +-- lib/lang/pl.js | 41 ++-- lib/lang/pt.js | 10 +- lib/lang/ro.js | 33 ++- lib/lang/ru.js | 10 +- lib/lang/sk.js | 485 ++++++++++++++++++++-------------------- lib/lang/sl.js | 18 +- lib/lang/sr.js | 56 +++-- lib/lang/sv.js | 42 ++-- lib/lang/tet.js | 11 +- lib/lang/tr.js | 16 +- lib/lang/uk.js | 10 +- lib/lang/x-pig-latin.js | 17 +- test.js | 8 +- test_cases/da.json | 2 +- 42 files changed, 818 insertions(+), 874 deletions(-) diff --git a/.gitignore b/.gitignore index 7ff92de6..2029d91e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,8 @@ -*.swp -.idea/ *.lock *.log -node_modules +*.swp +.DS_Store +.idea/ +/package-lock.json build -.DS_Store \ No newline at end of file +node_modules diff --git a/index.js b/index.js index d986487f..8db891ec 100644 --- a/index.js +++ b/index.js @@ -4,9 +4,11 @@ const path = require("path"); const Translation = require("./lib/translation"); for(const pathname of fs.readdirSync(path.join(__dirname, "lib/lang"))) { - const match = /^([^\.].*)\.js$/.exec(pathname); + const match = /^([^.].*)\.js$/.exec(pathname); if(match) { - exports[match[1]] = new Translation(Object.freeze(require("./lib/lang/" + pathname))); + const template = require("./lib/lang/" + pathname); + Object.freeze(template); + exports[match[1]] = new Translation(template); } } diff --git a/lib/lang/ar.js b/lib/lang/ar.js index 52f078fa..e3275f81 100644 --- a/lib/lang/ar.js +++ b/lib/lang/ar.js @@ -1,15 +1,15 @@ "use strict"; function join(a, b, joiner) { - return (a.slice(0, 4) === "يوم " && b.slice(0, 4) === "يوم " && joiner === " و ") - ? "يومي " + a.slice(4) + joiner + b.slice(4) - : a + joiner + b; + return (a.slice(0, 4) === "يوم " && b.slice(0, 4) === "يوم " && joiner === " و ") + ? "يومي " + a.slice(4) + joiner + b.slice(4) + : a + joiner + b; } function strip_prefix(period) { - return period.slice(0, 10) === "خلال الليل" ? period.slice(5) : - period.slice(0, 3) === "في " ? period.slice(3) : - period; + return period.slice(0, 10) === "خلال الليل" ? period.slice(5) : + period.slice(0, 3) === "في " ? period.slice(3) : + period; } module.exports = { @@ -98,7 +98,7 @@ module.exports = { "with": "$1 مع $2", "range": "$1\u2013$2", "parenthetical": function(a, b) { - return a + " (" + b + (a === "هطول أمطار وثلوج" ? " من الثلج)" : ")" );//a + " (" + b + ")"; + return a + " (" + b + (a === "هطول أمطار وثلوج" ? " من الثلج)" : ")" );// a + " (" + b + ")"; }, "for-hour": "$1 لهذه الساعة", "starting-in": "$1 تبدأ خلال $2", diff --git a/lib/lang/az.js b/lib/lang/az.js index 8c5f7173..5564d119 100644 --- a/lib/lang/az.js +++ b/lib/lang/az.js @@ -97,12 +97,12 @@ module.exports = { "temperatures-rising": "$2 temperatur $1-yə qalxacaq", "temperatures-valleying": "$2 hava kəskin soyuyacaq və temperatur $1-yə düşəcək", "temperatures-falling": "$2 temperatur $1-yə düşəcək", - - /* Capitalize the first letter of every word, except if that word is - * "and". (This is a very crude bastardization of proper English titling - * rules, but it is adequate for the purposes of this module.) */ + + // Capitalize the first letter of every word, except if that word is + // "and". (This is a very crude bastardization of proper English titling + // rules, but it is adequate for the purposes of this module.) "title": str => str.replace( - /([a-zA-ZÇ窺IıƏəÖöĞğÜü.]+)/g, + /([a-zA-ZÇ窺IıƏəÖöĞğÜü.]+)/g, txt => (txt === "və" || txt === "düym" || txt === "sm.")? txt: txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase() diff --git a/lib/lang/be.js b/lib/lang/be.js index 2a4a7f27..849b0020 100644 --- a/lib/lang/be.js +++ b/lib/lang/be.js @@ -1,16 +1,14 @@ "use strict"; function join_with_shared_prefix(a, b, joiner) { - var m = a, - i = 0, - j; + let i = 0; - while(i !== m.length && + while(i !== a.length && i !== b.length && - m.charCodeAt(i) === b.charCodeAt(i)) + a.charCodeAt(i) === b.charCodeAt(i)) ++i; - while(i && m.charCodeAt(i - 1) !== 32) + while(i && a.charCodeAt(i - 1) !== 32) --i; return a + joiner + b.slice(i); @@ -172,14 +170,14 @@ module.exports = { word.charAt(0).toUpperCase() + word.slice(1); }); }, - /* Replace u with short u after vowels in the begnning of the words, - * capitalize the first word of the sentence and end with a period. */ + // Replace u with short u after vowels in the begnning of the words, + // capitalize the first word of the sentence and end with a period. "sentence": function(str) { /* Replace u with short u after vowels in the begnning of the words */ str = str.replace(/[аеёіоуыэюя]\sу/gi, function(word) { return word.slice(0, -1) + "ў"; }); - + /* Capitalize. */ str = str.charAt(0).toUpperCase() + str.slice(1); diff --git a/lib/lang/bg.js b/lib/lang/bg.js index 067e52b2..e3878513 100644 --- a/lib/lang/bg.js +++ b/lib/lang/bg.js @@ -1,16 +1,14 @@ "use strict"; function join_with_shared_prefix(a, b, joiner) { - var m = a, - i = 0, - j; + let i = 0; - while(i !== m.length && + while(i !== a.length && i !== b.length && - m.charCodeAt(i) === b.charCodeAt(i)) + a.charCodeAt(i) === b.charCodeAt(i)) ++i; - while(i && m.charCodeAt(i - 1) !== 32) + while(i && a.charCodeAt(i - 1) !== 32) --i; return a + joiner + b.slice(i); @@ -114,7 +112,7 @@ module.exports = { ); }, "through": function(a, b) { - //return join_with_shared_prefix(a, time2(b), " до "); + // return join_with_shared_prefix(a, time2(b), " до "); return "от " + a + " до " + time2(b); }, "with": "$1, с $2", @@ -128,16 +126,16 @@ module.exports = { "for-day": "$1 през целият ден", "starting": "$1 започва $2", "until": function(condition, time) { - //return condition + " до " + time2(time); + // return condition + " до " + time2(time); return condition + " " + time; }, "until-starting-again": function(condition, timeUntil, timeAgain){ - //timeUntil = time2(timeUntil); + // timeUntil = time2(timeUntil); return condition + " до " + timeUntil + ", започва отново " + timeAgain; }, "starting-continuing-until": function(condition, timeFrom, timeTo) { - //timeFrom = time2(timeFrom); - //timeTo = time2(timeTo); + // timeFrom = time2(timeFrom); + // timeTo = time2(timeTo); return condition + ", започва от " + timeFrom + ", до " + timeTo; }, "during": function(condition, time) { diff --git a/lib/lang/bs.js b/lib/lang/bs.js index 22c2791d..a7badac8 100644 --- a/lib/lang/bs.js +++ b/lib/lang/bs.js @@ -1,16 +1,14 @@ "use strict"; function join_with_shared_prefix(a, b, joiner) { - var m = a, - i = 0, - j; + let i = 0; - while(i !== m.length && + while(i !== a.length && i !== b.length && - m.charCodeAt(i) === b.charCodeAt(i)) + a.charCodeAt(i) === b.charCodeAt(i)) ++i; - while(i && m.charCodeAt(i - 1) !== 32) + while(i && a.charCodeAt(i - 1) !== 32) --i; return a + joiner + b.slice(i); @@ -121,9 +119,9 @@ module.exports = { "temperatures-rising": "temperaturom raste do $1 $2", "temperatures-valleying": "temperaturom najniže do $1 $2", "temperatures-falling": "temperaturom pada do $1 $2", - /* Capitalize the first letter of every word, except if that word is - * "and". (This is a very crude bastardization of proper English titling - * rules, but it is adequate for the purposes of this module.) */ + // Capitalize the first letter of every word, except if that word is + // "and". (This is a very crude bastardization of proper English titling + // rules, but it is adequate for the purposes of this module.) "title": function(str) { return str.charAt(0).toUpperCase() + str.slice(1); }, diff --git a/lib/lang/ca.js b/lib/lang/ca.js index 2e599da5..00ba9138 100644 --- a/lib/lang/ca.js +++ b/lib/lang/ca.js @@ -1,16 +1,14 @@ "use strict"; function join_with_shared_prefix(a, b, joiner) { - var m = a, - i = 0, - j; + let i = 0; - while(i !== m.length && + while(i !== a.length && i !== b.length && - m.charCodeAt(i) === b.charCodeAt(i)) + a.charCodeAt(i) === b.charCodeAt(i)) ++i; - while(i && m.charCodeAt(i - 1) !== 32) + while(i && a.charCodeAt(i - 1) !== 32) --i; return a + joiner + b.slice(i); diff --git a/lib/lang/cs.js b/lib/lang/cs.js index 889eb187..ab91c1e6 100644 --- a/lib/lang/cs.js +++ b/lib/lang/cs.js @@ -1,230 +1,223 @@ -"use strict"; - -function remove_prefix_and_use_genitive(a) { - switch(a) { - case "dnes ráno": - return "dnešního rána"; - case "dnes dopoledne": - return "dnešního dopoledne"; - case "dnes odpoledne": - return "dnešního odpoledne"; - case "dnes podvečer": - return "dnešního podvečera"; - case "dnes večer": - return "dnešního večera"; - case "dnes pozdě večer": - return "dnešního pozdního večera"; - case "dnes v noci": - return "dnešní noci"; - case "dnes pozdě v noci": - return "dnešní pozdní noci"; - case "zítra ráno": - return "zítřejšího rána"; - case "zítra odpoledne": - return "zítřejšího odpoledne"; - case "zítra večer": - return "zítřejšího večera"; - case "zítra v noci": - return "zítřejší noci"; - case "ráno": - return "rána"; - case "odpoledne": - return "odpoledne"; - case "večer": - return "večera"; - case "v noci": - return "noci"; - case "v pondělí": - return "pondelí"; - case "v úterý": - return "uterý"; - case "ve středu": - return "středy"; - case "ve čtvrtek": - return "čtvrtka"; - case "v pátek": - return "pátku"; - case "v sobotu": - return "soboty"; - case "v neděli": - return "neděle"; - default: - return a; - } -} - -function join_with_shared_prefix(a, b, joiner) { - var m = a, - i = 0, - j; - - /* HACK: This gets around "today through on Tuesday" or cases like it, which - * are incorrect in English. */ - if(m === "today" || m === "tomorrow") - m = "on " + m; - - while(i !== m.length && - i !== b.length && - m.charCodeAt(i) === b.charCodeAt(i)) - ++i; - - while(i && m.charCodeAt(i - 1) !== 32) - --i; - - return a + joiner + b.slice(i); -} - -module.exports = { - "clear": "jasno", - "no-precipitation": "bez srážek", - "mixed-precipitation": "smíšené srážky", - "possible-very-light-precipitation": "možnost velmi slabých srážek", - "very-light-precipitation": "velmi slabé srážky", - "possible-light-precipitation": "možnost slabých srážek", - "light-precipitation": "slabé srážky", - "medium-precipitation": "srážky", - "heavy-precipitation": "silné srážky", - "possible-very-light-rain": "možnost mrholení", - "very-light-rain": "mrholení", - "possible-light-rain": "možnost slabého deště", - "light-rain": "slabý déšť", - "medium-rain": "déšť", - "heavy-rain": "vydatný déšť", - "possible-very-light-sleet": "možnost slabého deště se sněhem", - "very-light-sleet": "slabý déšť se sněhem", - "possible-light-sleet": "možnost slabého deště se sněhem", - "light-sleet": "slabý déšť se sněhem", - "medium-sleet": "déšť se sněhem", - "heavy-sleet": "vydatný déšť se sněhem", - "possible-very-light-snow": "možnost slabého sněžení", - "very-light-snow": "slabé sněžení", - "possible-light-snow": "možnost slabého sněžení", - "light-snow": "slabé sněžení", - "medium-snow": "sněžení", - "heavy-snow": "vydatné sněžení", - "light-wind": "slabý vítr", - "medium-wind": "větrno", - "heavy-wind": "silný vítr", - "low-humidity": "nízká vlhkost", - "high-humidity": "vysoká vlhkost", - "fog": "mlhavo", - "light-clouds": "částečně zamračeno", - "medium-clouds": "převážně zamračeno", - "heavy-clouds": "zamračeno", - "today-morning": "dnes ráno", - "later-today-morning": "dnes dopoledne", - "today-afternoon": "dnes odpoledne", - "later-today-afternoon": "dnes podvečer", - "today-evening": "dnes večer", - "later-today-evening": "dnes pozdě večer", - "today-night": "dnes v noci", - "later-today-night": "dnes pozdě v noci", - "tomorrow-morning": "zítra ráno", - "tomorrow-afternoon": "zítra odpoledne", - "tomorrow-evening": "zítra večer", - "tomorrow-night": "zítra v noci", - "morning": "ráno", - "afternoon": "odpoledne", - "evening": "večer", - "night": "v noci", - "today": "dnes", - "tomorrow": "zítra", - "sunday": "v neděli", - "monday": "v pondělí", - "tuesday": "v úterý", - "wednesday": "ve středu", - "thursday": "ve čtvrtek", - "friday": "v pátek", - "saturday": "v sobotu", - "next-sunday": "v neděli", // FIXME - "next-monday": "v pondělí", // FIXME - "next-tuesday": "v úterý", // FIXME - "next-wednesday": "ve středu", // FIXME - "next-thursday": "ve čtvrtek", // FIXME - "next-friday": "v pátek", // FIXME - "next-saturday": "v sobotu", // FIXME - "minutes": "$1 min.", - "fahrenheit": "$1°F", - "celsius": "$1°C", - "inches": "$1 in", - "centimeters": "$1 cm", - "less-than": "méně než $1", - "and": function(a, b) { - return join_with_shared_prefix( - a, - b, - " a " - ); - }, - "through": function(a, b) { - return "od " + remove_prefix_and_use_genitive(a) + " do " + remove_prefix_and_use_genitive(b); - }, - "with": "$1, $2", - "range": "$1-$2", - "parenthetical": function(a, b) { - return a + " (" + b + (a === "smíšené srážky" ? " sněhu)" : ")"); - }, - "for-hour": "$1 hodinu", - "starting-in": "$1 za $2", - "stopping-in": "$1 skončí za $2", - "starting-then-stopping-later": "$1 za $2, skončí o $3 později", - "stopping-then-starting-later": "$1 skončí za $2 a začne znovu o $3 později", - "for-day": "Během dne $1", - "starting": function(a, b) { - return "od " + remove_prefix_and_use_genitive(b) + " " + a; - }, - "until": function(condition, period) { - return condition + " až do " + remove_prefix_and_use_genitive(period); - }, - "until-starting-again": function(condition, a, b) { - var starting = ""; - if(condition.endsWith("srážky")) - starting = ", které začnou znovu "; - else if(condition.endsWith("déšť") || condition.endsWith("déšť se sněhem") || condition.endsWith("vítr")) - starting = ", který začne znovu "; - else if(condition.endsWith("sněžení") || condition.endsWith("mrholení")) - starting = ", které začne znovu "; - else if(condition.endsWith("vlhkost")) - starting = ", která začne znovu "; - else if(condition.endsWith("zamračeno") || condition.endsWith("mlhavo")) - starting = "a začne znovu "; - - return condition + " až do " + remove_prefix_and_use_genitive(a) + starting + b; - }, - "starting-continuing-until": function(condition, a, b) { - var continuing = ""; - if(condition.endsWith("srážky")) - continuing = ", které přetrvají až do "; - else if(condition.endsWith("déšť") || condition.endsWith("déšť se sněhem") || condition.endsWith("vítr")) - continuing = ", který přetrvá až do "; - else if(condition.endsWith("snežení") || condition.endsWith("mrholení")) - continuing = ", které přetrvá až do "; - else if(condition.endsWith("vlhkost")) - continuing = ", která přetrvá až do "; - else if(condition.endsWith("zamračeno") || condition.endsWith("mlhavo")) - continuing = " a přetrvá až do "; - return "od " + remove_prefix_and_use_genitive(a) + " " + condition + continuing + remove_prefix_and_use_genitive(b); - }, - "during": "$2 $1", - "for-week": "$1 během týdne", - "over-weekend": "$1 přes víkend", - "temperatures-peaking": "$2 s teplotním maximem $1", - "temperatures-rising": "$2 s teplotami stoupajícími k $1", - "temperatures-valleying": "$2 s teplotním minimem $1", - "temperatures-falling": "$2 s teplotami klesajícími k $1", - /* Capitalize the first letter of first word. */ - "title": function(str) { - return str.charAt(0).toUpperCase() + str.slice(1); - }, - /* Capitalize the first word of the sentence and end with a period. */ - "sentence": function(str) { - /* Capitalize. */ - str = str.charAt(0).toUpperCase() + str.slice(1); - - /* Add a period if there isn't already one. */ - if(str.charAt(str.length - 1) !== ".") - str += "."; - - return str; - }, -}; +"use strict"; + +function remove_prefix_and_use_genitive(a) { + switch(a) { + case "dnes ráno": + return "dnešního rána"; + case "dnes dopoledne": + return "dnešního dopoledne"; + case "dnes odpoledne": + return "dnešního odpoledne"; + case "dnes podvečer": + return "dnešního podvečera"; + case "dnes večer": + return "dnešního večera"; + case "dnes pozdě večer": + return "dnešního pozdního večera"; + case "dnes v noci": + return "dnešní noci"; + case "dnes pozdě v noci": + return "dnešní pozdní noci"; + case "zítra ráno": + return "zítřejšího rána"; + case "zítra odpoledne": + return "zítřejšího odpoledne"; + case "zítra večer": + return "zítřejšího večera"; + case "zítra v noci": + return "zítřejší noci"; + case "ráno": + return "rána"; + case "odpoledne": + return "odpoledne"; + case "večer": + return "večera"; + case "v noci": + return "noci"; + case "v pondělí": + return "pondelí"; + case "v úterý": + return "uterý"; + case "ve středu": + return "středy"; + case "ve čtvrtek": + return "čtvrtka"; + case "v pátek": + return "pátku"; + case "v sobotu": + return "soboty"; + case "v neděli": + return "neděle"; + default: + return a; + } +} + +function join_with_shared_prefix(a, b, joiner) { + let i = 0; + + while(i !== a.length && + i !== b.length && + a.charCodeAt(i) === b.charCodeAt(i)) + ++i; + + while(i && a.charCodeAt(i - 1) !== 32) + --i; + + return a + joiner + b.slice(i); +} + +module.exports = { + "clear": "jasno", + "no-precipitation": "bez srážek", + "mixed-precipitation": "smíšené srážky", + "possible-very-light-precipitation": "možnost velmi slabých srážek", + "very-light-precipitation": "velmi slabé srážky", + "possible-light-precipitation": "možnost slabých srážek", + "light-precipitation": "slabé srážky", + "medium-precipitation": "srážky", + "heavy-precipitation": "silné srážky", + "possible-very-light-rain": "možnost mrholení", + "very-light-rain": "mrholení", + "possible-light-rain": "možnost slabého deště", + "light-rain": "slabý déšť", + "medium-rain": "déšť", + "heavy-rain": "vydatný déšť", + "possible-very-light-sleet": "možnost slabého deště se sněhem", + "very-light-sleet": "slabý déšť se sněhem", + "possible-light-sleet": "možnost slabého deště se sněhem", + "light-sleet": "slabý déšť se sněhem", + "medium-sleet": "déšť se sněhem", + "heavy-sleet": "vydatný déšť se sněhem", + "possible-very-light-snow": "možnost slabého sněžení", + "very-light-snow": "slabé sněžení", + "possible-light-snow": "možnost slabého sněžení", + "light-snow": "slabé sněžení", + "medium-snow": "sněžení", + "heavy-snow": "vydatné sněžení", + "light-wind": "slabý vítr", + "medium-wind": "větrno", + "heavy-wind": "silný vítr", + "low-humidity": "nízká vlhkost", + "high-humidity": "vysoká vlhkost", + "fog": "mlhavo", + "light-clouds": "částečně zamračeno", + "medium-clouds": "převážně zamračeno", + "heavy-clouds": "zamračeno", + "today-morning": "dnes ráno", + "later-today-morning": "dnes dopoledne", + "today-afternoon": "dnes odpoledne", + "later-today-afternoon": "dnes podvečer", + "today-evening": "dnes večer", + "later-today-evening": "dnes pozdě večer", + "today-night": "dnes v noci", + "later-today-night": "dnes pozdě v noci", + "tomorrow-morning": "zítra ráno", + "tomorrow-afternoon": "zítra odpoledne", + "tomorrow-evening": "zítra večer", + "tomorrow-night": "zítra v noci", + "morning": "ráno", + "afternoon": "odpoledne", + "evening": "večer", + "night": "v noci", + "today": "dnes", + "tomorrow": "zítra", + "sunday": "v neděli", + "monday": "v pondělí", + "tuesday": "v úterý", + "wednesday": "ve středu", + "thursday": "ve čtvrtek", + "friday": "v pátek", + "saturday": "v sobotu", + "next-sunday": "v neděli", // FIXME + "next-monday": "v pondělí", // FIXME + "next-tuesday": "v úterý", // FIXME + "next-wednesday": "ve středu", // FIXME + "next-thursday": "ve čtvrtek", // FIXME + "next-friday": "v pátek", // FIXME + "next-saturday": "v sobotu", // FIXME + "minutes": "$1 min.", + "fahrenheit": "$1°F", + "celsius": "$1°C", + "inches": "$1 in", + "centimeters": "$1 cm", + "less-than": "méně než $1", + "and": function(a, b) { + return join_with_shared_prefix( + a, + b, + " a " + ); + }, + "through": function(a, b) { + return "od " + remove_prefix_and_use_genitive(a) + " do " + remove_prefix_and_use_genitive(b); + }, + "with": "$1, $2", + "range": "$1-$2", + "parenthetical": function(a, b) { + return a + " (" + b + (a === "smíšené srážky" ? " sněhu)" : ")"); + }, + "for-hour": "$1 hodinu", + "starting-in": "$1 za $2", + "stopping-in": "$1 skončí za $2", + "starting-then-stopping-later": "$1 za $2, skončí o $3 později", + "stopping-then-starting-later": "$1 skončí za $2 a začne znovu o $3 později", + "for-day": "Během dne $1", + "starting": function(a, b) { + return "od " + remove_prefix_and_use_genitive(b) + " " + a; + }, + "until": function(condition, period) { + return condition + " až do " + remove_prefix_and_use_genitive(period); + }, + "until-starting-again": function(condition, a, b) { + let starting = ""; + if(condition.endsWith("srážky")) + starting = ", které začnou znovu "; + else if(condition.endsWith("déšť") || condition.endsWith("déšť se sněhem") || condition.endsWith("vítr")) + starting = ", který začne znovu "; + else if(condition.endsWith("sněžení") || condition.endsWith("mrholení")) + starting = ", které začne znovu "; + else if(condition.endsWith("vlhkost")) + starting = ", která začne znovu "; + else if(condition.endsWith("zamračeno") || condition.endsWith("mlhavo")) + starting = "a začne znovu "; + + return condition + " až do " + remove_prefix_and_use_genitive(a) + starting + b; + }, + "starting-continuing-until": function(condition, a, b) { + let continuing = ""; + if(condition.endsWith("srážky")) + continuing = ", které přetrvají až do "; + else if(condition.endsWith("déšť") || condition.endsWith("déšť se sněhem") || condition.endsWith("vítr")) + continuing = ", který přetrvá až do "; + else if(condition.endsWith("snežení") || condition.endsWith("mrholení")) + continuing = ", které přetrvá až do "; + else if(condition.endsWith("vlhkost")) + continuing = ", která přetrvá až do "; + else if(condition.endsWith("zamračeno") || condition.endsWith("mlhavo")) + continuing = " a přetrvá až do "; + return "od " + remove_prefix_and_use_genitive(a) + " " + condition + continuing + remove_prefix_and_use_genitive(b); + }, + "during": "$2 $1", + "for-week": "$1 během týdne", + "over-weekend": "$1 přes víkend", + "temperatures-peaking": "$2 s teplotním maximem $1", + "temperatures-rising": "$2 s teplotami stoupajícími k $1", + "temperatures-valleying": "$2 s teplotním minimem $1", + "temperatures-falling": "$2 s teplotami klesajícími k $1", + /* Capitalize the first letter of first word. */ + "title": function(str) { + return str.charAt(0).toUpperCase() + str.slice(1); + }, + /* Capitalize the first word of the sentence and end with a period. */ + "sentence": function(str) { + /* Capitalize. */ + str = str.charAt(0).toUpperCase() + str.slice(1); + + /* Add a period if there isn't already one. */ + if(str.charAt(str.length - 1) !== ".") + str += "."; + + return str; + }, +}; diff --git a/lib/lang/da.js b/lib/lang/da.js index bcac80ac..fbed6d03 100644 --- a/lib/lang/da.js +++ b/lib/lang/da.js @@ -1,30 +1,32 @@ "use strict"; function join_with_shared_prefix(a, b, joiner) { - var m = a, - i = 0, - j; + let i = 0; - while(i !== m.length && + while(i !== a.length && i !== b.length && - m.charCodeAt(i) === b.charCodeAt(i)) + a.charCodeAt(i) === b.charCodeAt(i)) ++i; - while(i && m.charCodeAt(i - 1) !== 32) + while(i && a.charCodeAt(i - 1) !== 32) --i; return a + joiner + b.slice(i); } function strip_prefix(period) { - return period.slice(0, 10) === "om natten" ? period.slice(3) : - period.slice(0, 6) === "under " ? period.slice(6) : - period; + if(period.slice(0, 10) === "om natten") { + return period.slice(3); + } + if(period.slice(0, 6) === "under ") { + return period.slice(6); + } + return period; } function grammar(str) { - return str.replace(/på /gi, "om ") - .replace(/(man|tirs|ons|tors|fre|lør|søn)(dag)/gi, "$1dagen"); + return str.replace(/på /gi, "om "). + replace(/(man|tirs|ons|tors|fre|lør|søn)(dag)/gi, "$1dagen"); } module.exports = { @@ -125,14 +127,14 @@ module.exports = { "for-day": "$1 i løbet af dagen", "starting": "$1 $2", "until": function(condition, period) { - return condition + " indtil " + strip_prefix(period); + return condition + " indtil " + strip_prefix(period); }, "until-starting-again": function(condition, a, b) { - return condition + " indtil " + strip_prefix(a) + + return condition + " indtil " + strip_prefix(a) + ", kommer igen " + b; }, "starting-continuing-until": function(condition, a, b) { - return condition + " " + a + ", fortsætter indtil " + + return condition + " " + a + ", fortsætter indtil " + strip_prefix(b); }, "during": "$1 $2", diff --git a/lib/lang/de.js b/lib/lang/de.js index 63c7aa1f..dc38366d 100644 --- a/lib/lang/de.js +++ b/lib/lang/de.js @@ -1,7 +1,7 @@ "use strict"; function join_with_shared_prefix(a, b, joiner) { - var i = 0; + let i = 0; while(i !== a.length && i !== b.length && @@ -16,8 +16,8 @@ function join_with_shared_prefix(a, b, joiner) { function until_time(time) { return time === "Abend" ? "bis abends" : - time === "Nacht" ? "die ganze Nacht" : - "bis " + time; + time === "Nacht" ? "die ganze Nacht" : + "bis " + time; } module.exports = { @@ -120,11 +120,10 @@ module.exports = { if(this[1] === "starting") return time + ((time === "Vormittag" || time === "Nachmittag" || time === "Abend" || time === "Nacht") ? "s" : "") + " " + condition; - else if(this[1] === "and") + if(this[1] === "and") return time + " " + condition; - else - return condition + " " + time; + return condition + " " + time; }, "until": function(condition, time) { return condition + " " + until_time(time); @@ -133,35 +132,35 @@ module.exports = { return condition + " bis zum " + a + (b === "Nacht" ? " und Nacht" : " und " + b + " wieder"); }, "starting-continuing-until": function(condition, a, b) { - if (a === "Abend" && b === "Nacht") - return condition + " abends und nächtlich" + if(a === "Abend" && b === "Nacht") { + return condition + " abends und nächtlich"; + } - if(a === "Abend") + if(a === "Abend") { a = "abends "; - - else if (a === "Vormittag") + } + else if(a === "Vormittag") { a = "vormittags"; - - else if (a === "Mittag") + } + else if (a === "Mittag") { a = "mittags"; - - else if (a === "Nachmittag") + } + else if (a === "Nachmittag") { a = "nachmittags"; - + } return condition + " von " + a + " " + until_time(b); }, "during": function(condition, time) { if(this[1] === "and") return time + " " + condition; - else if(this[1] === "with") + if(this[1] === "with") return condition + " " + time; - else if(time === "Nacht") + if(time === "Nacht") return condition + " in der " + time; - else - return condition + " am " + time; + return condition + " am " + time; }, "for-week": "die ganze Woche $1", "over-weekend": "$1 am Wochenende", diff --git a/lib/lang/el.js b/lib/lang/el.js index 37e8cb0d..0cc7325c 100644 --- a/lib/lang/el.js +++ b/lib/lang/el.js @@ -5,9 +5,9 @@ function singular_or_plural(n,singular,plural){ } function strip_prefix(period) { - return period === "απόψε" ? "σήμερα το βράδυ" : - period.slice(0, 7) === "σήμερα " ? period.slice(7) : - period; + return period === "απόψε" ? "σήμερα το βράδυ" : + period.slice(0, 7) === "σήμερα " ? period.slice(7) : + period; } module.exports = { @@ -112,26 +112,25 @@ module.exports = { return condition + " μέχρι " + strip_prefix(a) + ", που θα συνεχιστεί και " + b; }, "starting-continuing-until": function(condition, a, b) { - return condition + " που θα αρχίσει " + a + ", και θα συνεχιστεί μέχρι " + - strip_prefix(b); + return condition + " που θα αρχίσει " + a + ", και θα συνεχιστεί μέχρι " + strip_prefix(b); }, "during": "$1 $2", "for-week": "$1 κατά τη διάρκεια της εβδομάδας", "over-weekend": "$1 το Σαββατοκύριακο", "temperatures-peaking": function(temperature,day){ - let sop = singular_or_plural(temperature,'στον','στους'); + const sop = singular_or_plural(temperature,"στον","στους"); return `τη θερμοκρασία να κορυφώνεται ${sop} ${temperature} ${day}`; }, "temperatures-rising": function(temperature,day){ - let sop = singular_or_plural(temperature,'τον','τους'); + const sop = singular_or_plural(temperature,"τον","τους"); return `τη θερμοκρασία να αυξάνεται έως ${sop} ${temperature} ${day}`; }, "temperatures-valleying": function(temperature,day){ - let sop = singular_or_plural(temperature,'στον','στους'); + const sop = singular_or_plural(temperature,"στον","στους"); return `τη θερμοκρασία να πέφτει ${sop} ${temperature} ${day}`; }, "temperatures-falling": function(temperature,day){ - let sop = singular_or_plural(temperature,'στον','στους'); + const sop = singular_or_plural(temperature,"στον","στους"); return `τη θερμοκρασία να μειώνεται ${sop} ${temperature} ${day}`; }, /* Capitalize the first letter of every word */ diff --git a/lib/lang/en.js b/lib/lang/en.js index 44d7fab7..d89c1c66 100644 --- a/lib/lang/en.js +++ b/lib/lang/en.js @@ -1,12 +1,11 @@ "use strict"; function join_with_shared_prefix(a, b, joiner) { - var m = a, - i = 0, - j; + let m = a; + let i = 0; - /* HACK: This gets around "today through on Tuesday" or cases like it, which - * are incorrect in English. */ + // HACK: This gets around "today through on Tuesday" or cases like it, which + // are incorrect in English. if(m === "today" || m === "tomorrow") m = "on " + m; @@ -23,8 +22,8 @@ function join_with_shared_prefix(a, b, joiner) { function strip_prefix(period) { return period.slice(0, 9) === "overnight" ? period.slice(4) : - period.slice(0, 7) === "in the " ? period.slice(7) : - period; + period.slice(0, 7) === "in the " ? period.slice(7) : + period; } module.exports = { @@ -133,8 +132,7 @@ module.exports = { return condition + " until " + strip_prefix(a) + ", starting again " + b; }, "starting-continuing-until": function(condition, a, b) { - return condition + " starting " + a + ", continuing until " + - strip_prefix(b); + return condition + " starting " + a + ", continuing until " + strip_prefix(b); }, "during": "$1 $2", "for-week": "$1 throughout the week", @@ -143,9 +141,9 @@ module.exports = { "temperatures-rising": "high temperatures rising to $1 $2", "temperatures-valleying": "high temperatures bottoming out at $1 $2", "temperatures-falling": "high temperatures falling to $1 $2", - /* Capitalize the first letter of every word, except if that word is - * "and". (This is a very crude bastardization of proper English titling - * rules, but it is adequate for the purposes of this module.) */ + // Capitalize the first letter of every word, except if that word is + // "and". (This is a very crude bastardization of proper English titling + // rules, but it is adequate for the purposes of this module.) "title": function(str) { return str.replace( /\b(?:a(?!nd\b)|c(?!m\.)|i(?!n\.)|[^\Waci])/g, diff --git a/lib/lang/es.js b/lib/lang/es.js index 83b5e6cb..2ea55cee 100644 --- a/lib/lang/es.js +++ b/lib/lang/es.js @@ -1,16 +1,14 @@ "use strict"; function join_with_shared_prefix(a, b, joiner) { - var m = a, - i = 0, - j; + let i = 0; - while(i !== m.length && + while(i !== a.length && i !== b.length && - m.charCodeAt(i) === b.charCodeAt(i)) + a.charCodeAt(i) === b.charCodeAt(i)) ++i; - while(i && m.charCodeAt(i - 1) !== 32) + while(i && a.charCodeAt(i - 1) !== 32) --i; return a + joiner + b.slice(i); diff --git a/lib/lang/et.js b/lib/lang/et.js index 07958302..c9d77c1c 100644 --- a/lib/lang/et.js +++ b/lib/lang/et.js @@ -1,22 +1,20 @@ "use strict"; function join_with_shared_prefix(a, b, joiner) { - var m = a, - i = 0, - j; + let i = 0; - while(i !== m.length && + while(i !== a.length && i !== b.length && - m.charCodeAt(i) === b.charCodeAt(i)) + a.charCodeAt(i) === b.charCodeAt(i)) ++i; - while(i && m.charCodeAt(i - 1) !== 32) + while(i && a.charCodeAt(i - 1) !== 32) --i; return a + joiner + b.slice(i); } -var grammar = { +const grammar = { "täna": ["tänasest", null], "homme": ["homsest", "homseni"], "öösel": ["ööst", "ööni"], @@ -43,7 +41,7 @@ var grammar = { "järgmisel kolmapäeval": ["järgmisest kolmapäevast", "järgmise kolmapäevani"], "järgmisel neljapäeval": ["järgmisest neljapäevast", "järgmise neljapäevani"], "järgmisel reedel": ["järgmisest reedest", "järgmise reedeni"], - "järgmisel laupäeval": ["järgmisest laupäevast", "järgmise laupäevani"] + "järgmisel laupäeval": ["järgmisest laupäevast", "järgmise laupäevani"], }; function elative(word) { @@ -139,8 +137,8 @@ module.exports = { b = illative(b); return (a && b)? a + " kuni " + b: - (a || b)? (a || b) + " kuni": - ""; + (a || b)? (a || b) + " kuni": + ""; }, "with": "$1, $2", "range": "$1\u2013$2", @@ -152,7 +150,7 @@ module.exports = { "stopping-then-starting-later": "$1 lõppeb $2 pärast, algab uuesti $3 hiljem", "for-day": "Terve päev on $1", "starting": function(condition, period){ - return condition + " alates " + elative(period); + return condition + " alates " + elative(period); }, "until": function(condition, period) { return condition + " kuni " + illative(period); diff --git a/lib/lang/fi.js b/lib/lang/fi.js index d3dc2bf5..2a1870d4 100644 --- a/lib/lang/fi.js +++ b/lib/lang/fi.js @@ -1,22 +1,20 @@ "use strict"; function join_with_shared_prefix(a, b, joiner) { - var m = a, - i = 0, - j; + let i = 0; - while(i !== m.length && + while(i !== a.length && i !== b.length && - m.charCodeAt(i) === b.charCodeAt(i)) + a.charCodeAt(i) === b.charCodeAt(i)) ++i; - while(i && m.charCodeAt(i - 1) !== 32) + while(i && a.charCodeAt(i - 1) !== 32) --i; return a + joiner + b.slice(i); } -var grammar = { +const grammar = { "tänään": [null, null], "huomenna": ["huomisesta", "huomiseen asti"], "yöllä": ["yöstä", "yöhön asti"], @@ -36,7 +34,7 @@ var grammar = { "torstaina": ["torstaista", "torstaihin"], "perjantaina": ["perjantaista", "perjantaihin"], "lauantaina": ["lauantaista", "lauantaihin"], - "sunnuntaina": ["sunnuntaista", "sunnuntaihin"] + "sunnuntaina": ["sunnuntaista", "sunnuntaihin"], }; function elative(word) { @@ -129,8 +127,8 @@ module.exports = { a = elative(a); b = illative(b); return (a && b)? a + " " + b + " asti": - (a || b)? (a || b) + " asti": - "asti"; + (a || b)? (a || b) + " asti": + "asti"; }, "with": "$1, $2", "range": "$1\u2013$2", @@ -142,7 +140,7 @@ module.exports = { "stopping-then-starting-later": "$1 vielä $2, alkaen uudestaan $3 myöhemmin", "for-day": "$1 päivän aikana", "starting": function(condition, period){ - return condition + " " + elative(period); + return condition + " " + elative(period); }, "until": function(condition, period) { return condition + " " + illative(period); diff --git a/lib/lang/fr.js b/lib/lang/fr.js index 3627ddc0..945c6338 100644 --- a/lib/lang/fr.js +++ b/lib/lang/fr.js @@ -1,8 +1,7 @@ "use strict"; function join_with_shared_prefix(a, b, joiner) { - var i = 0, - j; + let i = 0; while(i !== a.length && i !== b.length && @@ -131,12 +130,11 @@ module.exports = { "temperatures-rising": "des températures maximales montant jusqu’à $1 $2", "temperatures-valleying": "des températures maximales atteignant $1 $2", "temperatures-falling": "des températures maximales descendant jusqu’à $1 $2", - /* Capitalize the first letter of every word, except if that word is "et". - * - * Fun fact: JavaScript regex's "\w" and "\b" don't recognize accented - * characters (such as é or à) and so the neat trick used in the English - * version of the "title" function can't be used here. (Conveniently, - * anyway.) */ + // Capitalize the first letter of every word, except if that word is "et". + // Fun fact: JavaScript regex's "\w" and "\b" don't recognize accented + // characters (such as é or à) and so the neat trick used in the English + // version of the "title" function can't be used here. (Conveniently, + // anyway.) "title": function(str) { return str.replace(/\S+/g, function(word) { return word === "et" ? diff --git a/lib/lang/hr.js b/lib/lang/hr.js index f93214d5..16c90de9 100644 --- a/lib/lang/hr.js +++ b/lib/lang/hr.js @@ -1,16 +1,14 @@ "use strict"; function join_with_shared_prefix(a, b, joiner) { - var m = a, - i = 0, - j; + let i = 0; - while(i !== m.length && + while(i !== a.length && i !== b.length && - m.charCodeAt(i) === b.charCodeAt(i)) + a.charCodeAt(i) === b.charCodeAt(i)) ++i; - while(i && m.charCodeAt(i - 1) !== 32) + while(i && a.charCodeAt(i - 1) !== 32) --i; return a + joiner + b.slice(i); @@ -123,17 +121,17 @@ module.exports = { "temperatures-rising": "temperaturom raste do $1 $2", "temperatures-valleying": "temperaturom najniže do $1 $2", "temperatures-falling": "temperaturom pada do $1 $2", - /* Capitalize the first letter of every word, except if that word is - * "and". (This is a very crude bastardization of proper English titling - * rules, but it is adequate for the purposes of this module.) */ + // Capitalize the first letter of every word, except if that word is + // "and". (This is a very crude bastardization of proper English titling + // rules, but it is adequate for the purposes of this module.) "title": function(str) { return str.charAt(0).toUpperCase() + str.slice(1); - /*return str.replace( - /\b(?:a(?!nd\b)|[^\Wa])/g, - function(letter) { - return letter.toUpperCase(); - } - );*/ + // return str.replace( + // /\b(?:a(?!nd\b)|[^\Wa])/g, + // function(letter) { + // return letter.toUpperCase(); + // } + // ); }, /* Capitalize the first word of the sentence and end with a period. */ "sentence": function(str) { diff --git a/lib/lang/hu.js b/lib/lang/hu.js index c3012310..fe6503a0 100644 --- a/lib/lang/hu.js +++ b/lib/lang/hu.js @@ -1,14 +1,13 @@ "use strict"; function join_with_shared_prefix(a, b, joiner) { - var m = a, - i = 0, - j; + let m = a; + let i = 0; - /* HACK: This gets around "today through on Tuesday" or cases like it, which - * are incorrect in English. */ + // HACK: This gets around "today through on Tuesday" or cases like it, which + // are incorrect in English. if(m === "ma" || m === "holnap") - m = "a" + m + "i nap"; + m = "a" + m + "i nap"; while(i !== m.length && i !== b.length && @@ -18,7 +17,7 @@ function join_with_shared_prefix(a, b, joiner) { while(i && m.charCodeAt(i - 1) !== 32) --i; - return a + " és " + b.slice(i)+ joiner; + return a + " és " + b.slice(i) + joiner; } module.exports = { diff --git a/lib/lang/id.js b/lib/lang/id.js index 9b3bb390..048583c2 100644 --- a/lib/lang/id.js +++ b/lib/lang/id.js @@ -1,16 +1,14 @@ "use strict"; function join_with_shared_prefix(a, b, joiner) { - var m = a, - i = 0, - j; + let i = 0; - while(i !== m.length && + while(i !== a.length && i !== b.length && - m.charCodeAt(i) === b.charCodeAt(i)) + a.charCodeAt(i) === b.charCodeAt(i)) ++i; - while(i && m.charCodeAt(i - 1) !== 32) + while(i && a.charCodeAt(i - 1) !== 32) --i; return a + joiner + b.slice(i); @@ -125,9 +123,9 @@ module.exports = { "temperatures-rising": "suhu naik ke $1 $2", "temperatures-valleying": "suhu menurun pada $1 $2", "temperatures-falling": "suhu turun pada $1 $2", - /* Capitalize the first letter of every word, except if that word is - * "and". (This is a very crude bastardization of proper English titling - * rules, but it is adequate for the purposes of this module.) */ + // Capitalize the first letter of every word, except if that word is + // "and". (This is a very crude bastardization of proper English titling + // rules, but it is adequate for the purposes of this module.) "title": function(str) { return str.replace( /\b(?:a(?!nd\b)|c(?!m\.)|i(?!n\.)|[^\Waci])/g, diff --git a/lib/lang/is.js b/lib/lang/is.js index 419d9ea5..2f1c1861 100644 --- a/lib/lang/is.js +++ b/lib/lang/is.js @@ -1,16 +1,14 @@ "use strict"; function join_with_shared_prefix(a, b, joiner) { - var m = a, - i = 0, - j; + let i = 0; - while(i !== m.length && + while(i !== a.length && i !== b.length && - m.charCodeAt(i) === b.charCodeAt(i)) + a.charCodeAt(i) === b.charCodeAt(i)) ++i; - while(i && m.charCodeAt(i - 1) !== 32) + while(i && a.charCodeAt(i - 1) !== 32) --i; return a + joiner + b.slice(i); @@ -18,8 +16,8 @@ function join_with_shared_prefix(a, b, joiner) { function strip_prefix(period) { return period.slice(0, 13) === "yfir nóttina" ? period.slice(5) : - period.slice(0, 4) === "um " ? period.slice(3) : - period; + period.slice(0, 4) === "um " ? period.slice(3) : + period; } module.exports = { @@ -124,8 +122,7 @@ module.exports = { return condition + " þangað til " + strip_prefix(a) + ", byrjar aftur " + b; }, "starting-continuing-until": function(condition, a, b) { - return condition + ", byrjar " + a + " og heldur áfram yfir " + - strip_prefix(b); + return condition + ", byrjar " + a + " og heldur áfram yfir " + strip_prefix(b); }, "during": "$1 $2", "for-week": "$1 yfir vikuna", @@ -134,8 +131,8 @@ module.exports = { "temperatures-rising": "hita að nálgast $1 $2", "temperatures-valleying": "hita niður í $1 $2", "temperatures-falling": "hita að falla niður í $1 $2", - /* Capitalize the first character in the word. - * We never titleize nor camelcase words in an sentence in Icelandic. */ + // Capitalize the first character in the word. + // We never titleize nor camelcase words in an sentence in Icelandic. "title": function(str) { str = str.charAt(0).toUpperCase() + str.slice(1); return str; diff --git a/lib/lang/it.js b/lib/lang/it.js index ecc32474..b3b1d044 100644 --- a/lib/lang/it.js +++ b/lib/lang/it.js @@ -1,16 +1,14 @@ "use strict"; function join_with_shared_prefix(a, b, joiner) { - var m = a, - i = 0, - j; + let i = 0; - while(i !== m.length && + while(i !== a.length && i !== b.length && - m.charCodeAt(i) === b.charCodeAt(i)) + a.charCodeAt(i) === b.charCodeAt(i)) ++i; - while(i && m.charCodeAt(i - 1) !== 32) + while(i && a.charCodeAt(i - 1) !== 32) --i; return a + joiner + b.slice(i); @@ -102,16 +100,16 @@ module.exports = { "centimeters": "$1 cm.", "less-than": "meno di $1", "and": function(a, b) { - var joiner = b.length > 8 && b.slice(0,8) === "prossimo" ? " e il " : - b.length > 8 && b.slice(0,8) === "prossima" ? " e la " : - " e "; + let joiner = b.length > 8 && b.slice(0,8) === "prossimo" ? " e il " : + b.length > 8 && b.slice(0,8) === "prossima" ? " e la " : + " e "; if (a.indexOf(",") !== -1) joiner = "," + joiner; return join_with_shared_prefix(a,b,joiner); }, "through": function(a, b) { - var joiner = b.length > 8 && b.slice(0,8) === "prossimo" ? " fino al " : - b.length > 8 && b.slice(0,8) === "prossima" ? " fino alla " : - " fino a "; + const joiner = b.length > 8 && b.slice(0,8) === "prossimo" ? " fino al " : + b.length > 8 && b.slice(0,8) === "prossima" ? " fino alla " : + " fino a "; return join_with_shared_prefix(a, b, joiner); }, "with": "$1, con $2", @@ -135,8 +133,7 @@ module.exports = { return condition + " fino a " + strip_prefix(a) + ", ricominciando da " + b; }, "starting-continuing-until": function(condition, a, b) { - return condition + " a partire da " + strip_prefix(a) + ", fino a " + - strip_prefix(b); + return condition + " a partire da " + strip_prefix(a) + ", fino a " + strip_prefix(b); }, "during": "$1 $2", "for-week": "$1 durante la settimana", diff --git a/lib/lang/ja.js b/lib/lang/ja.js index a13335ff..76607397 100644 --- a/lib/lang/ja.js +++ b/lib/lang/ja.js @@ -1,7 +1,7 @@ "use strict"; function join_with_shared_prefix(a, b, joiner) { - var i = 0; + let i = 0; while(i !== a.length && i !== b.length && diff --git a/lib/lang/ka.js b/lib/lang/ka.js index b7afd447..3d2b0ce8 100644 --- a/lib/lang/ka.js +++ b/lib/lang/ka.js @@ -106,6 +106,6 @@ module.exports = { if(!str.endsWith(".")) { str += "."; } - return str; + return str; }, }; diff --git a/lib/lang/ko.js b/lib/lang/ko.js index 57174bb1..643c0d3f 100644 --- a/lib/lang/ko.js +++ b/lib/lang/ko.js @@ -1,7 +1,7 @@ "use strict"; function join_with_shared_prefix(a, b, joiner) { - var i = 0; + let i = 0; while(i !== a.length && i !== b.length && diff --git a/lib/lang/kw.js b/lib/lang/kw.js index c89640ad..5122c311 100644 --- a/lib/lang/kw.js +++ b/lib/lang/kw.js @@ -1,25 +1,26 @@ "use strict"; function in_the(period) { - var f=period.charAt(0); - var n="123456789"; - if (period==="myttin" || period==="dohajydh" || period==="gorthugher" || period==="nos") - return " y\'n " + period; - else if (period==="an dohajydh ma" || period==="an nos ma") - return " y\'n " + period.slice(3); - else if (n.indexOf(f)!=-1) + if(period === "myttin" || period === "dohajydh" || period === "gorthugher" || period === "nos") { + return " y'n " + period; + } + if(period === "an dohajydh ma" || period === "an nos ma") { + return " y'n " + period.slice(3); + } + if("123456789".indexOf(period.charAt(0)) !== -1) { return " yn " + period; - else - return " " + period; + } + return " " + period; } function until_the(period) { - if (period==="myttin" || period==="dohajydh" || period==="gorthugher" || period==="nos") - return " bys y\'n " + period; - else if (period==="an dohajydh ma" || period==="an nos ma") - return " bys y\'n " + period.slice(3); - else - return " bys yn " + period; + if(period === "myttin" || period === "dohajydh" || period === "gorthugher" || period === "nos") { + return " bys y'n " + period; + } + if(period === "an dohajydh ma" || period === "an nos ma") { + return " bys y'n " + period.slice(3); + } + return " bys yn " + period; } module.exports = { @@ -100,14 +101,15 @@ module.exports = { "centimeters": "$1 cm.", "less-than": "le ages $1", "and": function(a, b) { - var andy=a.indexOf(",") !== -1 ? ", ha" : " ha"; - if (b.charAt(0)=="a" || b.charAt(0)=="e" || b.charAt(0)=="i" || b.charAt(0)=='o' || b.charAt(0)=="u") + let andy = a.indexOf(",") !== -1 ? ", ha" : " ha"; + if(b.charAt(0) === "a" || b.charAt(0) === "e" || b.charAt(0) === "i" || b.charAt(0) === "o" || b.charAt(0) === "u") { andy = andy + "g"; + } return a + andy + " " + b; }, "through": function(a, b) { - return a + until_the(b);//" dres " + b; + return a + until_the(b); }, "with": "$1, gans $2", "range": "$1\u2013$2", @@ -122,10 +124,10 @@ module.exports = { return condition + " ow hedhi" + in_the(period); }, "starting-then-stopping-later": function(condition, period1, period2) { - return condition + " ow talleth" + in_the(period1) + ", ow hedhi "+period2+" diwettha"; + return condition + " ow talleth" + in_the(period1) + ", ow hedhi " + period2 + " diwettha"; }, "stopping-then-starting-later": function(condition, period1, period2) { - return condition + " ow hedhi" + in_the(period1) + ", ow tastalleth "+period2+" diwettha"; + return condition + " ow hedhi" + in_the(period1) + ", ow tastalleth " + period2 + " diwettha"; }, "for-day": "$1 dres oll an jydh", "starting": function(condition, period) { @@ -142,7 +144,7 @@ module.exports = { }, "during": function(condition, period) { return condition + in_the(period); - //"$1 y\'n $2" + // "$1 y\'n $2" }, "for-week": "$1 dres oll an seythun", "over-weekend": "$1 dres an bennseythun", @@ -150,9 +152,9 @@ module.exports = { "temperatures-rising": "tempredhow ow kressya dhe $1 $2", "temperatures-valleying": "tempredhow ow hedhi kodha dhe $1 $2", "temperatures-falling": "tempredhow ow kodha dhe $1 $2", - /* Capitalize the first letter of every word, except if that word is - * "and". (This is a very crude bastardization of proper English titling - * rules, but it is adequate for the purposes of this module.) */ + // Capitalize the first letter of every word, except if that word is + // "and". (This is a very crude bastardization of proper English titling + // rules, but it is adequate for the purposes of this module.) "title": function(str) { return str.replace( /\b(?:a(?!nd\b)|c(?!m\.)|i(?!n\.)|[^\Waci])/g, diff --git a/lib/lang/nl.js b/lib/lang/nl.js index 380aa55b..34023185 100644 --- a/lib/lang/nl.js +++ b/lib/lang/nl.js @@ -1,7 +1,7 @@ "use strict"; function join_with_shared_prefix(a, b, joiner) { - var i = 0; + let i = 0; while(i !== a.length && i !== b.length && @@ -90,7 +90,7 @@ module.exports = { "sunday": "op zondag", "monday": function(){ return weekdays(this, "maandag"); }, "tuesday": function(){ return weekdays(this, "dinsdag"); }, - "wednesday":function(){ return weekdays(this, "woensdag"); }, + "wednesday":function(){ return weekdays(this, "woensdag"); }, "thursday": function(){ return weekdays(this, "donderdag"); }, "friday": function(){ return weekdays(this, "vrijdag"); }, "saturday": function(){ return weekdays(this, "zaterdag"); }, @@ -130,11 +130,10 @@ module.exports = { if(this[1] === "starting") return "vanaf " + time + " " + condition; - else if(this[1] === "and") + if(this[1] === "and") return time + " " + condition; - else - return condition + " " + time; + return condition + " " + time; }, "until": "$1 tot $2", "until-starting-again": "$1 tot $2 en $3 weer opnieuw", @@ -143,11 +142,10 @@ module.exports = { if(this[1] === "and") return time + " " + condition; - else if(this[1] === "with") + if(this[1] === "with") return condition + " " + time; - else - return condition + " gedurende " + time; + return condition + " gedurende " + time; }, "for-week": "de hele week $1", "over-weekend": "$1 dit weekend", @@ -155,9 +153,9 @@ module.exports = { "temperatures-rising": "temperaturen stijgend tot $1 $2", "temperatures-valleying": "een minimum temperatuur van $1 $2", "temperatures-falling": "temperaturen dalend tot $1 $2", - /* Capitalize the first letter of every word, except if that word is - * "and". (This is a very crude bastardization of proper English titling - * rules, but it is adequate for the purposes of this module.) */ + // Capitalize the first letter of every word, except if that word is + // "and". (This is a very crude bastardization of proper English titling + // rules, but it is adequate for the purposes of this module.) "title": function(str) { return str.charAt(0).toUpperCase() + str.slice(1); }, diff --git a/lib/lang/no.js b/lib/lang/no.js index 4b813d36..2596fb5a 100644 --- a/lib/lang/no.js +++ b/lib/lang/no.js @@ -1,25 +1,27 @@ "use strict"; function join_with_shared_prefix(a, b, joiner) { - var m = a, - i = 0, - j; + let i = 0; - while(i !== m.length && + while(i !== a.length && i !== b.length && - m.charCodeAt(i) === b.charCodeAt(i)) + a.charCodeAt(i) === b.charCodeAt(i)) ++i; - while(i && m.charCodeAt(i - 1) !== 32) + while(i && a.charCodeAt(i - 1) !== 32) --i; return a + joiner + b.slice(i); } function strip_prefix(period) { - return period.slice(0, 12) === "över natten" ? period.slice(5) : - period.slice(0, 6) === "under " ? period.slice(6) : - period; + if(period.slice(0, 12) === "över natten ") { + return period.slice(12); + } + if(period.slice(0, 6) === "under ") { + return period.slice(6); + } + return period; } module.exports = { @@ -120,15 +122,13 @@ module.exports = { "for-day": "$1 i løpet av dagen", "starting": "$1 som starter $2", "until": function(condition, period) { - return condition + " fram til " + strip_prefix(period); + return condition + " fram til " + strip_prefix(period); }, "until-starting-again": function(condition, a, b) { - return condition + " fram til " + strip_prefix(a) + - ", som starter igjen " + b; + return condition + " fram til " + strip_prefix(a) + ", som starter igjen " + b; }, "starting-continuing-until": function(condition, a, b) { - return condition + " som starter " + a + ", fortsetter fram til " + - strip_prefix(b); + return condition + " som starter " + a + ", fortsetter fram til " + strip_prefix(b); }, "during": "$1 $2", "for-week": "$1 i løpet av uken", diff --git a/lib/lang/pl.js b/lib/lang/pl.js index 51d2cb0a..6ca62436 100644 --- a/lib/lang/pl.js +++ b/lib/lang/pl.js @@ -1,22 +1,27 @@ "use strict"; function join_with_shared_prefix(a, b, joiner) { - var m = a, - n = b, - i = 0, - j; + let m = a; + let n = b; + let i = 0; + if(m === "we wtorek") m = "w wtorek"; + if(n === "we wtorek") n = "w wtorek"; + while(i !== m.length && i !== n.length && m.charCodeAt(i) === n.charCodeAt(i)) ++i; + while(i && m.charCodeAt(i - 1) !== 32) --i; + if(i === 2 && b === "we wtorek") i = 3; + return a + joiner + b.slice(i); } @@ -53,8 +58,8 @@ function genitive_form(a) { case "w przyszłą niedzielę": return "przyszłej niedzieli"; default: - return a; - } + return a; + } } module.exports = { @@ -135,21 +140,21 @@ module.exports = { "centimeters": "$1 cm", "less-than": "mniej niż $1", "and": function(a, b) { - var times = ["w poniedziałek","we wtorek","w środę","w czwartek","w piątek", - "w sobotę","w niedzielę","rano","po południu","wieczorem","nocą", - "przed południem","późnym popołudniem","późnym wieczorem","późno w nocy", - "dzisiaj","jutro","jutro rano","jutro po południu","jutro wieczorem", - "w przyszły poniedziałek","w przyszły wtorek","w przyszłą środę", - "w przyszły czwartek","w przyszły piątek","w przyszłą sobotę", - "w przyszłą niedzielę"]; + const times = ["w poniedziałek","we wtorek","w środę","w czwartek","w piątek", + "w sobotę","w niedzielę","rano","po południu","wieczorem","nocą", + "przed południem","późnym popołudniem","późnym wieczorem","późno w nocy", + "dzisiaj","jutro","jutro rano","jutro po południu","jutro wieczorem", + "w przyszły poniedziałek","w przyszły wtorek","w przyszłą środę", + "w przyszły czwartek","w przyszły piątek","w przyszłą sobotę", + "w przyszłą niedzielę"]; return join_with_shared_prefix( a, b, a.indexOf(",")<0 && times.indexOf(a)>-1 && times.indexOf(b)>-1 ? " i " : ", " ); }, - "through": function(a, b) { - return 'od ' + genitive_form(a) + ' do ' + genitive_form(b); + "through": function(a, b) { + return "od " + genitive_form(a) + " do " + genitive_form(b); }, "with": "$1, $2", "range": "$1\u2013$2", @@ -164,15 +169,15 @@ module.exports = { "for-day": "$1 w ciągu dnia", "starting": "$2 $1", "until": function(condition, period) { - var lstr = (condition.indexOf("opady") > -1) ? ", ustaną " : ", ustanie "; + const lstr = (condition.indexOf("opady") > -1) ? ", ustaną " : ", ustanie "; return condition + lstr + period; }, "until-starting-again": function(condition, a, b) { - var lstr = (condition.indexOf("opady") > -1) ? ", ustaną " : ", ustanie "; + const lstr = (condition.indexOf("opady") > -1) ? ", ustaną " : ", ustanie "; return condition + lstr + a + ", " + b + " ponownie " + condition; }, "starting-continuing-until": function(condition, a, b) { - var lstr = (condition.indexOf("opady") > -1) ? ", skończą" : ", skończy"; + const lstr = (condition.indexOf("opady") > -1) ? ", skończą" : ", skończy"; return a + " " + condition + lstr + " się " + b; }, "during": "$2 $1", diff --git a/lib/lang/pt.js b/lib/lang/pt.js index 9ee8f367..347d5a99 100644 --- a/lib/lang/pt.js +++ b/lib/lang/pt.js @@ -1,16 +1,14 @@ "use strict"; function join_with_shared_prefix(a, b, joiner) { - var m = a, - i = 0, - j; + let i = 0; - while(i !== m.length && + while(i !== a.length && i !== b.length && - m.charCodeAt(i) === b.charCodeAt(i)) + a.charCodeAt(i) === b.charCodeAt(i)) ++i; - while(i && m.charCodeAt(i - 1) !== 32) + while(i && a.charCodeAt(i - 1) !== 32) --i; return a + joiner + b.slice(i); diff --git a/lib/lang/ro.js b/lib/lang/ro.js index f80db4e0..d0b65634 100644 --- a/lib/lang/ro.js +++ b/lib/lang/ro.js @@ -1,8 +1,7 @@ "use strict"; function join_with_shared_prefix(a, b, joiner) { - var i = 0, - j; + let i = 0; while(i !== a.length && i !== b.length && @@ -87,16 +86,18 @@ module.exports = { "next-friday": "vinerea viitoare", "next-saturday": "sâmbăta viitoare", "minutes": function(min) { - /* Special formatting for Romanian numbering. - * Working correctly only up to 100. - */ - if (min == 1) { + min = Math.round(min); + + // Special formatting for Romanian numbering. + // Working correctly only up to 100. + if(min < 2) { return "1 minut"; - } else if (min != 1 && min < 20) { - return min +" minute"; - } else { - return min + " de minute"; } + if(min < 20) { + return min + " minute"; + } + return min + " de minute"; + }, "fahrenheit": "$1\u00B0F", "celsius": "$1\u00B0C", @@ -135,13 +136,11 @@ module.exports = { "temperatures-rising": "temperaturi ce urcă până la $1 $2", "temperatures-valleying": "temperaturi ce ating un minim de $1 $2", "temperatures-falling": "temperaturi ce coboară până la $1 $2", - /* Capitalize the first letter of every word, except if that word is "et". - * - * Fun fact: JavaScript regex's "\w" and "\b" don't recognize accented - * characters (such as ș or ț) and so the neat trick used in the English - * version of the "title" function can't be used here. (Conveniently, - * anyway.) - */ + // Capitalize the first letter of every word, except if that word is "et". + // Fun fact: JavaScript regex's "\w" and "\b" don't recognize accented + // characters (such as ș or ț) and so the neat trick used in the English + // version of the "title" function can't be used here. (Conveniently, + // anyway.) "title": function(str) { return str.replace(/\S+/g, function(word) { return word === "și" || word === "de" || word.search(/in\./) > -1 || word.search(/cm\./) > -1 ? diff --git a/lib/lang/ru.js b/lib/lang/ru.js index 2bb3e6f6..508188cd 100644 --- a/lib/lang/ru.js +++ b/lib/lang/ru.js @@ -1,16 +1,14 @@ "use strict"; function join_with_shared_prefix(a, b, joiner) { - var m = a, - i = 0, - j; + let i = 0; - while(i !== m.length && + while(i !== a.length && i !== b.length && - m.charCodeAt(i) === b.charCodeAt(i)) + a.charCodeAt(i) === b.charCodeAt(i)) ++i; - while(i && m.charCodeAt(i - 1) !== 32) + while(i && a.charCodeAt(i - 1) !== 32) --i; return a + joiner + b.slice(i); diff --git a/lib/lang/sk.js b/lib/lang/sk.js index d195d18d..c971eac1 100644 --- a/lib/lang/sk.js +++ b/lib/lang/sk.js @@ -1,246 +1,239 @@ -"use strict"; - -function remove_prefix_and_use_genitive(a) { - switch(a) { - case "dnes ráno": - return "dnešného rána"; - case "dnes dopoludnia": - return "dnešného dopoludnia"; - case "dnes popoludní": - return "dnešného popoludnia"; - case "dnes podvečer": - return "dnešného podvečera"; - case "dnes večer": - return "dnešného večera"; - case "dnes neskoro večer": - return "dnešného neskorého večera"; - case "dnes v noci": - return "dnešnej noci"; - case "dnes neskoro v noci": - return "dnešnej neskorej noci"; - case "zajtra ráno": - return "zajtrajšieho rána"; - case "zajtra popoludní": - return "zajtrajšieho popoludnia"; - case "zajtra večer": - return "zajtrajšieho večera"; - case "zajtra v noci": - return "zajtrajšej noci"; - case "ráno": - return "rána"; - case "popoludní": - return "popoludnia"; - case "večer": - return "večera"; - case "v noci": - return "noci"; - case "v pondelok": - return "pondelka"; - case "v utorok": - return "utorka"; - case "v stredu": - return "stredy"; - case "vo štvrtok": - return "štvrtka"; - case "v piatok": - return "piatka"; - case "v sobotu": - return "soboty"; - case "v nedeľu": - return "nedele"; - case "budúci pondelok": - return "budúceho pondelka"; - case "budúci utorok": - return "budúceho utorka"; - case "budúca streda": - return "budúcej stredy"; - case "budúci štvrtok": - return "budúceho štvrtka"; - case "budúci piatok": - return "budúceho piatka"; - case "budúca sobota": - return "budúcej soboty"; - case "budúca nedeľa": - return "budúcej nedele"; - default: - return a; - } -} - -function join_with_shared_prefix(a, b, joiner) { - var m = a, - i = 0, - j; - - /* HACK: This gets around "today through on Tuesday" or cases like it, which - * are incorrect in English. */ - if(m === "today" || m === "tomorrow") - m = "on " + m; - - while(i !== m.length && - i !== b.length && - m.charCodeAt(i) === b.charCodeAt(i)) - ++i; - - while(i && m.charCodeAt(i - 1) !== 32) - --i; - - return a + joiner + b.slice(i); -} - -module.exports = { - "clear": "jasno", - "no-precipitation": "bez zrážok", - "mixed-precipitation": "zmiešané zrážky", - "possible-very-light-precipitation": "možnosť veľmi slabých zrážok", - "very-light-precipitation": "veľmi slabé zrážky", - "possible-light-precipitation": "možnosť slabých zrážok", - "light-precipitation": "slabé zrážky", - "medium-precipitation": "zrážky", - "heavy-precipitation": "silné zrážky", - "possible-very-light-rain": "možnosť mrholenia", - "very-light-rain": "mrholenie", - "possible-light-rain": "možnosť slabého dažďa", - "light-rain": "slabý dážď", - "medium-rain": "dážď", - "heavy-rain": "vydatný dážď", - "possible-very-light-sleet": "možnosť slabého dažďa so snehom", - "very-light-sleet": "slabý dážď so snehom", - "possible-light-sleet": "možnosť slabého dažďa so snehom", - "light-sleet": "slabý dážď so snehom", - "medium-sleet": "dážď so snehom", - "heavy-sleet": "vydatný dážď so snehom", - "possible-very-light-snow": "možnosť slabého sneženia", - "very-light-snow": "slabé sneženie", - "possible-light-snow": "možnosť slabého sneženia", - "light-snow": "slabé sneženie", - "medium-snow": "sneženie", - "heavy-snow": "vydatné sneženie", - "possible-thunderstorm": "možnosť búrok", - "thunderstorm": "búrky", - "light-wind": "slabý vietor", - "medium-wind": "veterno", - "heavy-wind": "silný vietor", - "low-humidity": "nízka vlhkosť", - "high-humidity": "vysoká vlhkosť", - "fog": "hmlisto", - "light-clouds": "čiastočne zamračené", - "medium-clouds": "prevažne zamračené", - "heavy-clouds": "zamračené", - "today-morning": "dnes ráno", - "later-today-morning": "dnes dopoludnia", - "today-afternoon": "dnes popoludní", - "later-today-afternoon": "dnes podvečer", - "today-evening": "dnes večer", - "later-today-evening": "dnes neskoro večer", - "today-night": "dnes v noci", - "later-today-night": "dnes neskoro v noci", - "tomorrow-morning": "zajtra ráno", - "tomorrow-afternoon": "zajtra popoludní", - "tomorrow-evening": "zajtra večer", - "tomorrow-night": "zajtra v noci", - "morning": "ráno", - "afternoon": "popoludní", - "evening": "večer", - "night": "v noci", - "today": "dnes", - "tomorrow": "zajtra", - "sunday": "v nedeľu", - "monday": "v pondelok", - "tuesday": "v utorok", - "wednesday": "v stredu", - "thursday": "vo štvrtok", - "friday": "v piatok", - "saturday": "v sobotu", - "next-sunday": "budúcu nedeľu", - "next-monday": "budúci pondelok", - "next-tuesday": "budúci utorok", - "next-wednesday": "budúcu stredu", - "next-thursday": "budúci štvrtok", - "next-friday": "budúci piatok", - "next-saturday": "budúcu sobotu", - "minutes": "$1 min.", - "fahrenheit": "$1°F", - "celsius": "$1°C", - "inches": "$1 in", - "centimeters": "$1 cm", - "less-than": "menej ako $1", - "and": function(a, b) { - return join_with_shared_prefix( - a, - b, - " a " - ); - }, - "through": function(a, b) { - return "od " + remove_prefix_and_use_genitive(a) + " do " + remove_prefix_and_use_genitive(b); - }, - "with": "$1, $2", - "range": "$1-$2", - "parenthetical": function(a, b) { - return a + " (" + b + (a === "zmiešané zrážky" ? " snehu)" : ")"); - }, - "for-hour": "$1 hodinu", - "starting-in": "$1 o $2", - "stopping-in": "$1 skončí o $2", - "starting-then-stopping-later": "$1 o $2, skončí o $3 neskôr", - "stopping-then-starting-later": "$1 skončí o $2 a začne znovu o $3 neskôr", - "for-day": "Počas dňa $1", - "starting": function(a, b) { - return "od " + remove_prefix_and_use_genitive(b) + " " + a; - }, - "until": function(condition, period) { - return condition + " až do " + remove_prefix_and_use_genitive(period); - }, - "until-starting-again": function(condition, a, b) { - var starting = ""; - if(condition.endsWith("zrážky")) - starting = ", ktoré začnú znovu "; - else if(condition.endsWith("dážď") || condition.endsWith("dážď so snehom") || condition.endsWith("vietor")) - starting = ", ktorý začne znovu "; - else if(condition.endsWith("sneženie") || condition.endsWith("mrholenie")) - starting = ", ktoré začne znovu "; - else if(condition.endsWith("vlhkosť")) - starting = ", ktorá začne znovu "; - else if(condition.endsWith("zamračené") || condition.endsWith("hmlisto")) - starting = "a začne znovu "; - - return condition + " až do " + remove_prefix_and_use_genitive(a) + starting + b; - }, - "starting-continuing-until": function(condition, a, b) { - var continuing = ""; - if(condition.endsWith("zrážky")) - continuing = ", ktoré pretrvajú až do "; - else if(condition.endsWith("dážď") || condition.endsWith("dážď so snehom") || condition.endsWith("vietor")) - continuing = ", ktorý pretrvá až do "; - else if(condition.endsWith("sneženie") || condition.endsWith("mrholenie")) - continuing = ", ktoré pretrvá až do "; - else if(condition.endsWith("vlhkosť")) - continuing = ", ktorá pretrvá až do "; - else if(condition.endsWith("zamračené") || condition.endsWith("hmlisto")) - continuing = " a pretrvá až do "; - return "od " + remove_prefix_and_use_genitive(a) + " " + condition + continuing + remove_prefix_and_use_genitive(b); - }, - "during": "$2 $1", - "for-week": "$1 počas týždňa", - "over-weekend": "$1 cez víkend", - "temperatures-peaking": "$2 s teplotným maximom $1", - "temperatures-rising": "$2 s teplotami stúpajúcimi k $1", - "temperatures-valleying": "$2 s teplotným minimom $1", - "temperatures-falling": "$2 s teplotami klesajúcimi k $1", - /* Capitalize the first letter of first word. */ - "title": function(str) { - return str.charAt(0).toUpperCase() + str.slice(1); - }, - /* Capitalize the first word of the sentence and end with a period. */ - "sentence": function(str) { - /* Capitalize. */ - str = str.charAt(0).toUpperCase() + str.slice(1); - - /* Add a period if there isn't already one. */ - if(str.charAt(str.length - 1) !== ".") - str += "."; - - return str; - }, -}; +"use strict"; + +function remove_prefix_and_use_genitive(a) { + switch(a) { + case "dnes ráno": + return "dnešného rána"; + case "dnes dopoludnia": + return "dnešného dopoludnia"; + case "dnes popoludní": + return "dnešného popoludnia"; + case "dnes podvečer": + return "dnešného podvečera"; + case "dnes večer": + return "dnešného večera"; + case "dnes neskoro večer": + return "dnešného neskorého večera"; + case "dnes v noci": + return "dnešnej noci"; + case "dnes neskoro v noci": + return "dnešnej neskorej noci"; + case "zajtra ráno": + return "zajtrajšieho rána"; + case "zajtra popoludní": + return "zajtrajšieho popoludnia"; + case "zajtra večer": + return "zajtrajšieho večera"; + case "zajtra v noci": + return "zajtrajšej noci"; + case "ráno": + return "rána"; + case "popoludní": + return "popoludnia"; + case "večer": + return "večera"; + case "v noci": + return "noci"; + case "v pondelok": + return "pondelka"; + case "v utorok": + return "utorka"; + case "v stredu": + return "stredy"; + case "vo štvrtok": + return "štvrtka"; + case "v piatok": + return "piatka"; + case "v sobotu": + return "soboty"; + case "v nedeľu": + return "nedele"; + case "budúci pondelok": + return "budúceho pondelka"; + case "budúci utorok": + return "budúceho utorka"; + case "budúca streda": + return "budúcej stredy"; + case "budúci štvrtok": + return "budúceho štvrtka"; + case "budúci piatok": + return "budúceho piatka"; + case "budúca sobota": + return "budúcej soboty"; + case "budúca nedeľa": + return "budúcej nedele"; + default: + return a; + } +} + +function join_with_shared_prefix(a, b, joiner) { + let i = 0; + + while(i !== a.length && + i !== b.length && + a.charCodeAt(i) === b.charCodeAt(i)) + ++i; + + while(i && a.charCodeAt(i - 1) !== 32) + --i; + + return a + joiner + b.slice(i); +} + +module.exports = { + "clear": "jasno", + "no-precipitation": "bez zrážok", + "mixed-precipitation": "zmiešané zrážky", + "possible-very-light-precipitation": "možnosť veľmi slabých zrážok", + "very-light-precipitation": "veľmi slabé zrážky", + "possible-light-precipitation": "možnosť slabých zrážok", + "light-precipitation": "slabé zrážky", + "medium-precipitation": "zrážky", + "heavy-precipitation": "silné zrážky", + "possible-very-light-rain": "možnosť mrholenia", + "very-light-rain": "mrholenie", + "possible-light-rain": "možnosť slabého dažďa", + "light-rain": "slabý dážď", + "medium-rain": "dážď", + "heavy-rain": "vydatný dážď", + "possible-very-light-sleet": "možnosť slabého dažďa so snehom", + "very-light-sleet": "slabý dážď so snehom", + "possible-light-sleet": "možnosť slabého dažďa so snehom", + "light-sleet": "slabý dážď so snehom", + "medium-sleet": "dážď so snehom", + "heavy-sleet": "vydatný dážď so snehom", + "possible-very-light-snow": "možnosť slabého sneženia", + "very-light-snow": "slabé sneženie", + "possible-light-snow": "možnosť slabého sneženia", + "light-snow": "slabé sneženie", + "medium-snow": "sneženie", + "heavy-snow": "vydatné sneženie", + "possible-thunderstorm": "možnosť búrok", + "thunderstorm": "búrky", + "light-wind": "slabý vietor", + "medium-wind": "veterno", + "heavy-wind": "silný vietor", + "low-humidity": "nízka vlhkosť", + "high-humidity": "vysoká vlhkosť", + "fog": "hmlisto", + "light-clouds": "čiastočne zamračené", + "medium-clouds": "prevažne zamračené", + "heavy-clouds": "zamračené", + "today-morning": "dnes ráno", + "later-today-morning": "dnes dopoludnia", + "today-afternoon": "dnes popoludní", + "later-today-afternoon": "dnes podvečer", + "today-evening": "dnes večer", + "later-today-evening": "dnes neskoro večer", + "today-night": "dnes v noci", + "later-today-night": "dnes neskoro v noci", + "tomorrow-morning": "zajtra ráno", + "tomorrow-afternoon": "zajtra popoludní", + "tomorrow-evening": "zajtra večer", + "tomorrow-night": "zajtra v noci", + "morning": "ráno", + "afternoon": "popoludní", + "evening": "večer", + "night": "v noci", + "today": "dnes", + "tomorrow": "zajtra", + "sunday": "v nedeľu", + "monday": "v pondelok", + "tuesday": "v utorok", + "wednesday": "v stredu", + "thursday": "vo štvrtok", + "friday": "v piatok", + "saturday": "v sobotu", + "next-sunday": "budúcu nedeľu", + "next-monday": "budúci pondelok", + "next-tuesday": "budúci utorok", + "next-wednesday": "budúcu stredu", + "next-thursday": "budúci štvrtok", + "next-friday": "budúci piatok", + "next-saturday": "budúcu sobotu", + "minutes": "$1 min.", + "fahrenheit": "$1°F", + "celsius": "$1°C", + "inches": "$1 in", + "centimeters": "$1 cm", + "less-than": "menej ako $1", + "and": function(a, b) { + return join_with_shared_prefix( + a, + b, + " a " + ); + }, + "through": function(a, b) { + return "od " + remove_prefix_and_use_genitive(a) + " do " + remove_prefix_and_use_genitive(b); + }, + "with": "$1, $2", + "range": "$1-$2", + "parenthetical": function(a, b) { + return a + " (" + b + (a === "zmiešané zrážky" ? " snehu)" : ")"); + }, + "for-hour": "$1 hodinu", + "starting-in": "$1 o $2", + "stopping-in": "$1 skončí o $2", + "starting-then-stopping-later": "$1 o $2, skončí o $3 neskôr", + "stopping-then-starting-later": "$1 skončí o $2 a začne znovu o $3 neskôr", + "for-day": "Počas dňa $1", + "starting": function(a, b) { + return "od " + remove_prefix_and_use_genitive(b) + " " + a; + }, + "until": function(condition, period) { + return condition + " až do " + remove_prefix_and_use_genitive(period); + }, + "until-starting-again": function(condition, a, b) { + let starting = ""; + if(condition.endsWith("zrážky")) + starting = ", ktoré začnú znovu "; + else if(condition.endsWith("dážď") || condition.endsWith("dážď so snehom") || condition.endsWith("vietor")) + starting = ", ktorý začne znovu "; + else if(condition.endsWith("sneženie") || condition.endsWith("mrholenie")) + starting = ", ktoré začne znovu "; + else if(condition.endsWith("vlhkosť")) + starting = ", ktorá začne znovu "; + else if(condition.endsWith("zamračené") || condition.endsWith("hmlisto")) + starting = "a začne znovu "; + + return condition + " až do " + remove_prefix_and_use_genitive(a) + starting + b; + }, + "starting-continuing-until": function(condition, a, b) { + let continuing = ""; + if(condition.endsWith("zrážky")) + continuing = ", ktoré pretrvajú až do "; + else if(condition.endsWith("dážď") || condition.endsWith("dážď so snehom") || condition.endsWith("vietor")) + continuing = ", ktorý pretrvá až do "; + else if(condition.endsWith("sneženie") || condition.endsWith("mrholenie")) + continuing = ", ktoré pretrvá až do "; + else if(condition.endsWith("vlhkosť")) + continuing = ", ktorá pretrvá až do "; + else if(condition.endsWith("zamračené") || condition.endsWith("hmlisto")) + continuing = " a pretrvá až do "; + return "od " + remove_prefix_and_use_genitive(a) + " " + condition + continuing + remove_prefix_and_use_genitive(b); + }, + "during": "$2 $1", + "for-week": "$1 počas týždňa", + "over-weekend": "$1 cez víkend", + "temperatures-peaking": "$2 s teplotným maximom $1", + "temperatures-rising": "$2 s teplotami stúpajúcimi k $1", + "temperatures-valleying": "$2 s teplotným minimom $1", + "temperatures-falling": "$2 s teplotami klesajúcimi k $1", + /* Capitalize the first letter of first word. */ + "title": function(str) { + return str.charAt(0).toUpperCase() + str.slice(1); + }, + /* Capitalize the first word of the sentence and end with a period. */ + "sentence": function(str) { + /* Capitalize. */ + str = str.charAt(0).toUpperCase() + str.slice(1); + + /* Add a period if there isn't already one. */ + if(str.charAt(str.length - 1) !== ".") + str += "."; + + return str; + }, +}; diff --git a/lib/lang/sl.js b/lib/lang/sl.js index d872d373..4a35a4ed 100644 --- a/lib/lang/sl.js +++ b/lib/lang/sl.js @@ -1,16 +1,14 @@ "use strict"; function join_with_shared_prefix(a, b, joiner) { - var m = a, - i = 0, - j; + let i = 0; - while(i !== m.length && + while(i !== a.length && i !== b.length && - m.charCodeAt(i) === b.charCodeAt(i)) + a.charCodeAt(i) === b.charCodeAt(i)) ++i; - while(i && m.charCodeAt(i - 1) !== 32) + while(i && a.charCodeAt(i - 1) !== 32) --i; return a + joiner + b.slice(i); @@ -80,10 +78,10 @@ module.exports = { "saturday": "v soboto", "next-sunday": "naslednjo nedeljo", "next-monday": "naslednji ponedeljek", - "next-tuesday": "naslednji torek", - "next-wednesday": "naslednjo sredo", - "next-thursday": "naslednji četrtek", - "next-friday": "naslednji petek", + "next-tuesday": "naslednji torek", + "next-wednesday": "naslednjo sredo", + "next-thursday": "naslednji četrtek", + "next-friday": "naslednji petek", "next-saturday": "naslednjo soboto", "minutes": "$1 min.", "fahrenheit": "$1\u00B0F", diff --git a/lib/lang/sr.js b/lib/lang/sr.js index ecfc3b88..6dc178cc 100644 --- a/lib/lang/sr.js +++ b/lib/lang/sr.js @@ -1,16 +1,14 @@ "use strict"; function join_with_shared_prefix(a, b, joiner) { - var m = a, - i = 0, - j; + let i = 0; - while(i !== m.length && + while(i !== a.length && i !== b.length && - m.charCodeAt(i) === b.charCodeAt(i)) + a.charCodeAt(i) === b.charCodeAt(i)) ++i; - while(i && m.charCodeAt(i - 1) !== 32) + while(i && a.charCodeAt(i - 1) !== 32) --i; return a + joiner + b.slice(i); @@ -35,14 +33,14 @@ function time_var(time, pref, t) { default: return time + "ak"; } - case "nedelj": + case "nedelj": switch(pref) { - case "od": - case "do": - return "nedelje"; - case "u": - return "u nedelju"; - default: + case "od": + case "do": + return "nedelje"; + case "u": + return "u nedelju"; + default: return "nedelja"; } case "subot": @@ -50,10 +48,10 @@ function time_var(time, pref, t) { switch(pref) { case "od": case "do": - return time + "e"; + return time + "e"; case "u": - return "u " + time + "u"; - default: + return "u " + time + "u"; + default: return time + "u"; } case "noć": @@ -62,16 +60,16 @@ function time_var(time, pref, t) { "noća"; case "sutra noć": return (t[2] === "starting-continuing-until" || pref === "u")? - "tokom noći": + "tokom noći": "sutra noć"; case "kasnije noć": return (t[2] === "starting")? "kasnije tokom noći": "kasnije noć"; case "kasnije ovog jutra": return (t[1] === "during")? "kasnije tokom ovog jutra": - "kasnije ovog jutra"; + "kasnije ovog jutra"; default: return time; - }; + } } function check_condition(c) { @@ -83,7 +81,7 @@ function check_condition(c) { function get_prefix(a, t) { switch(a) { case "sred": - return " i " + return " i "; case "sutra ujutro": return (t[1] === "during" && t[2] === "and")? " i ": ", "; default: @@ -92,7 +90,7 @@ function get_prefix(a, t) { } module.exports = { - "clear": "vedro", + "clear": "vedro", "no-precipitation": "nema padavina", "mixed-precipitation": "različite padavine", "possible-very-light-precipitation": "moguće su veoma slabe padavine", @@ -119,14 +117,14 @@ module.exports = { "light-snow": "sitan sneg", "medium-snow": "sneg", "heavy-snow": "jak sneg", - "light-wind": "vetrovito", + "light-wind": "vetrovito", "medium-wind": "vetrovito", "heavy-wind": "opasno vetrovito", "low-humidity": "suvo", "high-humidity": "vlažno", "fog": "maglovito", "light-clouds": "mestimično oblačno", - "medium-clouds": "pretežno oblačno", + "medium-clouds": "pretežno oblačno", "heavy-clouds": "oblačno", "today-morning": "ovog jutra", "later-today-morning": "kasnije ovog jutra", @@ -143,7 +141,7 @@ module.exports = { "morning": "ujutro", "afternoon": "popodne", "evening": "uveče", - "night": "noć", + "night": "noć", "today": "danas", "tomorrow": "sutra", "monday": "ponedelj", @@ -196,14 +194,12 @@ module.exports = { return condition + " do " + time_var(time, "", this); }, "until-starting-again": function(condition, until, again) { - return condition + " " + time_var(until, "do", this) + - " i opet počinje " + again; + return condition + " " + time_var(until, "do", this) + " i opet počinje " + again; }, "starting-continuing-until": function(condition, from, to) { - from = time_var(from, "", this); - to = time_var( to, "u", this); - return condition + " " + check_condition(condition) + " " + from + - ", nastaviće se " + to; + from = time_var(from, "", this); + to = time_var( to, "u", this); + return condition + " " + check_condition(condition) + " " + from + ", nastaviće se " + to; }, "during": function(condition, time) { time = time_var(time, "u", this); diff --git a/lib/lang/sv.js b/lib/lang/sv.js index 105075fb..8c200165 100644 --- a/lib/lang/sv.js +++ b/lib/lang/sv.js @@ -1,16 +1,14 @@ "use strict"; function join_with_shared_prefix(a, b, joiner) { - var m = a, - i = 0, - j; + let i = 0; - while(i !== m.length && + while(i !== a.length && i !== b.length && - m.charCodeAt(i) === b.charCodeAt(i)) + a.charCodeAt(i) === b.charCodeAt(i)) ++i; - while(i && m.charCodeAt(i - 1) !== 32) + while(i && a.charCodeAt(i - 1) !== 32) --i; return a + joiner + b.slice(i); @@ -18,13 +16,13 @@ function join_with_shared_prefix(a, b, joiner) { function strip_prefix(period) { return period.slice(0, 12) === "över natten" ? period.slice(5) : - period.slice(0, 6) === "under " ? period.slice(6) : - period; + period.slice(0, 6) === "under " ? period.slice(6) : + period; } function grammar(str) { - return str.replace(/på /gi, "under ") - .replace(/(ån|is|ns|rs|re|ör|ön)(dag)/gi, "$1dagen"); + return str.replace(/på /gi, "under "). + replace(/(ån|is|ns|rs|re|ör|ön)(dag)/gi, "$1dagen"); } module.exports = { @@ -91,13 +89,13 @@ module.exports = { "thursday": "på torsdag", "friday": "på fredag", "saturday": "på lördag", - "next-sunday": "nästa söndag", - "next-monday": "nästa måndag", - "next-tuesday": "nästa tisdag", - "next-wednesday": "nästa onsdag", - "next-thursday": "nästa torsdag", - "next-friday": "nästa fredag", - "next-saturday": "nästa lördag", + "next-sunday": "nästa söndag", + "next-monday": "nästa måndag", + "next-tuesday": "nästa tisdag", + "next-wednesday": "nästa onsdag", + "next-thursday": "nästa torsdag", + "next-friday": "nästa fredag", + "next-saturday": "nästa lördag", "minutes": "$1 min.", "fahrenheit": "$1\u00B0F", "celsius": "$1\u00B0C", @@ -128,12 +126,10 @@ module.exports = { return condition + " fram till " + strip_prefix(period); }, "until-starting-again": function(condition, a, b) { - return condition + " fram till " + strip_prefix(a) + - ", som startar igen " + b; + return condition + " fram till " + strip_prefix(a) + ", som startar igen " + b; }, "starting-continuing-until": function(condition, a, b) { - return condition + " som startar " + a + ", fortsätter fram till " + - strip_prefix(b); + return condition + " som startar " + a + ", fortsätter fram till " + strip_prefix(b); }, "during": "$1 $2", "for-week": "$1 under veckan", @@ -150,8 +146,8 @@ module.exports = { "temperatures-falling": function(a, b) { return "temperaturer som sjunker till " + a + " " + grammar(b); }, - /* Capitalize the first character in the word. - * We never titleize nor camelcase words in an sentence in Swedish. */ + // Capitalize the first character in the word. + // We never titleize nor camelcase words in an sentence in Swedish. "title": function(str) { /* Capitalize. */ str = str.charAt(0).toUpperCase() + str.slice(1); diff --git a/lib/lang/tet.js b/lib/lang/tet.js index 0c4ece47..300f5eda 100644 --- a/lib/lang/tet.js +++ b/lib/lang/tet.js @@ -1,7 +1,7 @@ "use strict"; function join_with_shared_prefix(a, b, joiner) { - var i = 0; + let i = 0; while(i !== a.length && i !== b.length && @@ -16,8 +16,8 @@ function join_with_shared_prefix(a, b, joiner) { function strip_prefix(period) { return period.slice(0, 9) === "iha kalan" ? period.slice(4) : - period.slice(0, 7) === "iha " ? period.slice(7) : - period; + period.slice(0, 7) === "iha " ? period.slice(7) : + period; } module.exports = { @@ -122,8 +122,7 @@ module.exports = { return condition + " to " + strip_prefix(a) + ", hahu fali " + b; }, "starting-continuing-until": function(condition, a, b) { - return condition + " hahu " + a + ", kontinua to " + - strip_prefix(b); + return condition + " hahu " + a + ", kontinua to " + strip_prefix(b); }, "during": "$1 $2", "for-week": "$1 durante semana ida", @@ -134,7 +133,7 @@ module.exports = { "temperatures-falling": "temperatur tun to $1 $2", "title": function(str) { return str.replace( - /(^|[\s\-])\w/g, + /(^|[\s-])\w/g, function(letter) { return letter.toUpperCase(); } diff --git a/lib/lang/tr.js b/lib/lang/tr.js index b138f62f..cd4701f2 100644 --- a/lib/lang/tr.js +++ b/lib/lang/tr.js @@ -1,19 +1,17 @@ "use strict"; -function join_with_shared_prefix(a,joiner1,b,joiner2) { - var m = a, - i = 0, - j; +function join_with_shared_prefix(a, joiner1, b, joiner2) { + let i = 0; - while(i !== m.length && + while(i !== a.length && i !== b.length && - m.charCodeAt(i) === b.charCodeAt(i)) + a.charCodeAt(i) === b.charCodeAt(i)) ++i; - while(i && m.charCodeAt(i - 1) !== 32) + while(i && a.charCodeAt(i - 1) !== 32) --i; - return a + joiner1 + b.slice(i)+joiner2; + return a + joiner1 + b.slice(i) + joiner2; } module.exports = { @@ -123,7 +121,7 @@ module.exports = { "temperatures-falling": "$2 sıcaklık $1'ye düşüyor", /* Capitalize the first letter of every word. */ "title": function(str) { - return str.charAt(0).toUpperCase() + str.slice(1); + return str.charAt(0).toUpperCase() + str.slice(1); }, /* Capitalize the first word of the sentence and end with a period. */ "sentence": function(str) { diff --git a/lib/lang/uk.js b/lib/lang/uk.js index 0ab70294..15dcbf96 100644 --- a/lib/lang/uk.js +++ b/lib/lang/uk.js @@ -1,16 +1,14 @@ "use strict"; function join_with_shared_prefix(a, b, joiner) { - var m = a, - i = 0, - j; + let i = 0; - while(i !== m.length && + while(i !== a.length && i !== b.length && - m.charCodeAt(i) === b.charCodeAt(i)) + a.charCodeAt(i) === b.charCodeAt(i)) ++i; - while(i && m.charCodeAt(i - 1) !== 32) + while(i && a.charCodeAt(i - 1) !== 32) --i; return a + joiner + b.slice(i); diff --git a/lib/lang/x-pig-latin.js b/lib/lang/x-pig-latin.js index e6f4ade7..88e095a2 100644 --- a/lib/lang/x-pig-latin.js +++ b/lib/lang/x-pig-latin.js @@ -1,12 +1,11 @@ "use strict"; function join_with_shared_prefix(a, b, joiner) { - var m = a, - i = 0, - j; + let m = a; + let i = 0; - /* HACK: This gets around "today through on Tuesday" or cases like it, which - * are incorrect in English. */ + // HACK: This gets around "today through on Tuesday" or cases like it, which + // are incorrect in English. if(m === "odaytay" || m === "omorrowtay") m = "onway " + m; @@ -29,7 +28,7 @@ function strip_prefix(period) { if(period.slice(0, 12) === "inway ethay ") { return period.slice(12); } - + return period; } @@ -147,9 +146,9 @@ module.exports = { "temperatures-rising": "emperaturestay isingray otay $1 $2", "temperatures-valleying": "emperaturestay ottomingbay outway atway $1 $2", "temperatures-falling": "emperaturestay allingfay otay $1 $2", - /* Capitalize the first letter of every word, except if that word is - * "and". (This is a very crude bastardization of proper English titling - * rules, but it is adequate for the purposes of this module.) */ + // Capitalize the first letter of every word, except if that word is + // "and". (This is a very crude bastardization of proper English titling + // rules, but it is adequate for the purposes of this module.) "title": function(str) { return str.replace( /\b(?:a(?!ndway\b)|[^\Wa])/g, diff --git a/test.js b/test.js index 5836e562..a04347c8 100644 --- a/test.js +++ b/test.js @@ -49,8 +49,8 @@ describe("translations", () => { }); it("should recursively apply function templates", () => { - /* Actually, a "meeple meeple bar" sounds like it'd be a pretty tasty - * candy treat. */ + // Actually, a "meeple meeple bar" sounds like it'd be a pretty tasty + // candy treat. assert.strictEqual( test.translate(["bar", 10, ["baz", 20, "foo"]]), "meeple meeple bar" @@ -106,7 +106,7 @@ describe("translations", () => { "glorp": function(a) { assert.deepEqual(this, ["foo", "neem", "glorp"]); return "Rope?"; - } + }, }); test.translate(["foo", "bar", ["baz", "quux"], ["neem", ["glorp", 42]]]); @@ -124,7 +124,7 @@ describe("translations", () => { it( "should translate " + JSON.stringify(source) + - " to " + JSON.stringify(summary), + " to " + JSON.stringify(summary), () => assert.strictEqual(translation.translate(source), summary) ); } diff --git a/test_cases/da.json b/test_cases/da.json index d1360ae4..73f710b0 100644 --- a/test_cases/da.json +++ b/test_cases/da.json @@ -247,4 +247,4 @@ "Kraftige regnbyger og tordenvejr": ["title", ["and", "heavy-rain", "thunderstorm"]] -} \ No newline at end of file +}