Skip to content

Commit fc93b1c

Browse files
committed
add ccplus
1 parent ccd5dea commit fc93b1c

9 files changed

+361
-2235
lines changed

.prettierignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
package.json
2+
package-lock.json

.prettierrc.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = {
2+
semi: true,
3+
trailingComma: 'all',
4+
singleQuote: true,
5+
printWidth: 120,
6+
useTabs: false,
7+
tabWidth: 2,
8+
endOfLine: 'lf',
9+
};

.releaseconfig.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"plugins": ["iobroker", "license", "manual-review"]
3+
}

admin/words.js

+39-40
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,40 @@
1-
/*global systemDictionary:true */
2-
"use strict";
3-
1+
'use strict';
2+
//eslint-disable-next-line
43
systemDictionary = {
5-
"fiat adapter settings": {
6-
"en": "Adapter settings for fiat",
7-
"de": "Adaptereinstellungen für fiat",
8-
"ru": "Настройки адаптера для fiat",
9-
"pt": "Configurações do adaptador para fiat",
10-
"nl": "Adapterinstellingen voor fiat",
11-
"fr": "Paramètres d'adaptateur pour fiat",
12-
"it": "Impostazioni dell'adattatore per fiat",
13-
"es": "Ajustes del adaptador para fiat",
14-
"pl": "Ustawienia adaptera dla fiat",
15-
"zh-cn": "fiat的适配器设置"
16-
},
17-
"option1": {
18-
"en": "option1",
19-
"de": "Option 1",
20-
"ru": "Опция 1",
21-
"pt": "Opção 1",
22-
"nl": "Optie 1",
23-
"fr": "Option 1",
24-
"it": "opzione 1",
25-
"es": "Opción 1",
26-
"pl": "opcja 1",
27-
"zh-cn": "选项1"
28-
},
29-
"option2": {
30-
"en": "option2",
31-
"de": "Option 2",
32-
"ru": "option2",
33-
"pt": "opção 2",
34-
"nl": "Optie 2",
35-
"fr": "Option 2",
36-
"it": "opzione 2",
37-
"es": "opcion 2",
38-
"pl": "Opcja 2",
39-
"zh-cn": "选项2"
40-
}
41-
};
4+
'fiat adapter settings': {
5+
en: 'Adapter settings for fiat',
6+
de: 'Adaptereinstellungen für fiat',
7+
ru: 'Настройки адаптера для fiat',
8+
pt: 'Configurações do adaptador para fiat',
9+
nl: 'Adapterinstellingen voor fiat',
10+
fr: "Paramètres d'adaptateur pour fiat",
11+
it: "Impostazioni dell'adattatore per fiat",
12+
es: 'Ajustes del adaptador para fiat',
13+
pl: 'Ustawienia adaptera dla fiat',
14+
'zh-cn': 'fiat的适配器设置',
15+
},
16+
option1: {
17+
en: 'option1',
18+
de: 'Option 1',
19+
ru: 'Опция 1',
20+
pt: 'Opção 1',
21+
nl: 'Optie 1',
22+
fr: 'Option 1',
23+
it: 'opzione 1',
24+
es: 'Opción 1',
25+
pl: 'opcja 1',
26+
'zh-cn': '选项1',
27+
},
28+
option2: {
29+
en: 'option2',
30+
de: 'Option 2',
31+
ru: 'option2',
32+
pt: 'opção 2',
33+
nl: 'Optie 2',
34+
fr: 'Option 2',
35+
it: 'opzione 2',
36+
es: 'opcion 2',
37+
pl: 'Opcja 2',
38+
'zh-cn': '选项2',
39+
},
40+
};

lib/tools.js

+49-49
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
const axios = require("axios").default;
1+
const axios = require('axios').default;
22

33
/**
44
* Tests whether the given variable is a real object and not an Array
55
* @param {any} it The variable to test
66
* @returns {it is Record<string, any>}
77
*/
88
function isObject(it) {
9-
// This is necessary because:
10-
// typeof null === 'object'
11-
// typeof [] === 'object'
12-
// [] instanceof Object === true
13-
return Object.prototype.toString.call(it) === "[object Object]";
9+
// This is necessary because:
10+
// typeof null === 'object'
11+
// typeof [] === 'object'
12+
// [] instanceof Object === true
13+
return Object.prototype.toString.call(it) === '[object Object]';
1414
}
1515

1616
/**
@@ -19,8 +19,8 @@ function isObject(it) {
1919
* @returns {it is any[]}
2020
*/
2121
function isArray(it) {
22-
if (typeof Array.isArray === "function") return Array.isArray(it);
23-
return Object.prototype.toString.call(it) === "[object Array]";
22+
if (typeof Array.isArray === 'function') return Array.isArray(it);
23+
return Object.prototype.toString.call(it) === '[object Array]';
2424
}
2525

2626
/**
@@ -31,16 +31,16 @@ function isArray(it) {
3131
* @returns {Promise<string>}
3232
*/
3333
async function translateText(text, targetLang, yandexApiKey) {
34-
if (targetLang === "en") {
35-
return text;
36-
} else if (!text) {
37-
return "";
38-
}
39-
if (yandexApiKey) {
40-
return translateYandex(text, targetLang, yandexApiKey);
41-
} else {
42-
return translateGoogle(text, targetLang);
43-
}
34+
if (targetLang === 'en') {
35+
return text;
36+
} else if (!text) {
37+
return '';
38+
}
39+
if (yandexApiKey) {
40+
return translateYandex(text, targetLang, yandexApiKey);
41+
} else {
42+
return translateGoogle(text, targetLang);
43+
}
4444
}
4545

4646
/**
@@ -51,19 +51,19 @@ async function translateText(text, targetLang, yandexApiKey) {
5151
* @returns {Promise<string>}
5252
*/
5353
async function translateYandex(text, targetLang, apiKey) {
54-
if (targetLang === "zh-cn") {
55-
targetLang = "zh";
56-
}
57-
try {
58-
const url = `https://translate.yandex.net/api/v1.5/tr.json/translate?key=${apiKey}&text=${encodeURIComponent(text)}&lang=en-${targetLang}`;
59-
const response = await axios({url, timeout: 15000});
60-
if (response.data && response.data.text && isArray(response.data.text)) {
61-
return response.data.text[0];
62-
}
63-
throw new Error("Invalid response for translate request");
64-
} catch (e) {
65-
throw new Error(`Could not translate to "${targetLang}": ${e}`);
54+
if (targetLang === 'zh-cn') {
55+
targetLang = 'zh';
56+
}
57+
try {
58+
const url = `https://translate.yandex.net/api/v1.5/tr.json/translate?key=${apiKey}&text=${encodeURIComponent(text)}&lang=en-${targetLang}`;
59+
const response = await axios({url, timeout: 15000});
60+
if (response.data && response.data.text && isArray(response.data.text)) {
61+
return response.data.text[0];
6662
}
63+
throw new Error('Invalid response for translate request');
64+
} catch (e) {
65+
throw new Error(`Could not translate to "${targetLang}": ${e}`);
66+
}
6767
}
6868

6969
/**
@@ -73,27 +73,27 @@ async function translateYandex(text, targetLang, apiKey) {
7373
* @returns {Promise<string>}
7474
*/
7575
async function translateGoogle(text, targetLang) {
76-
try {
77-
const url = `http://translate.googleapis.com/translate_a/single?client=gtx&sl=en&tl=${targetLang}&dt=t&q=${encodeURIComponent(text)}&ie=UTF-8&oe=UTF-8`;
78-
const response = await axios({url, timeout: 15000});
79-
if (isArray(response.data)) {
80-
// we got a valid response
81-
return response.data[0][0][0];
82-
}
83-
throw new Error("Invalid response for translate request");
84-
} catch (e) {
85-
if (e.response && e.response.status === 429) {
86-
throw new Error(
87-
`Could not translate to "${targetLang}": Rate-limited by Google Translate`
88-
);
89-
} else {
90-
throw new Error(`Could not translate to "${targetLang}": ${e}`);
91-
}
76+
try {
77+
const url = `http://translate.googleapis.com/translate_a/single?client=gtx&sl=en&tl=${targetLang}&dt=t&q=${encodeURIComponent(text)}&ie=UTF-8&oe=UTF-8`;
78+
const response = await axios({url, timeout: 15000});
79+
if (isArray(response.data)) {
80+
// we got a valid response
81+
return response.data[0][0][0];
82+
}
83+
throw new Error('Invalid response for translate request');
84+
} catch (e) {
85+
if (e.response && e.response.status === 429) {
86+
throw new Error(
87+
`Could not translate to "${targetLang}": Rate-limited by Google Translate`
88+
);
89+
} else {
90+
throw new Error(`Could not translate to "${targetLang}": ${e}`);
9291
}
92+
}
9393
}
9494

9595
module.exports = {
96-
isArray,
97-
isObject,
98-
translateText
96+
isArray,
97+
isObject,
98+
translateText
9999
};

0 commit comments

Comments
 (0)