-
-
Notifications
You must be signed in to change notification settings - Fork 186
/
i18n-z2m-exporter.js
49 lines (41 loc) · 1.7 KB
/
i18n-z2m-exporter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const { devices } = require('zigbee-herdsman-converters');
const settingsSchema = require('../zigbee2mqtt/lib/util/settings.schema.json');
const fs = require('fs');
const camelCase = require('lodash/camelCase');
const startCase = require('lodash/startCase');
let featureDescriptions = {};
let featureNames = {};
const exportDescriptions = ({ features = [], description, name }) => {
featureNames[name] = startCase(camelCase(name));
featureDescriptions[description] = description;
if (Array.isArray(features)) {
features.forEach(exportDescriptions);
} else {
features().forEach(exportDescriptions);
}
};
devices.forEach((device) => {
exportDescriptions({ features: device.exposes });
});
const enTranslationFile = './src/i18n/locales/en.json';
const enTranslations = require(enTranslationFile);
let settingsSchemaDescriptions = {};
let settingsSchemaTitles = {};
const isObject = (value) => value !== null && typeof value === 'object';
const exportSettingsSchemaDescriptions = (obj) => {
Object.entries(obj).forEach(([key, value]) => {
if (isObject(value)) {
exportSettingsSchemaDescriptions(value);
} else if (key === 'description') {
settingsSchemaDescriptions[value] = value;
} else if (key === 'title') {
settingsSchemaTitles[value] = value;
}
});
};
exportSettingsSchemaDescriptions(settingsSchema);
enTranslations.featureDescriptions = featureDescriptions;
enTranslations.featureNames = featureNames;
enTranslations.settingsSchemaDescriptions = settingsSchemaDescriptions;
enTranslations.settingsSchemaTitles = settingsSchemaTitles;
fs.writeFileSync(enTranslationFile, JSON.stringify(enTranslations, null, 4));