Add language to plugin via dict object

This commit is contained in:
Luis Riegger 2021-05-04 08:46:12 +02:00
parent 010e177306
commit bdb5807aeb
2 changed files with 56 additions and 13 deletions

View File

@ -38,6 +38,48 @@ function NeatoVacuumRobotAccessory(platform, robotObject)
this.spotPlusFeatures = ((typeof robotObject.availableServices.spotCleaning !== 'undefined') && robotObject.availableServices.spotCleaning.includes("basic")); this.spotPlusFeatures = ((typeof robotObject.availableServices.spotCleaning !== 'undefined') && robotObject.availableServices.spotCleaning.includes("basic"));
this.boundary = (typeof robotObject.boundary === 'undefined') ? null : robotObject.boundary; this.boundary = (typeof robotObject.boundary === 'undefined') ? null : robotObject.boundary;
this.dict = {
'en': {
"clean": "Clean",
"clean the": "Clean the",
"goToDock": "Go to Dock",
"dockState": "Dock",
"eco": "Eco Mode",
"noGoLines": "NoGo Lines",
"extraCare": "Extra Care",
"schedule": "Schedule",
"findMe": "Find me",
"cleanSpot": "Clean Spot",
"battery": "Battery"
},
'de': {
"clean": "Sauge",
"clean the": "Sauge",
"goToDock": "Zur Basis",
"dockState": "In der Basis",
"eco": "Eco Modus",
"noGoLines": "NoGo Linien",
"extraCare": "Extra Care",
"schedule": "Zeitplan",
"findMe": "Finde mich",
"cleanSpot": "Spot Reinigung",
"battery": "Batterie"
},
'fr': {
"clean": "Aspirer",
"clean the": "Aspirer",
"goToDock": "Retour à la base",
"dockState": "Sur la base",
"eco": "Eco mode",
"noGoLines": "Lignes NoGo",
"extraCare": "Extra Care",
"schedule": "Planifier",
"findMe": "Me retrouver",
"cleanSpot": "Nettoyage local",
"battery": "Batterie"
}
}[this.platform.language]
if (this.boundary == null) if (this.boundary == null)
{ {
this.name = this.robot.name; this.name = this.robot.name;
@ -64,20 +106,20 @@ function NeatoVacuumRobotAccessory(platform, robotObject)
this.name = this.robot.name + ' - ' + this.boundary.name; this.name = this.robot.name + ' - ' + this.boundary.name;
} }
this.batteryService = new Service.BatteryService("Battery", "battery"); this.batteryService = new Service.BatteryService(this.name + " " + this.dict["battery"], "battery");
if (this.boundary == null) if (this.boundary == null)
{ {
this.cleanService = new Service.Switch(this.name + " Clean", "clean"); this.cleanService = new Service.Switch(this.name + " " + this.dict["clean"], "clean");
this.goToDockService = new Service.Switch(this.name + " Go to Dock", "goToDock"); this.goToDockService = new Service.Switch(this.name + " " + this.dict["goToDock"], "goToDock");
this.dockStateService = new Service.OccupancySensor(this.name + " Dock", "dockState"); this.dockStateService = new Service.OccupancySensor(this.name + " " + this.dict["dockState"], "dockState");
this.ecoService = new Service.Switch(this.name + " Eco Mode", "eco"); this.ecoService = new Service.Switch(this.name + " " + this.dict["eco"], "eco");
this.noGoLinesService = new Service.Switch(this.name + " NoGo Lines", "noGoLines"); this.noGoLinesService = new Service.Switch(this.name + " " + this.dict["noGoLines"], "noGoLines");
this.extraCareService = new Service.Switch(this.name + " Extra Care", "extraCare"); this.extraCareService = new Service.Switch(this.name + " " + this.dict["extraCare"], "extraCare");
this.scheduleService = new Service.Switch(this.name + " Schedule", "schedule"); this.scheduleService = new Service.Switch(this.name + " " + this.dict["schedule"], "schedule");
this.findMeService = new Service.Switch(this.name + " Find Me", "findMe"); this.findMeService = new Service.Switch(this.name + " " + this.dict["findMe"], "findMe");
this.spotCleanService = new Service.Switch(this.name + " Clean Spot", "cleanSpot"); this.spotCleanService = new Service.Switch(this.name + " " + this.dict["cleanSpot"], "cleanSpot");
this.spotCleanService.addCharacteristic(SpotRepeatCharacteristic); this.spotCleanService.addCharacteristic(SpotRepeatCharacteristic);
if (this.spotPlusFeatures) if (this.spotPlusFeatures)
{ {
@ -88,10 +130,10 @@ function NeatoVacuumRobotAccessory(platform, robotObject)
else else
{ {
const splitName = this.boundary.name.split(' '); const splitName = this.boundary.name.split(' ');
let serviceName = "Clean the " + this.boundary.name; let serviceName = this.dict["clean the"] + " " + this.boundary.name;
if (splitName.length >= 2 && splitName[splitName.length - 2].match(/[']s$/g)) if (splitName.length >= 2 && splitName[splitName.length - 2].match(/[']s$/g))
{ {
serviceName = "Clean " + this.boundary.name; serviceName = this.dict["clean"] + " " + this.boundary.name;
} }
this.cleanService = new Service.Switch(serviceName, "cleanBoundary:" + this.boundary.id); this.cleanService = new Service.Switch(serviceName, "cleanBoundary:" + this.boundary.id);
} }
@ -679,4 +721,4 @@ NeatoVacuumRobotAccessory.prototype = {
}); });
} }
} }
}; };

View File

@ -21,6 +21,7 @@ function NeatoVacuumRobotPlatform(log, config)
this.serial = "1-3-3-7"; this.serial = "1-3-3-7";
this.email = config['email']; this.email = config['email'];
this.password = config['password']; this.password = config['password'];
this.language = config['language'];
this.hiddenServices = ''; this.hiddenServices = '';
this.hiddenServices = ('disabled' in config ? config['disabled'] : this.hiddenServices); this.hiddenServices = ('disabled' in config ? config['disabled'] : this.hiddenServices);
this.hiddenServices = ('hidden' in config ? config['hidden'] : this.hiddenServices); this.hiddenServices = ('hidden' in config ? config['hidden'] : this.hiddenServices);