Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add translations #29

Merged
merged 19 commits into from
Jan 4, 2024
59 changes: 38 additions & 21 deletions MMM-AirQuality.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ Module.register('MMM-AirQuality', {
DATA: 'AIR_QUALITY_DATA',
DATA_RESPONSE: 'AIR_QUALITY_DATA_RESPONSE',
},
colors: {
GOOD: '#009966',
MODERATE: '#ffde33',
UNHEALTHY_FOR_SENSITIVE_GROUPS: '#ff9933',
UNHEALTHY: '#cc0033',
HAZARDOUS: '#7e0023',
UNKNOWN: '#333333',
},
start: function () {
const self = this
Log.info(`Starting module: ${this.name}`)
Expand All @@ -42,23 +50,19 @@ Module.register('MMM-AirQuality', {
this.data.value = data.aqi
this.data.city = data.city.name
this.loaded = true

if (data.aqi < 51) {
this.data.color = '#009966'
this.data.impact = 'Good'
} else if (data.aqi < 101) {
this.data.color = '#ffde33'
this.data.impact = 'Moderate'
} else if (data.aqi < 151) {
this.data.color = '#ff9933'
this.data.impact = 'Unhealty for Sensitive Groups'
} else if (data.aqi < 201) {
this.data.color = '#cc0033'
this.data.impact = 'Unhealthy'
} else if (data.aqi < 301) {
this.data.color = '#7e0023'
this.data.impact = 'Hazardous'
}
this.data.impact = this.getImpact(data.aqi)
this.data.color = this.getColor(this.data.impact)
},
getImpact: function (aqi) {
if (aqi < 51) return 'GOOD'
if (aqi < 101) return 'MODERATE'
if (aqi < 151) return 'UNHEALTHY_FOR_SENSITIVE_GROUPS'
if (aqi < 201) return 'UNHEALTHY'
if (aqi < 301) return 'HAZARDOUS'
return 'UNKNOWN'
},
getColor: function (impact) {
return this.colors[impact]
},
html: {
icon: '<i class="fa-solid fa-smog"></i>',
Expand All @@ -77,8 +81,15 @@ Module.register('MMM-AirQuality', {
// Override getHeader method.
getHeader: function () {
let header = ''
if (this.data.header) { header += this.data.header }
if (this.config.appendLocationNameToHeader) {
if (this.data.header !== '') {
if (this.data.header === undefined) {
header += this.translate('HEADER')
} else {
header += this.data.header
}
}

if (this.loaded && this.config.appendLocationNameToHeader) {
if (header !== '') {
header += ' '
}
Expand All @@ -101,19 +112,25 @@ Module.register('MMM-AirQuality', {
}

if (!this.loaded) {
wrapper.innerHTML = 'Loading air quality index ...'
wrapper.innerHTML = this.translate('LOADING')
wrapper.className = 'dimmed light small'
return wrapper
}
wrapper.innerHTML =
this.html.quality.format(
this.data.color,
this.html.icon,
this.data.impact,
this.translate(this.data.impact),
(this.config.showIndex ? ' (' + this.data.value + ')' : '')) +
(this.config.showLocation && !this.config.appendLocationNameToHeader ? this.html.city.format(this.data.city) : '')
return wrapper
},
getTranslations: function () {
return {
en: 'l10n/en.json', // fallback language
de: 'l10n/de.json',
}
},
socketNotificationReceived: function (notification, payload) {
const self = this
Log.debug('received ' + notification)
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@ Add the module configuration to your `config.js` file.
{
module: 'MMM-AirQuality',
position: 'top_center', // you may choose any location
header: 'AQI', //choose a header if you like
config: {
location: 'beijing' // the location to check the index for
token: '' // add your token here
location: 'beijing' // the location to check the index for
}
},
```
Expand Down
9 changes: 9 additions & 0 deletions l10n/de.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"HEADER": "Luftqualität",
"GOOD": "gut",
"MODERATE": "moderat",
"UNHEALTHY_FOR_SENSITIVE_GROUPS": "ungesund für gefährdete Gruppen",
"UNHEALTHY": "ungesund",
"HAZARDOUS": "gefährlich",
"UNKNOWN": "unbekannt"
}
9 changes: 9 additions & 0 deletions l10n/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"HEADER": "Air Quality",
"GOOD": "Good",
"MODERATE": "Moderate",
"UNHEALTHY_FOR_SENSITIVE_GROUPS": "Unhealty for Sensitive Groups",
"UNHEALTHY": "Unhealthy",
"HAZARDOUS": "Hazardous",
"UNKNOWN": "Unknown"
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"scripts": {
"validate": "npm run validate:js && npm run validate:md",
"validate:js": "eslint **/*.js",
"validate:md": "node_modules/.bin/markdownlint *.md"
"validate:md": "node_modules/.bin/markdownlint *.md",
"fix:js": "eslint **/*.js --fix"
},
"devDependencies": {
"eslint": "8.56.0",
Expand Down