Skip to content

Commit

Permalink
Translations and configurable digits for numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Osterkamp authored and Daniel Osterkamp committed Nov 11, 2020
1 parent 9c7c7b9 commit 8e39d2b
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 9 deletions.
26 changes: 17 additions & 9 deletions MMM-COVID19-AMPEL.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Module.register("MMM-COVID19-AMPEL", {
showCasesPerPeople: true,
showDeathRatePerPeople: true,
show7DayIncidence: true,
numberOfDigits: 2,
updateInterval: 3600000, // update interval in milliseconds
fadeSpeed: 4000,
updateDate: "no update received yet",
Expand All @@ -30,6 +31,13 @@ Module.register("MMM-COVID19-AMPEL", {
return ["MMM-COVID19-AMPEL.css"];
},

getTranslations: function() {
return {
en: "translations/en.json",
de: "translations/de.json"
}
},

start: function () {
this.getInfo();
this.scheduleUpdate();
Expand Down Expand Up @@ -87,22 +95,22 @@ Module.register("MMM-COVID19-AMPEL", {
let incident7DayNumber = document.createElement("td");
let incidentStateColorb = document.createElement("td");

incidentCityName.innerHTML = "Location";
incidentCityName.innerHTML = this.translate('Location');
incidentCityName.className = this.config.infoRowClass;

incidentUpdateDate.innerHTML = "Updated on";
incidentUpdateDate.innerHTML = this.translate('Updated on');
incidentUpdateDate.className = this.config.infoRowClass;

totalCases.innerHTML = "Infections";
totalCases.innerHTML = this.translate('Infections');
totalCases.className = this.config.infoRowClass;

casesPerCapita.innerHTML = "Infection rate %";
casesPerCapita.innerHTML = this.translate('Infection rate %');
casesPerCapita.className = this.config.infoRowClass;

deathPerInfection.innerHTML = "Death rate %";
deathPerInfection.innerHTML = this.translate('Death rate %');
deathPerInfection.className = this.config.infoRowClass;

incident7DayNumber.innerHTML = "Incidence value";
incident7DayNumber.innerHTML = this.translate('Incidence value');
incident7DayNumber.className = this.config.infoRowClass;

if (this.config.showStatusLightLeft) {
Expand Down Expand Up @@ -159,18 +167,18 @@ Module.register("MMM-COVID19-AMPEL", {
}
if (this.config.showCasesPerPeople) {
casesPerCapita.innerHTML =
element.cases_per_population.toFixed(2) + "%";
element.cases_per_population.toFixed(this.config.numberOfDigits) + "%";
casesPerCapita.className = this.config.infoRowClass;
}
if (this.config.showDeathRatePerPeople) {
deathPerInfection.innerHTML = element.death_rate.toFixed(2) + "%";
deathPerInfection.innerHTML = element.death_rate.toFixed(this.config.numberOfDigits) + "%";
deathPerInfection.className = this.config.infoRowClass;
}
if (this.config.show7DayIncidence) {
incident7DayNumber.className = this.config.infoRowClass;
incident7DayNumber.innerHTML = (
Math.round(element.cases7_per_100k * 100) / 100
).toFixed(2);
).toFixed(this.config.numberOfDigits);
}
incidentStateColora.innerHTML = "__";
incidentStateColorb.innerHTML = "__";
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ The following properties can be configured:
| `showCasesPerPeople` | Show % of cases per people in this city/region <br><br> **Possible bool values:** `true`, `false` <br> **Default value:** `true`
| `showDeathRatePerPeople` | Show death rate of people <br><br> **Possible bool values:** `true`, `false` <br> **Default value:** `true`
| `show7DayIncidence` | Show 7 day incidence value which corresponds to the status light <br><br> **Possible bool values:** `true`, `false` <br> **Default value:** `true`
| `numberOfDigits` | Number of digits for percentage values to show.<br><br> **Possible int values:** `0`, `1` or `2` <br> **Default value:** `2`
| `fadeSpeed` | Fading speed when module is updating. No need to change it... <br><br> **Possible values:** `1000` - `86400000` <br> **Default value:** `4000`

## Config Example
Expand All @@ -65,6 +66,7 @@ The following properties can be configured:
showCasesPerPeople: true, //Show Percentage of active cases per inhabitant
showDeathRatePerPeople: true, //show death rate in % of infected people
show7DayIncidence: true, // Show 7 day incidence value for your location
numberOfDigits: 2 //Round the Percentage and incidence value to number of digits
updateInterval: 3600000, // update interval in milliseconds // 1 Hour - Values are only refreshed every 24 H on Server
fadeSpeed: 4000
}
Expand Down
8 changes: 8 additions & 0 deletions translations/de.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Location": "Ort",
"Updated on": "Update am",
"Infections": "Infektionen",
"Infection rate %": "Infizierte in %",
"Death rate %": "Todesrate in %",
"Incidence value": "Inzidenzwert"
}
8 changes: 8 additions & 0 deletions translations/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Location": "Location",
"Updated on": "Updated on",
"Infections": "Infections",
"Infection rate %": "Infection rate %",
"Death rate %": "Death rate %",
"Incidence value": "Incidence value"
}

0 comments on commit 8e39d2b

Please sign in to comment.