Repository: darkskyapp/forecast-io-translations
Pull request #83 (2016-11-15 17:13:27)

Adding catalan language
I added the document ca.js for the Catalan language to your amazing API. I need the translation to catalan for a project I'm developing.

Thx in advance!


Patch:
diff --git a/lib/lang/ca.js b/lib/lang/ca.js
new file mode 100644
index 0000000..e976809
--- /dev/null
+++ b/lib/lang/ca.js
@@ -0,0 +1,147 @@
+function join_with_shared_prefix(a, b, joiner) {
+  var m = a,
+      i = 0,
+      j;
+
+  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);
+}
+
+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")({
+  "clear": "clar",
+  "no-precipitation": "sense precipitacions",
+  "mixed-precipitation": "precipitacions mixtes",
+  "possible-very-light-precipitation": "possibles pluges lleugeres",
+  "very-light-precipitation": "pluges lleugeres",
+  "possible-light-precipitation": "possibles pluges lleugeres",
+  "light-precipitation": "precipitacions lleugeres",
+  "medium-precipitation": "precipitació",
+  "heavy-precipitation": "fortes precipitacions",
+  "possible-very-light-rain": "possible plugim",
+  "very-light-rain": "plugim",
+  "possible-light-rain": "possible plugim",
+  "light-rain": "pluja lleugera",
+  "medium-rain": "pluja",
+  "heavy-rain": "plujes fortes",
+  "possible-very-light-sleet": "possible aiguaneu",
+  "very-light-sleet": "aiguaneu",
+  "possible-light-sleet": "possible aiguaneu",
+  "light-sleet": "aiguaneu",
+  "medium-sleet": "aiguaneu",
+  "heavy-sleet": "fortes aiguaneu",
+  "possible-very-light-snow": "possible nevada lleugera",
+  "very-light-snow": "lleugeres nevades",
+  "possible-light-snow": "possible nevada lleugera",
+  "light-snow": "lleugeres nevades",
+  "medium-snow": "nevades",
+  "heavy-snow": "fortes nevades",
+  "light-wind": "vents fluixos",
+  "medium-wind": "ventós",
+  "heavy-wind": "perillosament ventós",
+  "low-humidity": "sec",
+  "high-humidity": "humit",
+  "fog": "ennuvolat",
+  "light-clouds": "parcialment ennuvolat",
+  "medium-clouds": "majoritariament ennuvolat",
+  "heavy-clouds": "ennuvolat",
+  "today-morning": "aquest matí",
+  "later-today-morning": "durant el matí",
+  "today-afternoon": "aquesta tarda",
+  "later-today-afternoon": "durant la tarda",
+  "today-evening": "aquest vespre",
+  "later-today-evening": "durant el vespre",
+  "today-night": "aquesta nit",
+  "later-today-night": "durant la nit",
+  "tomorrow-morning": "demà al matí",
+  "tomorrow-afternoon": "demà a la tarda",
+  "tomorrow-evening": "demà al vespre",
+  "tomorrow-night": "demà a la nit",
+  "morning": "al matí",
+  "afternoon": "a la tarda",
+  "evening": "al vespre",
+  "night": "a la nit",
+  "today": "avui",
+  "tomorrow": "demà",
+  "sunday": "el Diumenge",
+  "monday": "el Dilluns",
+  "tuesday": "el Dimarts",
+  "wednesday": "el Dimecres",
+  "thursday": "el Dijous",
+  "friday": "el Divendres",
+  "saturday": "el Dissabte",
+  "minutes": "$1 min.",
+  "fahrenheit": "$1\u00B0F",
+  "celsius": "$1\u00B0C",
+  "inches": "$1 in.",
+  "centimeters": "$1 cm.",
+  "less-than": "menys de $1",
+  "and": function(a, b) {
+    return join_with_shared_prefix(
+      a,
+      b,
+      a.indexOf(",") !== -1 ? ", i " : " i "
+    );
+  },
+  "through": function(a, b) {
+    return join_with_shared_prefix(a, b, " fins a ");
+  },
+  "with": "$1, amb $2",
+  "range": "$1\u2013$2",
+  "parenthetical": "$1 ($2)",
+  "for-hour": "$1 cada hora",
+  "starting-in": "$1 començant $2",
+  "stopping-in": "$1 parant a $2",
+  "starting-then-stopping-later": "$1 començant d'aquí $2, després parant al cap $3",
+  "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);
+  },
+  "during": "$1 $2",
+  "for-week": "$1 durant la setmana",
+  "over-weekend": "$1 cap al cap de setmana",
+  "temperatures-peaking": "temperatures aconseguint un màxim de $1 $2",
+  "temperatures-rising": "temperatures arribant a $1 $2",
+  "temperatures-valleying": "temperatures aconseguint un mínim de $1 $2",
+  "temperatures-falling": "temperatures per sota a $1 $2",
+  /* Capitalize the first letter of every word, except if that word is "y". */
+  "title": function(str) {
+    return str.replace(/\S+/g, function(word) {
+      return word === "i" ?
+        word :
+        word.charAt(0).toUpperCase() + word.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;
+  }
+});


Test patch:
diff --git a/test_cases/ca.json b/test_cases/ca.json
new file mode 100644
index 0000000..5b6ac9a
--- /dev/null
+++ b/test_cases/ca.json
@@ -0,0 +1,238 @@
+{
+  "Clar":
+    ["title", "clear"],
+
+  "Possibles Pluges Lleugeres":
+    ["title", "possible-very-light-precipitation"],
+
+  "Precipitacions Lleugeres":
+    ["title", "very-light-precipitation"],
+
+  "Possibles Pluges Lleugeres":
+    ["title", "possible-light-precipitation"],
+
+  "Precipitacions Lleugeres":
+    ["title", "light-precipitation"],
+
+  "Precipitació":
+    ["title", "medium-precipitation"],
+
+  "Fortes Precipitacions":
+    ["title", "heavy-precipitation"],
+
+  "Possible Plugim":
+    ["title", "possible-very-light-rain"],
+
+  "Plugim":
+    ["title", "very-light-rain"],
+
+  "Possible Plugim":
+    ["title", "possible-light-rain"],
+
+  "Pluja Lleugera":
+    ["title", "light-rain"],
+
+  "Pluja":
+    ["title", "medium-rain"],
+
+  "Plujes Fortes":
+    ["title", "heavy-rain"],
+
+  "Aiguaneu":
+    ["title", "possible-very-light-sleet"],
+
+  "Aiguaneu":
+    ["title", "very-light-sleet"],
+
+  "Possible Aiguaneu":
+    ["title", "possible-light-sleet"],
+
+  "Aiguaneu":
+    ["title", "light-sleet"],
+
+  "Aiguaneu":
+    ["title", "medium-sleet"],
+
+  "Fortes Aiguaneu":
+    ["title", "heavy-sleet"],
+
+  "Possible Nevada Lleugera":
+    ["title", "possible-very-light-snow"],
+
+  "Lleugeres Nevades":
+    ["title", "very-light-snow"],
+
+  "Possible Nevada Lleugera":
+    ["title", "possible-light-snow"],
+
+  "Lleugeres Nevades":
+    ["title", "light-snow"],
+
+  "Nevades":
+    ["title", "medium-snow"],
+
+  "Fortes Nevades":
+    ["title", "heavy-snow"],
+
+  "Ventós":
+    ["title", "medium-wind"],
+
+  "Perillosament Ventós":
+    ["title", "heavy-wind"],
+
+  "Ennuvolat":
+    ["title", "fog"],
+
+  "Majoritariament Ennuvolat":
+    ["title", "medium-clouds"],
+
+  "Ennuvolat":
+    ["title", "heavy-clouds"],
+
+  "Sec i Vents Fluixos":
+    ["title", ["and", "low-humidity", "light-wind"]],
+
+  "Plugim i Perillosament Ventós":
+    ["title", ["and", "very-light-rain", "heavy-wind"]],
+
+  "Humit i Parcialment Ennuvolat":
+    ["title", ["and", "high-humidity", "light-clouds"]],
+
+  "Clar cada hora.":
+    ["sentence", ["for-hour", "clear"]],
+
+  "Lleugeres nevades començant 35 min.":
+    ["sentence", ["starting-in", "very-light-snow", ["minutes", 35]]],
+
+  "Pluja lleugera parant a 15 min.":
+    ["sentence", ["stopping-in", "light-rain", ["minutes", 15]]],
+
+  "Fortes aiguaneu començant d'aquí 20 min., després parant al cap 30 min.":
+    ["sentence",
+      ["starting-then-stopping-later",
+        "heavy-sleet",
+        ["minutes", 20],
+        ["minutes", 30]]],
+
+  "Pluja parant d'aquí 25 min., tornant a començar al cap 8 min.":
+    ["sentence",
+      ["stopping-then-starting-later",
+        "medium-rain",
+        ["minutes", 25],
+        ["minutes", 8]]],
+
+  "Majoritariament ennuvolat durant el dia.":
+    ["sentence", ["for-day", "medium-clouds"]],
+
+  "Aiguaneu començant al matí.":
+    ["sentence", ["starting", "very-light-sleet", "morning"]],
+
+  "Ventós aquesta nit.":
+    ["sentence", ["until", "medium-wind", "today-night"]],
+
+  "Fortes precipitacions a la tarda.":
+    ["sentence", ["until", "heavy-precipitation", "afternoon"]],
+
+  "Vents fluixos a la tarda.":
+    ["sentence", ["during", "light-wind", "afternoon"]],
+
+  "Nevades durant el vespre i demà al matí.":
+    ["sentence", ["during",
+      "medium-snow",
+      ["and", "later-today-evening", "tomorrow-morning"]]],
+
+  "Plujes fortes durant el matí, començant aquest vespre.":
+    ["sentence", ["until-starting-again",
+      "heavy-rain",
+      "later-today-morning",
+      "today-evening"]],
+
+  "Ennuvolat començant al vespre, continuant a la nit.":
+    ["sentence", ["starting-continuing-until",
+      "heavy-clouds",
+      "evening",
+      "night"]],
+
+  "Aiguaneu durant la tarda i ennuvolat demà al matí.":
+    ["sentence", ["and",
+      ["during", "light-sleet", "later-today-afternoon"],
+      ["during", "fog", "tomorrow-morning"]]],
+
+  "Perillosament ventós començant aquest matí, continuant aquesta tarda, i aiguaneu demà al matí.":
+    ["sentence", ["and",
+      ["starting-continuing-until",
+        "heavy-wind",
+        "today-morning",
+        "today-afternoon"],
+      ["during", "medium-sleet", "tomorrow-morning"]]],
+
+  "Ennuvolat començant durant la nit i fortes nevades demà a la tarda.":
+    ["sentence", ["and",
+      ["starting", "heavy-clouds", "later-today-night"],
+      ["during", "heavy-snow", "tomorrow-afternoon"]]],
+
+  "Sec aquesta nit i precipitacions lleugeres començant demà al vespre, continuant demà a la nit.":
+    ["sentence", ["and",
+      ["during", "low-humidity", "today-night"],
+      ["starting-continuing-until",
+        "light-precipitation",
+        "tomorrow-evening",
+        "tomorrow-night"]]],
+
+  "Nevades (5 in.) a la nit.":
+    ["sentence", ["during",
+      ["parenthetical", "medium-snow", ["inches", 5]],
+      "night"]],
+
+  "Lleugeres nevades (2 cm.) durant el matí.":
+    ["sentence", ["during",
+      ["parenthetical", "light-snow", ["centimeters", 2]],
+      "later-today-morning"]],
+
+  "Fortes nevades (8–12 in.) durant el dia.":
+    ["sentence", ["for-day",
+      ["parenthetical", "heavy-snow", ["inches", ["range", 8, 12]]]]],
+
+  "Nevades (menys de 1 cm.) a la tarda.":
+    ["sentence", ["during",
+      ["parenthetical", "medium-snow", ["less-than", ["centimeters", 1]]],
+      "afternoon"]],
+
+
+  "Sense precipitacions durant la setmana, amb temperatures aconseguint un màxim de 85\u00B0F demà.":
+    ["sentence", ["with",
+      ["for-week", "no-precipitation"],
+      ["temperatures-peaking",
+        ["fahrenheit", 85],
+        "tomorrow"]]],
+
+  "Precipitacions mixtes cap al cap de setmana, amb temperatures arribant a 32\u00B0C el Dijous.":
+    ["sentence", ["with",
+      ["over-weekend", "mixed-precipitation"],
+      ["temperatures-rising",
+        ["celsius", 32],
+        "thursday"]]],
+
+  "Plugim el Dilluns, amb temperatures aconseguint un mínim de 15\u00B0F el Divendres.":
+    ["sentence", ["with",
+      ["during", "very-light-rain", "monday"],
+      ["temperatures-valleying",
+        ["fahrenheit", 15],
+        "friday"]]],
+
+  "Lleugeres nevades el Dimarts i Dimecres, amb temperatures per sota a 0\u00B0C el Diumenge.":
+    ["sentence", ["with",
+      ["during", "light-snow", ["and", "tuesday", "wednesday"]],
+      ["temperatures-falling",
+        ["celsius", 0],
+        "sunday"]]],
+
+  "Precipitació avui fins a el Dissabte, amb temperatures aconseguint un màxim de 100\u00B0F el Dilluns.":
+    ["sentence", ["with",
+      ["during",
+        "medium-precipitation",
+        ["through", "today", "saturday"]],
+      ["temperatures-peaking",
+        ["fahrenheit", 100],
+        "monday"]]]
+}