From d006c1fde9463b7c2f566356d917f623a41d3776 Mon Sep 17 00:00:00 2001 From: Jay LaPorte Date: Wed, 7 Feb 2018 16:23:24 -0500 Subject: [PATCH] 2.0 (#165) * Rename nb to no (until nynorsk is contributed, anyway) * Convert to Translate class, cleanup * Clean up tests * Clarify weekly summaries in en, fr #158 --- index.js | 3 +- lib/lang/ar.js | 16 ++- lib/lang/az.js | 4 +- lib/lang/be.js | 112 ++++++--------------- lib/lang/bg.js | 43 +++----- lib/lang/bs.js | 33 ++---- lib/lang/ca.js | 27 ++--- lib/lang/cs.js | 36 +++---- lib/lang/da.js | 8 +- lib/lang/de.js | 8 +- lib/lang/el.js | 8 +- lib/lang/en.js | 16 +-- lib/lang/es.js | 27 ++--- lib/lang/et.js | 8 +- lib/lang/fi.js | 8 +- lib/lang/fr.js | 16 +-- lib/lang/hr.js | 27 ++--- lib/lang/hu.js | 26 ++--- lib/lang/id.js | 8 +- lib/lang/is.js | 8 +- lib/lang/it.js | 12 ++- lib/lang/ja.js | 20 ++-- lib/lang/ka.js | 8 +- lib/lang/kw.js | 8 +- lib/lang/nl.js | 8 +- lib/lang/{nb.js => no.js} | 8 +- lib/lang/pl.js | 8 +- lib/lang/pt.js | 8 +- lib/lang/ro.js | 27 ++--- lib/lang/ru.js | 108 ++++++-------------- lib/lang/sk.js | 36 +++---- lib/lang/sl.js | 27 ++--- lib/lang/sr.js | 8 +- lib/lang/sv.js | 8 +- lib/lang/tet.js | 8 +- lib/lang/tr.js | 8 +- lib/lang/uk.js | 108 ++++++-------------- lib/lang/x-pig-latin.js | 16 +-- lib/lang/zh-tw.js | 5 +- lib/lang/zh.js | 5 +- lib/{template.js => translation.js} | 16 ++- test.js | 151 +++++++++++++--------------- test_cases/en.json | 10 +- test_cases/fr.json | 10 +- test_cases/{nb.json => no.json} | 0 45 files changed, 429 insertions(+), 644 deletions(-) rename lib/lang/{nb.js => no.js} (99%) rename lib/{template.js => translation.js} (90%) rename test_cases/{nb.json => no.json} (100%) diff --git a/index.js b/index.js index 1b52ab83..d986487f 100644 --- a/index.js +++ b/index.js @@ -1,11 +1,12 @@ "use strict"; const fs = require("fs"); 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); if(match) { - exports[match[1]] = require("./lib/lang/" + pathname); + exports[match[1]] = new Translation(Object.freeze(require("./lib/lang/" + pathname))); } } diff --git a/lib/lang/ar.js b/lib/lang/ar.js index 2069ff21..52f078fa 100644 --- a/lib/lang/ar.js +++ b/lib/lang/ar.js @@ -1,3 +1,4 @@ +"use strict"; function join(a, b, joiner) { return (a.slice(0, 4) === "يوم " && b.slice(0, 4) === "يوم " && joiner === " و ") @@ -11,8 +12,8 @@ function strip_prefix(period) { period; } -module.exports = require("../template")({ - "clear": "صافِ", +module.exports = { + "clear": "صافِ", "no-precipitation": "لا أمطار", "mixed-precipitation": "هطول أمطار وثلوج", "possible-very-light-precipitation": "إحتمالية هطول أمطار خفيفة", @@ -122,11 +123,6 @@ module.exports = require("../template")({ "temperatures-rising": "درجات حرارة ترتفع حتى $1 $2", "temperatures-valleying": "انخفاض درجات الحرارة لأدنى مستوى لها عند $1 $2", "temperatures-falling": "درجات حرارة تنخفض حتى $1 $2", - "title": function(str) { - return str; - }, - "sentence": function(str) { - return str; - } - -}); \ No newline at end of file + "title": "$1", + "sentence": "$1", +}; diff --git a/lib/lang/az.js b/lib/lang/az.js index 87192460..8c5f7173 100644 --- a/lib/lang/az.js +++ b/lib/lang/az.js @@ -1,6 +1,6 @@ "use strict"; -module.exports = require("../template")({ +module.exports = { "clear": "buludsuz", "no-precipitation": "yağmursuz", "mixed-precipitation": "qarışıq yağış", @@ -119,4 +119,4 @@ module.exports = require("../template")({ return str; }, -}); +}; diff --git a/lib/lang/be.js b/lib/lang/be.js index e48fe2e1..2a4a7f27 100644 --- a/lib/lang/be.js +++ b/lib/lang/be.js @@ -1,3 +1,5 @@ +"use strict"; + function join_with_shared_prefix(a, b, joiner) { var m = a, i = 0, @@ -14,87 +16,37 @@ function join_with_shared_prefix(a, b, joiner) { return a + joiner + b.slice(i); } -function time2(time) -{ +function time2(time) { switch(time) { - case "раніцай": - time = "раніцы"; - break; - case "днём": - time = "сярэдзіны дня"; - break; - case "вечарам": - time = "вечара"; - break; - case "ноччу": - time = "ночы"; - break; - case "сёння ранкам": - time="сённяшняй раніцы"; - break; - case "сёння позняй раніцай": - time="сённяшняй позняй раніцы"; - break; - case "сёння днём": - time="сярэдзіны дня"; - break; - case "сёння познім днём": - time="сённяшняга позняга дня"; - break; - case "сёння ўвечары": - time="сённяшняга вечара"; - break; - case "сёння познім вечарам": - time="сённяшняга позняга вечара"; - break; - case "сёння ноччу": - time="сённяшняй ночы"; - break; - case "сёння позняй ноччу": - time="сённяшняй позняй ночы"; - break; - case "заўтра раніцай": - time="заўтрашняй раніцы"; - break; - case "заўтра днём": - time="заўтрашняга дня"; - break; - case "заўтра ўвечары": - time="заўтрашняга вечара"; - break; - case "ўвечары": - time="вечара"; - break; - case "заўтра ноччу": - time="заўтрашняй ночы"; - break; - case "у нядзелю": - time="нядзелі"; - break; - case "у панядзелак": - time="панядзелка"; - break; - case "у аўторак": - time="аўторка"; - break; - case "у сераду": - time="серады"; - break; - case "у чацвер": - time="чацвярга"; - break; - case "у пятніцу": - time="пятніцы"; - break; - case "у суботу": - time="суботы"; - break; - }; - - return time; + case "раніцай": return "раніцы"; + case "днём": return "сярэдзіны дня"; + case "вечарам": return "вечара"; + case "ноччу": return "ночы"; + case "сёння ранкам": return "сённяшняй раніцы"; + case "сёння позняй раніцай": return "сённяшняй позняй раніцы"; + case "сёння днём": return "сярэдзіны дня"; + case "сёння познім днём": return "сённяшняга позняга дня"; + case "сёння ўвечары": return "сённяшняга вечара"; + case "сёння познім вечарам": return "сённяшняга позняга вечара"; + case "сёння ноччу": return "сённяшняй ночы"; + case "сёння позняй ноччу": return "сённяшняй позняй ночы"; + case "заўтра раніцай": return "заўтрашняй раніцы"; + case "заўтра днём": return "заўтрашняга дня"; + case "заўтра ўвечары": return "заўтрашняга вечара"; + case "ўвечары": return "вечара"; + case "заўтра ноччу": return "заўтрашняй ночы"; + case "у нядзелю": return "нядзелі"; + case "у панядзелак": return "панядзелка"; + case "у аўторак": return "аўторка"; + case "у сераду": return "серады"; + case "у чацвер": return "чацвярга"; + case "у пятніцу": return "пятніцы"; + case "у суботу": return "суботы"; + default: return time; + } } -module.exports = require("../template")({ +module.exports = { "clear": "ясна", "no-precipitation": "без ападкаў", "mixed-precipitation": "змешаныя ападкі", @@ -236,5 +188,5 @@ module.exports = require("../template")({ str += "."; return str; - } -}); + }, +}; diff --git a/lib/lang/bg.js b/lib/lang/bg.js index a3c55a1e..067e52b2 100644 --- a/lib/lang/bg.js +++ b/lib/lang/bg.js @@ -1,3 +1,5 @@ +"use strict"; + function join_with_shared_prefix(a, b, joiner) { var m = a, i = 0, @@ -14,35 +16,20 @@ function join_with_shared_prefix(a, b, joiner) { return a + joiner + b.slice(i); } -function time2(time) -{ +function time2(time) { switch(time) { - case "в неделя": - time = "неделя"; - break; - case "в понеделник": - time = "понеделник"; - break; - case "във вторник": - time = "вторник"; - break; - case "в сряда": - time = "сряда"; - break; - case "в четвъртък": - time = "четвъртък"; - break; - case "в петък": - time = "петък"; - break; - case "в събота": - time = "събота"; - break; - }; - return time; + case "в неделя": return "неделя"; + case "в понеделник": return "понеделник"; + case "във вторник": return "вторник"; + case "в сряда": return "сряда"; + case "в четвъртък": return "четвъртък"; + case "в петък": return "петък"; + case "в събота": return "събота"; + default: return time; + } } -module.exports = require("../template")({ +module.exports = { "clear": "ясно", "no-precipitation": "без превалявания", "mixed-precipitation": "временни превалявания", @@ -180,5 +167,5 @@ module.exports = require("../template")({ str += "."; return str; - } -}); + }, +}; diff --git a/lib/lang/bs.js b/lib/lang/bs.js index 19d82ec3..22c2791d 100644 --- a/lib/lang/bs.js +++ b/lib/lang/bs.js @@ -1,3 +1,5 @@ +"use strict"; + function join_with_shared_prefix(a, b, joiner) { var m = a, i = 0, @@ -14,13 +16,7 @@ function join_with_shared_prefix(a, b, joiner) { return a + joiner + b.slice(i); } -function strip_prefix(period) { - return period.slice(0, 9) === "overnight" ? period.slice(4) : - period.slice(0, 7) === "in the " ? period.slice(7) : - period; -} - -module.exports = require("../template")({ +module.exports = { "clear": "vedro", "no-precipitation": "nema padavina", "mixed-precipitation": "različite padavine", @@ -115,16 +111,9 @@ module.exports = require("../template")({ "stopping-then-starting-later": "$1 prekida za $2, ondak počinje za $3", "for-day": "$1 tokom cijelog dana", "starting": "$1 počinje $2", - "until": function(condition, period) { - return condition + " do " + strip_prefix(period); - }, - "until-starting-again": function(condition, a, b) { - return condition + " do " + strip_prefix(a) + ", i opet poćinje " + b; - }, - "starting-continuing-until": function(condition, a, b) { - return condition + " poćinje " + a + ", ostaje do " + - strip_prefix(b); - }, + "until": "$1 do $2", + "until-starting-again": "$1 do $2, i opet poćinje $3", + "starting-continuing-until": "$1 poćinje $2, ostaje do $3", "during": "$1 $2", "for-week": "$1 tokom sedmice", "over-weekend": "$1 tokom vikenda", @@ -137,12 +126,6 @@ module.exports = require("../template")({ * 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(); - } - );*/ }, /* Capitalize the first word of the sentence and end with a period. */ "sentence": function(str) { @@ -154,5 +137,5 @@ module.exports = require("../template")({ str += "."; return str; - } -}); + }, +}; diff --git a/lib/lang/ca.js b/lib/lang/ca.js index 84972f97..2e599da5 100644 --- a/lib/lang/ca.js +++ b/lib/lang/ca.js @@ -1,3 +1,5 @@ +"use strict"; + function join_with_shared_prefix(a, b, joiner) { var m = a, i = 0, @@ -14,13 +16,7 @@ function join_with_shared_prefix(a, b, joiner) { return a + joiner + b.slice(i); } -function strip_prefix(period) { - return period.slice(0, 9) === "durant la nit" ? period.slice(4) : - period.slice(0, 7) === "a la " ? period.slice(7) : - period; -} - -module.exports = require("../template")({ +module.exports = { "clear": "clar", "no-precipitation": "sense precipitacions", "mixed-precipitation": "precipitacions mixtes", @@ -117,16 +113,9 @@ module.exports = require("../template")({ "stopping-then-starting-later": "$1 parant d'aquí $2, tornant a començar al cap $3", "for-day": "$1 durant el dia", "starting": "$1 començant $2", - "until": function(condition, period) { - return condition + " " + strip_prefix(period); - }, - "until-starting-again": function(condition, a, b) { - return condition + " " + strip_prefix(a) + ", començant " + b; - }, - "starting-continuing-until": function(condition, a, b) { - return condition + " començant " + a + ", continuant " + - strip_prefix(b); - }, + "until": "$1 $2", + "until-starting-again": "$1 $2, començant $3", + "starting-continuing-until": "$1 començant $2, continuant $3", "during": "$1 $2", "for-week": "$1 durant la setmana", "over-weekend": "$1 cap al cap de setmana", @@ -152,5 +141,5 @@ module.exports = require("../template")({ str += "."; return str; - } -}); + }, +}; diff --git a/lib/lang/cs.js b/lib/lang/cs.js index 085d07bb..889eb187 100644 --- a/lib/lang/cs.js +++ b/lib/lang/cs.js @@ -1,6 +1,4 @@ -function endsWith(str, suffix) { - return str.indexOf(suffix, str.length - suffix.length) !== -1; -} +"use strict"; function remove_prefix_and_use_genitive(a) { switch(a) { @@ -76,13 +74,7 @@ function join_with_shared_prefix(a, b, joiner) { return a + joiner + b.slice(i); } -function strip_prefix(period) { - return period.slice(0, 9) === "overnight" ? period.slice(4) : - period.slice(0, 7) === "in the " ? period.slice(7) : - period; -} - -module.exports = require("../template")({ +module.exports = { "clear": "jasno", "no-precipitation": "bez srážek", "mixed-precipitation": "smíšené srážky", @@ -186,30 +178,30 @@ module.exports = require("../template")({ }, "until-starting-again": function(condition, a, b) { var starting = ""; - if(endsWith(condition, "srážky")) + if(condition.endsWith("srážky")) starting = ", které začnou znovu "; - else if(endsWith(condition, "déšť") || endsWith(condition, "déšť se sněhem") || endsWith(condition, "vítr")) + else if(condition.endsWith("déšť") || condition.endsWith("déšť se sněhem") || condition.endsWith("vítr")) starting = ", který začne znovu "; - else if(endsWith(condition, "sněžení") || endsWith(condition, "mrholení")) + else if(condition.endsWith("sněžení") || condition.endsWith("mrholení")) starting = ", které začne znovu "; - else if(endsWith(condition, "vlhkost")) + else if(condition.endsWith("vlhkost")) starting = ", která začne znovu "; - else if(endsWith(condition, "zamračeno") || endsWith(condition, "mlhavo")) + 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(endsWith(condition, "srážky")) + if(condition.endsWith("srážky")) continuing = ", které přetrvají až do "; - else if(endsWith(condition, "déšť") || endsWith(condition, "déšť se sněhem") || endsWith(condition, "vítr")) + else if(condition.endsWith("déšť") || condition.endsWith("déšť se sněhem") || condition.endsWith("vítr")) continuing = ", který přetrvá až do "; - else if(endsWith(condition, "snežení") || endsWith(condition, "mrholení")) + else if(condition.endsWith("snežení") || condition.endsWith("mrholení")) continuing = ", které přetrvá až do "; - else if(endsWith(condition, "vlhkost")) + else if(condition.endsWith("vlhkost")) continuing = ", která přetrvá až do "; - else if(endsWith(condition, "zamračeno") || endsWith(condition, "mlhavo")) + 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); }, @@ -234,5 +226,5 @@ module.exports = require("../template")({ str += "."; return str; - } -}); + }, +}; diff --git a/lib/lang/da.js b/lib/lang/da.js index 34493034..bcac80ac 100644 --- a/lib/lang/da.js +++ b/lib/lang/da.js @@ -1,3 +1,5 @@ +"use strict"; + function join_with_shared_prefix(a, b, joiner) { var m = a, i = 0, @@ -25,7 +27,7 @@ function grammar(str) { .replace(/(man|tirs|ons|tors|fre|lør|søn)(dag)/gi, "$1dagen"); } -module.exports = require("../template")({ +module.exports = { "clear": "klart", "no-precipitation": "ingen målbar nedbør", "mixed-precipitation": "blandet nedbør", @@ -162,5 +164,5 @@ module.exports = require("../template")({ str += "."; return str; - } -}); \ No newline at end of file + }, +}; diff --git a/lib/lang/de.js b/lib/lang/de.js index 64af7dff..63c7aa1f 100644 --- a/lib/lang/de.js +++ b/lib/lang/de.js @@ -1,3 +1,5 @@ +"use strict"; + function join_with_shared_prefix(a, b, joiner) { var i = 0; @@ -18,7 +20,7 @@ function until_time(time) { "bis " + time; } -module.exports = require("../template")({ +module.exports = { "clear": "heiter", "no-precipitation": "kein Niederschlag", "mixed-precipitation": "wechselnder Niederschlag", @@ -180,5 +182,5 @@ module.exports = require("../template")({ str += "."; return str; - } -}); + }, +}; diff --git a/lib/lang/el.js b/lib/lang/el.js index 43b6d495..37e8cb0d 100644 --- a/lib/lang/el.js +++ b/lib/lang/el.js @@ -1,3 +1,5 @@ +"use strict"; + function singular_or_plural(n,singular,plural){ return Math.abs(parseInt(n)) === 1 ? singular : plural; } @@ -8,7 +10,7 @@ function strip_prefix(period) { period; } -module.exports = require("../template")({ +module.exports = { "clear": "αίθριος", "no-precipitation": "καθόλου υετός", "mixed-precipitation": "μικτός υετός", @@ -146,5 +148,5 @@ module.exports = require("../template")({ str += "."; return str; - } -}); + }, +}; diff --git a/lib/lang/en.js b/lib/lang/en.js index 09b61828..44d7fab7 100644 --- a/lib/lang/en.js +++ b/lib/lang/en.js @@ -1,3 +1,5 @@ +"use strict"; + function join_with_shared_prefix(a, b, joiner) { var m = a, i = 0, @@ -25,7 +27,7 @@ function strip_prefix(period) { period; } -module.exports = require("../template")({ +module.exports = { "clear": "clear", "no-precipitation": "no precipitation", "mixed-precipitation": "mixed precipitation", @@ -137,10 +139,10 @@ module.exports = require("../template")({ "during": "$1 $2", "for-week": "$1 throughout the week", "over-weekend": "$1 over the weekend", - "temperatures-peaking": "temperatures peaking at $1 $2", - "temperatures-rising": "temperatures rising to $1 $2", - "temperatures-valleying": "temperatures bottoming out at $1 $2", - "temperatures-falling": "temperatures falling to $1 $2", + "temperatures-peaking": "high temperatures peaking at $1 $2", + "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.) */ @@ -162,5 +164,5 @@ module.exports = require("../template")({ str += "."; return str; - } -}); + }, +}; diff --git a/lib/lang/es.js b/lib/lang/es.js index f8b00268..83b5e6cb 100644 --- a/lib/lang/es.js +++ b/lib/lang/es.js @@ -1,3 +1,5 @@ +"use strict"; + function join_with_shared_prefix(a, b, joiner) { var m = a, i = 0, @@ -14,13 +16,7 @@ function join_with_shared_prefix(a, b, joiner) { return a + joiner + b.slice(i); } -function strip_prefix(period) { - return period.slice(0, 9) === "sobre la noche" ? period.slice(4) : - period.slice(0, 7) === "en la " ? period.slice(7) : - period; -} - -module.exports = require("../template")({ +module.exports = { "clear": "despejado", "no-precipitation": "sin precipitaciones", "mixed-precipitation": "precipitación mixta", @@ -117,16 +113,9 @@ module.exports = require("../template")({ "stopping-then-starting-later": "$1 parando en $2, comenzando de nuevo $3 después", "for-day": "$1 durante el día", "starting": "$1 comenzando $2", - "until": function(condition, period) { - return condition + " hasta " + strip_prefix(period); - }, - "until-starting-again": function(condition, a, b) { - return condition + " hasta " + strip_prefix(a) + ", comenzando otra vez " + b; - }, - "starting-continuing-until": function(condition, a, b) { - return condition + " comenzando " + a + ", continuando hasta " + - strip_prefix(b); - }, + "until": "$1 hasta $2", + "until-starting-again": "$1 hasta $2, comenzando otra vez $3", + "starting-continuing-until": "$1 comenzando $2, continuando hasta $3", "during": "$1 $2", "for-week": "$1 durante la semana", "over-weekend": "$1 sobre el fin de semana", @@ -152,5 +141,5 @@ module.exports = require("../template")({ str += "."; return str; - } -}); + }, +}; diff --git a/lib/lang/et.js b/lib/lang/et.js index 0165fca5..07958302 100644 --- a/lib/lang/et.js +++ b/lib/lang/et.js @@ -1,3 +1,5 @@ +"use strict"; + function join_with_shared_prefix(a, b, joiner) { var m = a, i = 0, @@ -52,7 +54,7 @@ function illative(word){ return grammar.hasOwnProperty(word)? grammar[word][1]: word; } -module.exports = require("../template")({ +module.exports = { "clear": "selge", "no-precipitation": "kuiv", "mixed-precipitation": "erinevad sademed", @@ -180,5 +182,5 @@ module.exports = require("../template")({ str += "."; return str; - } -}); + }, +}; diff --git a/lib/lang/fi.js b/lib/lang/fi.js index f2b34fd6..d3dc2bf5 100644 --- a/lib/lang/fi.js +++ b/lib/lang/fi.js @@ -1,3 +1,5 @@ +"use strict"; + function join_with_shared_prefix(a, b, joiner) { var m = a, i = 0, @@ -45,7 +47,7 @@ function illative(word){ return grammar.hasOwnProperty(word)? grammar[word][1]: word; } -module.exports = require("../template")({ +module.exports = { "clear": "selkeää", "no-precipitation": "poutaa", "mixed-precipitation": "räntäsadetta", @@ -171,5 +173,5 @@ module.exports = require("../template")({ str += "."; return str; - } -}); + }, +}; diff --git a/lib/lang/fr.js b/lib/lang/fr.js index c15cadc4..3627ddc0 100644 --- a/lib/lang/fr.js +++ b/lib/lang/fr.js @@ -1,3 +1,5 @@ +"use strict"; + function join_with_shared_prefix(a, b, joiner) { var i = 0, j; @@ -13,7 +15,7 @@ function join_with_shared_prefix(a, b, joiner) { return a.slice(0, i) + a.slice(i) + joiner + b.slice(i); } -module.exports = require("../template")({ +module.exports = { "clear": "dégagé", "no-precipitation": "pas de précipitations", "mixed-precipitation": "précipitations mêlées", @@ -125,10 +127,10 @@ module.exports = require("../template")({ "during": "$1 $2", "for-week": "$1 pendant toute la semaine", "over-weekend": "$1 pendant tout le week-end", - "temperatures-peaking": "des températures atteignant $1 $2", - "temperatures-rising": "des températures montant jusqu’à $1 $2", - "temperatures-valleying": "des températures atteignant $1 $2", - "temperatures-falling": "des températures descendant jusqu’à $1 $2", + "temperatures-peaking": "des températures maximales atteignant $1 $2", + "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 @@ -152,5 +154,5 @@ module.exports = require("../template")({ str += "."; return str; - } -}); + }, +}; diff --git a/lib/lang/hr.js b/lib/lang/hr.js index 1d034f1d..f93214d5 100644 --- a/lib/lang/hr.js +++ b/lib/lang/hr.js @@ -1,3 +1,5 @@ +"use strict"; + function join_with_shared_prefix(a, b, joiner) { var m = a, i = 0, @@ -14,13 +16,7 @@ function join_with_shared_prefix(a, b, joiner) { return a + joiner + b.slice(i); } -function strip_prefix(period) { - return period.slice(0, 9) === "overnight" ? period.slice(4) : - period.slice(0, 7) === "in the " ? period.slice(7) : - period; -} - -module.exports = require("../template")({ +module.exports = { "clear": "vedro", "no-precipitation": "nema padalina", "mixed-precipitation": "različite padaline", @@ -117,16 +113,9 @@ module.exports = require("../template")({ "stopping-then-starting-later": "$1 prestaje za $2, pa počinje za $3", "for-day": "$1 tijekom cijelog dana", "starting": "$1 počinje $2", - "until": function(condition, period) { - return condition + " do " + strip_prefix(period); - }, - "until-starting-again": function(condition, a, b) { - return condition + " do " + strip_prefix(a) + ", i opet počinje " + b; - }, - "starting-continuing-until": function(condition, a, b) { - return condition + " počinje " + a + ", ostaje do " + - strip_prefix(b); - }, + "until": "$1 do $2", + "until-starting-again": "$1 do $2, i opet počinje $3", + "starting-continuing-until": "$1 počinje $2, ostaje do $3", "during": "$1 $2", "for-week": "$1 tijekom tjedna", "over-weekend": "$1 tijekom vikenda", @@ -156,5 +145,5 @@ module.exports = require("../template")({ str += "."; return str; - } -}); + }, +}; diff --git a/lib/lang/hu.js b/lib/lang/hu.js index f4aad0b2..c3012310 100644 --- a/lib/lang/hu.js +++ b/lib/lang/hu.js @@ -1,3 +1,5 @@ +"use strict"; + function join_with_shared_prefix(a, b, joiner) { var m = a, i = 0, @@ -19,13 +21,7 @@ function join_with_shared_prefix(a, b, joiner) { return a + " és " + b.slice(i)+ joiner; } -function strip_prefix(period) { - return period.slice(0, 9) === "éjszaka" ? period.slice(4) : - period.slice(0, 7) === "" ? period.slice(7) : - period; -} - -module.exports = require("../template")({ +module.exports = { "clear": "derült", "no-precipitation": "csapadékmentes idő", "mixed-precipitation": "vegyes csapadék", @@ -122,15 +118,9 @@ module.exports = require("../template")({ "stopping-then-starting-later": "$1 $2 múlva véget ér, de $3 elteltével újra várható", "for-day": "$1 egész nap", "starting": "$1 lesz $2", - "until": function(condition, period) { - return condition + " " + strip_prefix(period)+ ""; - }, - "until-starting-again": function(condition, a, b) { - return condition + " " + strip_prefix(a) + ", majd "+ b +" ismét" ; - }, - "starting-continuing-until": function(condition, a, b) { - return condition + " kezdődik " + a + ", " + strip_prefix(b) + " folytatódik"; - }, + "until": "$1 $2", + "until-starting-again": "$1 $2, majd $3 ismét", + "starting-continuing-until": "$1 kezdődik $2, $3 folytatódik", "during": "$1 $2", "for-week": "$1 ezen a héten", "over-weekend": "$1 a hétvégén", @@ -152,5 +142,5 @@ module.exports = require("../template")({ str += "."; return str; - } -}); + }, +}; diff --git a/lib/lang/id.js b/lib/lang/id.js index 727420cf..9b3bb390 100644 --- a/lib/lang/id.js +++ b/lib/lang/id.js @@ -1,3 +1,5 @@ +"use strict"; + function join_with_shared_prefix(a, b, joiner) { var m = a, i = 0, @@ -14,7 +16,7 @@ function join_with_shared_prefix(a, b, joiner) { return a + joiner + b.slice(i); } -module.exports = require("../template")({ +module.exports = { "clear": "cerah", "no-precipitation": "tidak hujan", "mixed-precipitation": "hujan ringan", @@ -144,5 +146,5 @@ module.exports = require("../template")({ str += "."; return str; - } -}); + }, +}; diff --git a/lib/lang/is.js b/lib/lang/is.js index e9e8189f..419d9ea5 100644 --- a/lib/lang/is.js +++ b/lib/lang/is.js @@ -1,3 +1,5 @@ +"use strict"; + function join_with_shared_prefix(a, b, joiner) { var m = a, i = 0, @@ -20,7 +22,7 @@ function strip_prefix(period) { period; } -module.exports = require("../template")({ +module.exports = { "clear": "heiðskýrt", "no-precipitation": "engin úrkoma", "mixed-precipitation": "úrkoma með köflum", @@ -148,5 +150,5 @@ module.exports = require("../template")({ str += "."; return str; - } -}); + }, +}; diff --git a/lib/lang/it.js b/lib/lang/it.js index 30d2d488..ecc32474 100644 --- a/lib/lang/it.js +++ b/lib/lang/it.js @@ -1,3 +1,5 @@ +"use strict"; + function join_with_shared_prefix(a, b, joiner) { var m = a, i = 0, @@ -17,12 +19,12 @@ function join_with_shared_prefix(a, b, joiner) { function strip_prefix(period) { if(period === "in serata") return "sera"; if(period === "in mattinata") return "mattina"; - if(period.slice(0,6) === "nella ") return period.slice(6); - if(period.slice(0,4) === "nel ") return period.slice(4); + if(period.slice(0, 6) === "nella ") return period.slice(6); + if(period.slice(0, 4) === "nel ") return period.slice(4); return period; } -module.exports = require("../template")({ +module.exports = { "clear": "sereno", "no-precipitation": "nessuna precipitazione", "mixed-precipitation": "precipitazioni miste", @@ -161,5 +163,5 @@ module.exports = require("../template")({ str += "."; return str; - } -}); + }, +}; diff --git a/lib/lang/ja.js b/lib/lang/ja.js index f63b4163..a13335ff 100644 --- a/lib/lang/ja.js +++ b/lib/lang/ja.js @@ -1,3 +1,5 @@ +"use strict"; + function join_with_shared_prefix(a, b, joiner) { var i = 0; @@ -12,7 +14,7 @@ function join_with_shared_prefix(a, b, joiner) { return a.slice(0, i) + a.slice(i) + joiner + b.slice(i); } -module.exports = require("../template")({ +module.exports = { "clear": "晴れ", "no-precipitation": "降水なし", "mixed-precipitation": "みぞれ", @@ -109,15 +111,9 @@ module.exports = require("../template")({ "stopping-then-starting-later": "$1が$2に終わり、また$3後始まります", "for-day": "一日中$1", "starting": "$1は$2が始まります", - "until": function(condition, period) { - return condition + period + " まで" ; - }, - "until-starting-again": function(condition, a, b) { - return condition + a + "まで" + b + ", また始まる " ; - }, - "starting-continuing-until": function(condition, a, b) { - return condition + a + " 始まって" + b + ", まで続く " ; - }, + "until": "$1$2 まで", + "until-starting-again": "$1$2まで$3, また始まる ", + "starting-continuing-until": "$1$2 始まって$3, まで続く ", "during": "$1から$2にかけて", "for-week": "一週間中$1", "over-weekend": "土、日曜日に$1", @@ -132,5 +128,5 @@ module.exports = require("../template")({ str += "。"; return str; - } -}); + }, +}; diff --git a/lib/lang/ka.js b/lib/lang/ka.js index 0d21323d..b7afd447 100644 --- a/lib/lang/ka.js +++ b/lib/lang/ka.js @@ -1,4 +1,6 @@ -module.exports = require("../template")({ +"use strict"; + +module.exports = { "clear": "მოწმენდილი", "no-precipitation": "უნალექო", "mixed-precipitation": "ცვალებადი ნალექი", @@ -105,5 +107,5 @@ module.exports = require("../template")({ str += "."; } return str; - } -}); + }, +}; diff --git a/lib/lang/kw.js b/lib/lang/kw.js index 3ee77852..c89640ad 100644 --- a/lib/lang/kw.js +++ b/lib/lang/kw.js @@ -1,3 +1,5 @@ +"use strict"; + function in_the(period) { var f=period.charAt(0); var n="123456789"; @@ -20,7 +22,7 @@ function until_the(period) { return " bys yn " + period; } -module.exports = require("../template")({ +module.exports = { "clear": "kler", "no-precipitation": "kodhans vyth", "mixed-precipitation": "kodhans kemyskys", @@ -169,5 +171,5 @@ module.exports = require("../template")({ str += "."; return str; - } -}); + }, +}; diff --git a/lib/lang/nl.js b/lib/lang/nl.js index 54e14e8f..380aa55b 100644 --- a/lib/lang/nl.js +++ b/lib/lang/nl.js @@ -1,3 +1,5 @@ +"use strict"; + function join_with_shared_prefix(a, b, joiner) { var i = 0; @@ -20,7 +22,7 @@ function weekdays(scope, day){ return (scope.indexOf("through") !== -1 ? "" : "op ") + day; } -module.exports = require("../template")({ +module.exports = { "clear": "helder", "no-precipitation": "geen neerslag", "mixed-precipitation": "wisselende neerslag", @@ -169,5 +171,5 @@ module.exports = require("../template")({ str += "."; return str; - } -}); + }, +}; diff --git a/lib/lang/nb.js b/lib/lang/no.js similarity index 99% rename from lib/lang/nb.js rename to lib/lang/no.js index c8ac6012..4b813d36 100644 --- a/lib/lang/nb.js +++ b/lib/lang/no.js @@ -1,3 +1,5 @@ +"use strict"; + function join_with_shared_prefix(a, b, joiner) { var m = a, i = 0, @@ -20,7 +22,7 @@ function strip_prefix(period) { period; } -module.exports = require("../template")({ +module.exports = { "clear": "klart", "no-precipitation": "ingen målbar nedbør", "mixed-precipitation": "blandet nedbør", @@ -149,5 +151,5 @@ module.exports = require("../template")({ str += "."; return str; - } -}); + }, +}; diff --git a/lib/lang/pl.js b/lib/lang/pl.js index 589a1863..51d2cb0a 100644 --- a/lib/lang/pl.js +++ b/lib/lang/pl.js @@ -1,3 +1,5 @@ +"use strict"; + function join_with_shared_prefix(a, b, joiner) { var m = a, n = b, @@ -55,7 +57,7 @@ function genitive_form(a) { } } -module.exports = require("../template")({ +module.exports = { "clear": "bezchmurnie", "no-precipitation": "brak opadów", "mixed-precipitation": "przelotne opady", @@ -190,5 +192,5 @@ module.exports = require("../template")({ if (str.charAt(str.length - 1) !== ".") str += "."; return str; - } -}); + }, +}; diff --git a/lib/lang/pt.js b/lib/lang/pt.js index a6b8c517..9ee8f367 100644 --- a/lib/lang/pt.js +++ b/lib/lang/pt.js @@ -1,3 +1,5 @@ +"use strict"; + function join_with_shared_prefix(a, b, joiner) { var m = a, i = 0, @@ -14,7 +16,7 @@ function join_with_shared_prefix(a, b, joiner) { return a + joiner + b.slice(i); } -module.exports = require("../template")({ +module.exports = { "clear": "limpo", "no-precipitation": "sem aguaceiros", "mixed-precipitation": "aguaceiros variados", @@ -139,5 +141,5 @@ module.exports = require("../template")({ str += "."; return str; - } -}); + }, +}; diff --git a/lib/lang/ro.js b/lib/lang/ro.js index 2e76721b..f80db4e0 100644 --- a/lib/lang/ro.js +++ b/lib/lang/ro.js @@ -1,3 +1,5 @@ +"use strict"; + function join_with_shared_prefix(a, b, joiner) { var i = 0, j; @@ -13,13 +15,7 @@ function join_with_shared_prefix(a, b, joiner) { return a.slice(0, i) + a.slice(i) + joiner + b.slice(i); } -function strip_prefix(period) { - return period.slice(0, 9) === "overnight" ? period.slice(4) : - period.slice(0, 7) === "in the " ? period.slice(7) : - period; -} - -module.exports = require("../template")({ +module.exports = { "clear": "senin", "no-precipitation": "fără precipitații", "mixed-precipitation": "precipitații mixte", @@ -129,16 +125,9 @@ module.exports = require("../template")({ "stopping-then-starting-later": "$1, se oprește în $2, începe din nou $3 mai târziu", "for-day": "$1 de-a lungul zilei", "starting": "$1, începând de $2", - "until": function(condition, period) { - return condition + " până " + strip_prefix(period); - }, - "until-starting-again": function(condition, a, b) { - return condition + " până " + strip_prefix(a) + ", începe din nou " + b; - }, - "starting-continuing-until": function(condition, a, b) { - return condition + " începând de " + a + " și până " + - strip_prefix(b); - }, + "until": "$1 până $2", + "until-starting-again": "$1 până $2, începe din nou $3", + "starting-continuing-until": "$1 începând de $2 și până $3", "during": "$1 $2", "for-week": "$1 pe toată durata săptămânii", "over-weekend": "$1 în weekend", @@ -170,5 +159,5 @@ module.exports = require("../template")({ str += "."; return str; - } -}); + }, +}; diff --git a/lib/lang/ru.js b/lib/lang/ru.js index 9b69386f..2bb3e6f6 100644 --- a/lib/lang/ru.js +++ b/lib/lang/ru.js @@ -1,3 +1,5 @@ +"use strict"; + function join_with_shared_prefix(a, b, joiner) { var m = a, i = 0, @@ -14,84 +16,36 @@ function join_with_shared_prefix(a, b, joiner) { return a + joiner + b.slice(i); } -function time2(time) -{ +function time2(time) { switch(time) { - case "утром": - time = "утра"; - break; - case "днем": - time = "середины дня"; - break; - case "вечером": - time = "вечера"; - break; - case "ночью": - time = "ночи"; - break; - case "сегодня утром": - time="сегодняшнего утра"; - break; - case "сегодня поздним утром": - time="сегодняшнего позднего утра"; - break; - case "сегодня днем": - time="середины дня"; - break; - case "сегодня поздним днем": - time="сегодняшнего позднего дня"; - break; - case "сегодня вечером": - time="сегодняшнего вечера"; - break; - case "сегодня поздним вечером": - time="сегодняшнего позднего вечера"; - break; - case "сегодня ночью": - time="сегодняшней ночи"; - break; - case "сегодня поздней ночью": - time="сегодняшней поздней ночи"; - break; - case "завтра утром": - time="завтрашнего утра"; - break; - case "завтра днем": - time="завтрашнего дня"; - break; - case "завтра вечером": - time="завтрашнего вечера"; - break; - case "завтра ночью": - time="завтрашней ночи"; - break; - case "в воскресенье": - time="воскресенья"; - break; - case "в понедельник": - time="понедельника"; - break; - case "во вторник": - time="вторника"; - break; - case "в среду": - time="среды"; - break; - case "в четверг": - time="четверга"; - break; - case "в пятницу": - time="пятницы"; - break; - case "в субботу": - time="субботы"; - break; - }; - - return time; + case "утром": return "утра"; + case "днем": return "середины дня"; + case "вечером": return "вечера"; + case "ночью": return "ночи"; + case "сегодня утром": return "сегодняшнего утра"; + case "сегодня поздним утром": return "сегодняшнего позднего утра"; + case "сегодня днем": return "середины дня"; + case "сегодня поздним днем": return "сегодняшнего позднего дня"; + case "сегодня вечером": return "сегодняшнего вечера"; + case "сегодня поздним вечером": return "сегодняшнего позднего вечера"; + case "сегодня ночью": return "сегодняшней ночи"; + case "сегодня поздней ночью": return "сегодняшней поздней ночи"; + case "завтра утром": return "завтрашнего утра"; + case "завтра днем": return "завтрашнего дня"; + case "завтра вечером": return "завтрашнего вечера"; + case "завтра ночью": return "завтрашней ночи"; + case "в воскресенье": return "воскресенья"; + case "в понедельник": return "понедельника"; + case "во вторник": return "вторника"; + case "в среду": return "среды"; + case "в четверг": return "четверга"; + case "в пятницу": return "пятницы"; + case "в субботу": return "субботы"; + default: return time; + } } -module.exports = require("../template")({ +module.exports = { "clear": "ясно", "no-precipitation": "без осадков", "mixed-precipitation": "смешанные осадки", @@ -227,5 +181,5 @@ module.exports = require("../template")({ str += "."; return str; - } -}); + }, +}; diff --git a/lib/lang/sk.js b/lib/lang/sk.js index bae9f290..d195d18d 100644 --- a/lib/lang/sk.js +++ b/lib/lang/sk.js @@ -1,6 +1,4 @@ -function endsWith(str, suffix) { - return str.indexOf(suffix, str.length - suffix.length) !== -1; -} +"use strict"; function remove_prefix_and_use_genitive(a) { switch(a) { @@ -90,13 +88,7 @@ function join_with_shared_prefix(a, b, joiner) { return a + joiner + b.slice(i); } -function strip_prefix(period) { - return period.slice(0, 9) === "overnight" ? period.slice(4) : - period.slice(0, 7) === "in the " ? period.slice(7) : - period; -} - -module.exports = require("../template")({ +module.exports = { "clear": "jasno", "no-precipitation": "bez zrážok", "mixed-precipitation": "zmiešané zrážky", @@ -202,30 +194,30 @@ module.exports = require("../template")({ }, "until-starting-again": function(condition, a, b) { var starting = ""; - if(endsWith(condition, "zrážky")) + if(condition.endsWith("zrážky")) starting = ", ktoré začnú znovu "; - else if(endsWith(condition, "dážď") || endsWith(condition, "dážď so snehom") || endsWith(condition, "vietor")) + else if(condition.endsWith("dážď") || condition.endsWith("dážď so snehom") || condition.endsWith("vietor")) starting = ", ktorý začne znovu "; - else if(endsWith(condition, "sneženie") || endsWith(condition, "mrholenie")) + else if(condition.endsWith("sneženie") || condition.endsWith("mrholenie")) starting = ", ktoré začne znovu "; - else if(endsWith(condition, "vlhkosť")) + else if(condition.endsWith("vlhkosť")) starting = ", ktorá začne znovu "; - else if(endsWith(condition, "zamračené") || endsWith(condition, "hmlisto")) + 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(endsWith(condition, "zrážky")) + if(condition.endsWith("zrážky")) continuing = ", ktoré pretrvajú až do "; - else if(endsWith(condition, "dážď") || endsWith(condition, "dážď so snehom") || endsWith(condition, "vietor")) + else if(condition.endsWith("dážď") || condition.endsWith("dážď so snehom") || condition.endsWith("vietor")) continuing = ", ktorý pretrvá až do "; - else if(endsWith(condition, "sneženie") || endsWith(condition, "mrholenie")) + else if(condition.endsWith("sneženie") || condition.endsWith("mrholenie")) continuing = ", ktoré pretrvá až do "; - else if(endsWith(condition, "vlhkosť")) + else if(condition.endsWith("vlhkosť")) continuing = ", ktorá pretrvá až do "; - else if(endsWith(condition, "zamračené") || endsWith(condition, "hmlisto")) + 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); }, @@ -250,5 +242,5 @@ module.exports = require("../template")({ str += "."; return str; - } -}); + }, +}; diff --git a/lib/lang/sl.js b/lib/lang/sl.js index 3ee2d685..d872d373 100644 --- a/lib/lang/sl.js +++ b/lib/lang/sl.js @@ -1,3 +1,5 @@ +"use strict"; + function join_with_shared_prefix(a, b, joiner) { var m = a, i = 0, @@ -14,13 +16,7 @@ function join_with_shared_prefix(a, b, joiner) { return a + joiner + b.slice(i); } -function strip_prefix(period) { - return period.slice(0, 9) === "overnight" ? period.slice(4) : - period.slice(0, 7) === "in the " ? period.slice(7) : - period; -} - -module.exports = require("../template")({ +module.exports = { "clear": "jasno", "no-precipitation": "brez padavin", "mixed-precipitation": "možne padavine", @@ -115,16 +111,9 @@ module.exports = require("../template")({ "stopping-then-starting-later": "$1 do $2, začelo bo zopet $3 kasneje", "for-day": "$1 čez dan", "starting": "$1 od $2", - "until": function(condition, period) { - return condition + " do " + strip_prefix(period); - }, - "until-starting-again": function(condition, a, b) { - return condition + " do " + strip_prefix(a) + ", začelo bo zopet " + b; - }, - "starting-continuing-until": function(condition, a, b) { - return condition + " začel " + a + ", do " + - strip_prefix(b); - }, + "until": "$1 do $2", + "until-starting-again": "$1 do $2, začelo bo zopet $3", + "starting-continuing-until": "$1 začel $2, do $3", "during": "$1 $2", "for-week": "$1 čez teden", "over-weekend": "$1 v soboto in nedeljo", @@ -146,5 +135,5 @@ module.exports = require("../template")({ str += "."; return str; - } -}); \ No newline at end of file + }, +}; diff --git a/lib/lang/sr.js b/lib/lang/sr.js index aab0ceeb..ecfc3b88 100644 --- a/lib/lang/sr.js +++ b/lib/lang/sr.js @@ -1,3 +1,5 @@ +"use strict"; + function join_with_shared_prefix(a, b, joiner) { var m = a, i = 0, @@ -89,7 +91,7 @@ function get_prefix(a, t) { } } -module.exports = require("../template")({ +module.exports = { "clear": "vedro", "no-precipitation": "nema padavina", "mixed-precipitation": "različite padavine", @@ -238,5 +240,5 @@ module.exports = require("../template")({ str += "."; return str; - } -}); + }, +}; diff --git a/lib/lang/sv.js b/lib/lang/sv.js index c0a096ce..105075fb 100644 --- a/lib/lang/sv.js +++ b/lib/lang/sv.js @@ -1,3 +1,5 @@ +"use strict"; + function join_with_shared_prefix(a, b, joiner) { var m = a, i = 0, @@ -25,7 +27,7 @@ function grammar(str) { .replace(/(ån|is|ns|rs|re|ör|ön)(dag)/gi, "$1dagen"); } -module.exports = require("../template")({ +module.exports = { "clear": "klart", "no-precipitation": "ingen mätbar nederbörd", "mixed-precipitation": "blandad nederbörd", @@ -165,5 +167,5 @@ module.exports = require("../template")({ str += "."; return str; - } -}); + }, +}; diff --git a/lib/lang/tet.js b/lib/lang/tet.js index 3c5e86a4..0c4ece47 100644 --- a/lib/lang/tet.js +++ b/lib/lang/tet.js @@ -1,3 +1,5 @@ +"use strict"; + function join_with_shared_prefix(a, b, joiner) { var i = 0; @@ -18,7 +20,7 @@ function strip_prefix(period) { period; } -module.exports = require("../template")({ +module.exports = { "clear": "pas", "no-precipitation": "udan la iha", "mixed-precipitation": "udan - maran kahur", @@ -148,5 +150,5 @@ module.exports = require("../template")({ str += "."; return str; - } -}); + }, +}; diff --git a/lib/lang/tr.js b/lib/lang/tr.js index b1f997db..b138f62f 100644 --- a/lib/lang/tr.js +++ b/lib/lang/tr.js @@ -1,3 +1,5 @@ +"use strict"; + function join_with_shared_prefix(a,joiner1,b,joiner2) { var m = a, i = 0, @@ -14,7 +16,7 @@ function join_with_shared_prefix(a,joiner1,b,joiner2) { return a + joiner1 + b.slice(i)+joiner2; } -module.exports = require("../template")({ +module.exports = { "clear": "açık hava", "no-precipitation": "yağış yok", "mixed-precipitation": "karışık yağış", @@ -133,5 +135,5 @@ module.exports = require("../template")({ str += "."; return str; - } -}); + }, +}; diff --git a/lib/lang/uk.js b/lib/lang/uk.js index a9a7cee7..0ab70294 100644 --- a/lib/lang/uk.js +++ b/lib/lang/uk.js @@ -1,3 +1,5 @@ +"use strict"; + function join_with_shared_prefix(a, b, joiner) { var m = a, i = 0, @@ -14,84 +16,36 @@ function join_with_shared_prefix(a, b, joiner) { return a + joiner + b.slice(i); } -function time2(time) -{ +function time2(time) { switch(time) { - case "вранці": - time = "ранку"; - break; - case "вдень": - time = "середини дня"; - break; - case "ввечері": - time = "вечору"; - break; - case "вночі": - time = "ночі"; - break; - case "сьогодні вранці": - time="сьогоднішнього ранку"; - break; - case "сьогодні пізно вранці": - time="сьогоднішнього пізнього ранку"; - break; - case "сьогодні вдень": - time="середини дня"; - break; - case "сьогодні пізно вдень": - time="сьогоднішнього пізнього дня"; - break; - case "сьогодні ввечері": - time="сьогоднішнього вечору"; - break; - case "сьогодні пізно ввечері": - time="сьогоднішнього пізнього вечору"; - break; - case "сьогодні вночі": - time="сьогоднішньої ночі"; - break; - case "сьогодні пізно вночі": - time="сьогоднішньої пізньої ночі"; - break; - case "завтра вранці": - time="завтрашнього ранку"; - break; - case "завтра вдень": - time="завтрашнього дня"; - break; - case "завтра ввечері": - time="завтрашнього вечору"; - break; - case "завтра вночі": - time="завтрашньої ночі"; - break; - case "у неділю": - time="неділі"; - break; - case "в понеділок": - time="понеділка"; - break; - case "у вівторок": - time="вівторка"; - break; - case "в середу": - time="середи"; - break; - case "в четвер": - time="четверга"; - break; - case "в п'ятницю": - time="п'ятниці"; - break; - case "в суботу": - time="суботи"; - break; - }; - - return time; + case "вранці": return "ранку"; + case "вдень": return "середини дня"; + case "ввечері": return "вечору"; + case "вночі": return "ночі"; + case "сьогодні вранці": return "сьогоднішнього ранку"; + case "сьогодні пізно вранці": return "сьогоднішнього пізнього ранку"; + case "сьогодні вдень": return "середини дня"; + case "сьогодні пізно вдень": return "сьогоднішнього пізнього дня"; + case "сьогодні ввечері": return "сьогоднішнього вечору"; + case "сьогодні пізно ввечері": return "сьогоднішнього пізнього вечору"; + case "сьогодні вночі": return "сьогоднішньої ночі"; + case "сьогодні пізно вночі": return "сьогоднішньої пізньої ночі"; + case "завтра вранці": return "завтрашнього ранку"; + case "завтра вдень": return "завтрашнього дня"; + case "завтра ввечері": return "завтрашнього вечору"; + case "завтра вночі": return "завтрашньої ночі"; + case "у неділю": return "неділі"; + case "в понеділок": return "понеділка"; + case "у вівторок": return "вівторка"; + case "в середу": return "середи"; + case "в четвер": return "четверга"; + case "в п'ятницю": return "п'ятниці"; + case "в суботу": return "суботи"; + default: return time; + } } -module.exports = require("../template")({ +module.exports = { "clear": "ясно", "no-precipitation": "без опадів", "mixed-precipitation": "змішані опади", @@ -227,5 +181,5 @@ module.exports = require("../template")({ str += "."; return str; - } -}); + }, +}; diff --git a/lib/lang/x-pig-latin.js b/lib/lang/x-pig-latin.js index 6d70291f..e6f4ade7 100644 --- a/lib/lang/x-pig-latin.js +++ b/lib/lang/x-pig-latin.js @@ -1,3 +1,5 @@ +"use strict"; + function join_with_shared_prefix(a, b, joiner) { var m = a, i = 0, @@ -21,17 +23,17 @@ function join_with_shared_prefix(a, b, joiner) { function strip_prefix(period) { if(period.slice(0, 12) === "overnightway") { - period = period.slice(12); - return 'ightnay'+period; - - } else if(period.slice(0, 12) === "inway ethay ") { + return "ightnay" + period.slice(12); + } + + if(period.slice(0, 12) === "inway ethay ") { return period.slice(12); } return period; } -module.exports = require("../template")({ +module.exports = { "clear": "earclay", "no-precipitation": "onay ecipitationpray", "mixed-precipitation": "ixedmay ecipitationpray", @@ -166,5 +168,5 @@ module.exports = require("../template")({ str += "."; return str; - } -}); + }, +}; diff --git a/lib/lang/zh-tw.js b/lib/lang/zh-tw.js index d76db89c..44f10f24 100644 --- a/lib/lang/zh-tw.js +++ b/lib/lang/zh-tw.js @@ -1,5 +1,6 @@ "use strict"; -module.exports = require("../template")({ + +module.exports = { "clear": "晴朗", "no-precipitation": "無降水", "mixed-precipitation": "多雲轉雨", @@ -100,4 +101,4 @@ module.exports = require("../template")({ "temperatures-falling": "$2溫度下降到$1", "title": "$1", "sentence": a => a.endsWith("。")? a: a + "。", -}); +}; diff --git a/lib/lang/zh.js b/lib/lang/zh.js index 13cdbf9b..c19475bc 100644 --- a/lib/lang/zh.js +++ b/lib/lang/zh.js @@ -1,5 +1,6 @@ "use strict"; -module.exports = require("../template")({ + +module.exports = { "clear": "晴朗", "no-precipitation": "无降水", "mixed-precipitation": "多云转雨", @@ -100,4 +101,4 @@ module.exports = require("../template")({ "temperatures-falling": "$2温度下降到$1", "title": "$1", "sentence": a => a.endsWith("。")? a: a + "。", -}); +}; diff --git a/lib/template.js b/lib/translation.js similarity index 90% rename from lib/template.js rename to lib/translation.js index 4b5c817e..5f505c96 100644 --- a/lib/template.js +++ b/lib/translation.js @@ -95,4 +95,18 @@ function parse(template, expr, stack) { return result; } -module.exports = template => expr => parse(template, expr, []); +class Translation { + constructor(template) { + this.template = template; + } + + translate(expr) { + return parse(this.template, expr, []); + } + + is_supported(term) { + return term in this.template; + } +} + +module.exports = Translation; diff --git a/test.js b/test.js index a21e9a13..5836e562 100644 --- a/test.js +++ b/test.js @@ -1,149 +1,134 @@ "use strict"; -const assert = require("assert"), - fs = require("fs"), - path = require("path"), - template = require("./lib/template"), - translation = require("./"), - util = require("util"); - -describe("translation", () => { - describe("template", () => { - const convert = template({ - "foo": "bar", - "bar": "meeple $2", - "baz": (a, b) => "meeple " + b, - "quux": () => "glorple", - }); +const assert = require("assert"); +const Translation = require("./lib/translation"); +const translations = require("./"); + +describe("translations", () => { + describe("Translation", () => { + const test = new Translation({ + "foo": "bar", + "bar": "meeple $2", + "baz": (a, b) => "meeple " + b, + "quux": () => "glorple", + }); it("should return a number in string form", () => { - assert.strictEqual(convert(42), "42"); + assert.strictEqual(test.translate(42), "42"); }); it("should throw an error given an unrecognized string", () => { - assert.throws(() => { convert("42"); }); + assert.throws(() => { test.translate("42"); }); }); it("should apply an expected value conversion", () => { - assert.strictEqual(convert("foo"), "bar"); + assert.strictEqual(test.translate("foo"), "bar"); }); it("should throw an error given a value expected to be a string", () => { - assert.throws(() => { convert("bar"); }); + assert.throws(() => { test.translate("bar"); }); }); it("should throw an error given a value expected to be a function", () => { - assert.throws(() => { convert("baz"); }); + assert.throws(() => { test.translate("baz"); }); }); it("should throw an error given an empty array", () => { - assert.throws(() => { convert([]); }); + assert.throws(() => { test.translate([]); }); }); it("should apply a string template", () => { - assert.strictEqual(convert(["bar", 10, 20]), "meeple 20"); + assert.strictEqual(test.translate(["bar", 10, 20]), "meeple 20"); }); it("should fail to apply a function with the wrong arity", () => { - assert.throws(() => { convert(["baz", 10, 20, 30]); }); + assert.throws(() => { test.translate(["baz", 10, 20, 30]); }); }); it("should apply a function template", () => { - assert.strictEqual(convert(["baz", 10, 20]), "meeple 20"); + assert.strictEqual(test.translate(["baz", 10, 20]), "meeple 20"); }); it("should recursively apply function templates", () => { /* Actually, a "meeple meeple bar" sounds like it'd be a pretty tasty * candy treat. */ assert.strictEqual( - convert(["bar", 10, ["baz", 20, "foo"]]), + test.translate(["bar", 10, ["baz", 20, "foo"]]), "meeple meeple bar" ); }); it("should throw an error given undefined", () => { - assert.throws(() => { convert(undefined); }); + assert.throws(() => { test.translate(undefined); }); }); it("should throw an error given null", () => { - assert.throws(() => { convert(null); }); + assert.throws(() => { test.translate(null); }); }); it("should throw an error given an object", () => { - assert.throws(() => { convert({}); }); + assert.throws(() => { test.translate({}); }); }); it("should apply a zero-argument function", () => { - assert.strictEqual(convert("quux"), "glorple"); + assert.strictEqual(test.translate("quux"), "glorple"); }); it("should fail to apply a zero-argument function given arguments", () => { - assert.throws(() => { convert(["quux"]); }); + assert.throws(() => { test.translate(["quux"]); }); }); it("should fail to apply a function template given a value", () => { - assert.throws(() => { convert("baz"); }); + assert.throws(() => { test.translate("baz"); }); }); it("should provide context to functions", () => { - const convert = template({ - "foo": function(a, b, c) { - assert.deepEqual(this, ["foo"]); - return "Moop."; - }, - "bar": function() { - assert.deepEqual(this, ["foo", "bar"]); - return "Boop."; - }, - "baz": function(a) { - assert.deepEqual(this, ["foo", "baz"]); - return "Soup."; - }, - "quux": function() { - assert.deepEqual(this, ["foo", "baz", "quux"]); - return "Floop."; - }, - "neem": function(a) { - assert.deepEqual(this, ["foo", "neem"]); - return "Bloop."; - }, - "glorp": function(a) { - assert.deepEqual(this, ["foo", "neem", "glorp"]); - return "Rope?"; - } - }); - - convert(["foo", "bar", ["baz", "quux"], ["neem", ["glorp", 42]]]); + const test = new Translation({ + "foo": function(a, b, c) { + assert.deepEqual(this, ["foo"]); + return "Moop."; + }, + "bar": function() { + assert.deepEqual(this, ["foo", "bar"]); + return "Boop."; + }, + "baz": function(a) { + assert.deepEqual(this, ["foo", "baz"]); + return "Soup."; + }, + "quux": function() { + assert.deepEqual(this, ["foo", "baz", "quux"]); + return "Floop."; + }, + "neem": function(a) { + assert.deepEqual(this, ["foo", "neem"]); + return "Bloop."; + }, + "glorp": function(a) { + assert.deepEqual(this, ["foo", "neem", "glorp"]); + return "Rope?"; + } + }); + + test.translate(["foo", "bar", ["baz", "quux"], ["neem", ["glorp", 42]]]); }); }); - describe("language", () => { - fs.readdirSync(path.join(__dirname, "test_cases")).forEach(lang => { - if(lang.charAt(0) === ".") { - return; - } - - const name = path.basename(lang, ".json"), - translate = translation[name]; - - describe(name, () => { - const cases = JSON.parse( - fs.readFileSync( - path.join(__dirname, "test_cases", lang), - "utf8" - ) - ); - - Object.keys(cases).forEach(summary => { + describe("languages", () => { + for(const lang in translations) { + describe(lang, () => { + const translation = translations[lang]; + const cases = require("./test_cases/" + lang); + + for(const summary in cases) { const source = cases[summary]; it( - util.format("should translate %j to \"%s\"", source, summary), - () => { - assert.strictEqual(translate(source), summary); - } + "should translate " + JSON.stringify(source) + + " to " + JSON.stringify(summary), + () => assert.strictEqual(translation.translate(source), summary) ); - }); + } }); - }); + } }); }); diff --git a/test_cases/en.json b/test_cases/en.json index 2f0368e9..1c6fad7e 100644 --- a/test_cases/en.json +++ b/test_cases/en.json @@ -201,35 +201,35 @@ "afternoon"]], - "No precipitation throughout the week, with temperatures peaking at 85\u00B0F tomorrow.": + "No precipitation throughout the week, with high temperatures peaking at 85\u00B0F tomorrow.": ["sentence", ["with", ["for-week", "no-precipitation"], ["temperatures-peaking", ["fahrenheit", 85], "tomorrow"]]], - "Mixed precipitation over the weekend, with temperatures rising to 32\u00B0C on Thursday.": + "Mixed precipitation over the weekend, with high temperatures rising to 32\u00B0C on Thursday.": ["sentence", ["with", ["over-weekend", "mixed-precipitation"], ["temperatures-rising", ["celsius", 32], "thursday"]]], - "Drizzle on Monday, with temperatures bottoming out at 15\u00B0F on Friday.": + "Drizzle on Monday, with high temperatures bottoming out at 15\u00B0F on Friday.": ["sentence", ["with", ["during", "very-light-rain", "monday"], ["temperatures-valleying", ["fahrenheit", 15], "friday"]]], - "Light snow on Tuesday and next Wednesday, with temperatures falling to 0\u00B0C on Sunday.": + "Light snow on Tuesday and next Wednesday, with high temperatures falling to 0\u00B0C on Sunday.": ["sentence", ["with", ["during", "light-snow", ["and", "tuesday", "next-wednesday"]], ["temperatures-falling", ["celsius", 0], "sunday"]]], - "Precipitation today through Saturday, with temperatures peaking at 100\u00B0F on Monday.": + "Precipitation today through Saturday, with high temperatures peaking at 100\u00B0F on Monday.": ["sentence", ["with", ["during", "medium-precipitation", diff --git a/test_cases/fr.json b/test_cases/fr.json index a9cb8c27..9344fbec 100644 --- a/test_cases/fr.json +++ b/test_cases/fr.json @@ -201,35 +201,35 @@ "afternoon"]], - "Pas de précipitations pendant toute la semaine, avec des températures atteignant 85\u00B0F demain.": + "Pas de précipitations pendant toute la semaine, avec des températures maximales atteignant 85\u00B0F demain.": ["sentence", ["with", ["for-week", "no-precipitation"], ["temperatures-peaking", ["fahrenheit", 85], "tomorrow"]]], - "Précipitations mêlées pendant tout le week-end, avec des températures montant jusqu’à 32\u00B0C jeudi.": + "Précipitations mêlées pendant tout le week-end, avec des températures maximales montant jusqu’à 32\u00B0C jeudi.": ["sentence", ["with", ["over-weekend", "mixed-precipitation"], ["temperatures-rising", ["celsius", 32], "thursday"]]], - "Bruine aujourd’hui, avec des températures atteignant 15\u00B0F vendredi.": + "Bruine aujourd’hui, avec des températures maximales atteignant 15\u00B0F vendredi.": ["sentence", ["with", ["during", "very-light-rain", "today"], ["temperatures-valleying", ["fahrenheit", 15], "friday"]]], - "Neige faible lundi et mardi, avec des températures descendant jusqu’à 0\u00B0C dimanche.": + "Neige faible lundi et mardi, avec des températures maximales descendant jusqu’à 0\u00B0C dimanche.": ["sentence", ["with", ["during", "light-snow", ["and", "monday", "tuesday"]], ["temperatures-falling", ["celsius", 0], "sunday"]]], - "Précipitations mercredi jusqu’à samedi, avec des températures atteignant 100\u00B0F lundi.": + "Précipitations mercredi jusqu’à samedi, avec des températures maximales atteignant 100\u00B0F lundi.": ["sentence", ["with", ["during", "medium-precipitation", diff --git a/test_cases/nb.json b/test_cases/no.json similarity index 100% rename from test_cases/nb.json rename to test_cases/no.json