From 2bdf1afda729827016cacafca587bc69f63cd893 Mon Sep 17 00:00:00 2001 From: adrian w kirk Date: Sun, 18 Apr 2021 09:38:33 +0100 Subject: [PATCH] sliding text clock - forgot to add spanish language module --- apps/slidingtext/custom.html | 2 +- apps/slidingtext/slidingtext.locale.es.js | 77 +++++++++++++++++++++++ 2 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 apps/slidingtext/slidingtext.locale.es.js diff --git a/apps/slidingtext/custom.html b/apps/slidingtext/custom.html index e20dd2919..5023d9a3d 100644 --- a/apps/slidingtext/custom.html +++ b/apps/slidingtext/custom.html @@ -23,7 +23,7 @@ {name:"English", shortname:"en"}, {name:"English(Traditional)",shortname:"en2"}, {name:"French",shortname:"fr"}, - {name:"Japanese",shortname:"jp"} + {name:"Japanese",shortname:"jp"}, {name:"Spanish",shortname:"es"} ]; var selected_languages = ["en","es","jp"]; diff --git a/apps/slidingtext/slidingtext.locale.es.js b/apps/slidingtext/slidingtext.locale.es.js new file mode 100644 index 000000000..e1f3bc18b --- /dev/null +++ b/apps/slidingtext/slidingtext.locale.es.js @@ -0,0 +1,77 @@ +var DateFormatter = require("slidingtext.dtfmt.js"); + +const spanishNumberStr = [ ["ZERO"], // 0 + ["UNA",""], // 1 + ["DOS",""], //2 + ["TRES",''], //3 + ["CUATRO",''], //4 + ["CINCO",''], //5 + ["SEIS",''], //6 + ["SEITO",''], //7 + ["OCHO",''], //8 + ["NUEVE",''], // 9, + ["DIEZ",''], // 10 + ["ONCE",''], // 11, + ["DOCE",''], // 12 + ["TRECE",''], // 13 + ["CATORCE",''], // 14 + ["QUINCE",''], // 15 + ["DIECI",'SEIS'], // 16 + ["DIECI",'SIETE'], // 17 + ["DIECI",'OCHO'], // 18 + ["DIECI",'NEUVE'], // 19 + ["VEINTA",''], // 20 + ["VEINTI",'UNO'], // 21 + ["VEINTI",'DOS'], // 22 + ["VEINTI",'TRES'], // 23 + ["VEINTI",'CUATRO'], // 24 + ["VEINTI",'CINCO'], // 25 + ["VEINTI",'SEIS'], // 26 + ["VEINTI",'SIETE'], // 27 + ["VEINTI",'OCHO'], // 28 + ["VEINTI",'NUEVE'] // 29 + ]; + +function spanishHoursToText(hours){ + hours = hours % 12; + if(hours == 0){ + hours = 12; + } + return spanishNumberStr[hours][0]; +} + +function spanishMinsToText(mins){ + return spanishNumberStr[mins]; +} + +class SpanishDateFormatter extends DateFormatter { + constructor() { super();} + name(){return "Spanish";} + formatDate(date){ + var mins = date.getMinutes(); + var hourOfDay = date.getHours(); + if(mins > 30){ + hourOfDay += 1; + } + var hours = spanishHoursToText(hourOfDay); + //console.log('hourOfDay->' + hourOfDay + ' hours text->' + hours) + // Deal with the special times first + if(mins == 0){ + return [hours,"", "","",""]; + } else if(mins == 30){ + return [hours, "Y", "MEDIA",""]; + } else if(mins == 15){ + return [hours, "Y", "CUARTO",""]; + } else if(mins == 45) { + return [hours, "MENOS", "CUARTO",""]; + } else if(mins > 30){ + var mins_txt = spanishMinsToText(60-mins); + return [hours, "MENOS", mins_txt[0],mins_txt[1]]; + } else { + var mins_txt = spanishMinsToText(mins); + return [hours, "Y", mins_txt[0],mins_txt[1]]; + } + } +} + +module.exports = SpanishDateFormatter; \ No newline at end of file