Skip to content

Commit

Permalink
add ccplus
Browse files Browse the repository at this point in the history
  • Loading branch information
TA2k committed Jun 9, 2024
1 parent ccd5dea commit fc93b1c
Show file tree
Hide file tree
Showing 9 changed files with 361 additions and 2,235 deletions.
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
package.json
package-lock.json
9 changes: 9 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
semi: true,
trailingComma: 'all',
singleQuote: true,
printWidth: 120,
useTabs: false,
tabWidth: 2,
endOfLine: 'lf',
};
3 changes: 3 additions & 0 deletions .releaseconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"plugins": ["iobroker", "license", "manual-review"]
}
79 changes: 39 additions & 40 deletions admin/words.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,40 @@
/*global systemDictionary:true */
"use strict";

'use strict';
//eslint-disable-next-line
systemDictionary = {
"fiat adapter settings": {
"en": "Adapter settings for fiat",
"de": "Adaptereinstellungen für fiat",
"ru": "Настройки адаптера для fiat",
"pt": "Configurações do adaptador para fiat",
"nl": "Adapterinstellingen voor fiat",
"fr": "Paramètres d'adaptateur pour fiat",
"it": "Impostazioni dell'adattatore per fiat",
"es": "Ajustes del adaptador para fiat",
"pl": "Ustawienia adaptera dla fiat",
"zh-cn": "fiat的适配器设置"
},
"option1": {
"en": "option1",
"de": "Option 1",
"ru": "Опция 1",
"pt": "Opção 1",
"nl": "Optie 1",
"fr": "Option 1",
"it": "opzione 1",
"es": "Opción 1",
"pl": "opcja 1",
"zh-cn": "选项1"
},
"option2": {
"en": "option2",
"de": "Option 2",
"ru": "option2",
"pt": "opção 2",
"nl": "Optie 2",
"fr": "Option 2",
"it": "opzione 2",
"es": "opcion 2",
"pl": "Opcja 2",
"zh-cn": "选项2"
}
};
'fiat adapter settings': {
en: 'Adapter settings for fiat',
de: 'Adaptereinstellungen für fiat',
ru: 'Настройки адаптера для fiat',
pt: 'Configurações do adaptador para fiat',
nl: 'Adapterinstellingen voor fiat',
fr: "Paramètres d'adaptateur pour fiat",
it: "Impostazioni dell'adattatore per fiat",
es: 'Ajustes del adaptador para fiat',
pl: 'Ustawienia adaptera dla fiat',
'zh-cn': 'fiat的适配器设置',
},
option1: {
en: 'option1',
de: 'Option 1',
ru: 'Опция 1',
pt: 'Opção 1',
nl: 'Optie 1',
fr: 'Option 1',
it: 'opzione 1',
es: 'Opción 1',
pl: 'opcja 1',
'zh-cn': '选项1',
},
option2: {
en: 'option2',
de: 'Option 2',
ru: 'option2',
pt: 'opção 2',
nl: 'Optie 2',
fr: 'Option 2',
it: 'opzione 2',
es: 'opcion 2',
pl: 'Opcja 2',
'zh-cn': '选项2',
},
};
98 changes: 49 additions & 49 deletions lib/tools.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
const axios = require("axios").default;
const axios = require('axios').default;

/**
* Tests whether the given variable is a real object and not an Array
* @param {any} it The variable to test
* @returns {it is Record<string, any>}
*/
function isObject(it) {
// This is necessary because:
// typeof null === 'object'
// typeof [] === 'object'
// [] instanceof Object === true
return Object.prototype.toString.call(it) === "[object Object]";
// This is necessary because:
// typeof null === 'object'
// typeof [] === 'object'
// [] instanceof Object === true
return Object.prototype.toString.call(it) === '[object Object]';
}

/**
Expand All @@ -19,8 +19,8 @@ function isObject(it) {
* @returns {it is any[]}
*/
function isArray(it) {
if (typeof Array.isArray === "function") return Array.isArray(it);
return Object.prototype.toString.call(it) === "[object Array]";
if (typeof Array.isArray === 'function') return Array.isArray(it);
return Object.prototype.toString.call(it) === '[object Array]';
}

/**
Expand All @@ -31,16 +31,16 @@ function isArray(it) {
* @returns {Promise<string>}
*/
async function translateText(text, targetLang, yandexApiKey) {
if (targetLang === "en") {
return text;
} else if (!text) {
return "";
}
if (yandexApiKey) {
return translateYandex(text, targetLang, yandexApiKey);
} else {
return translateGoogle(text, targetLang);
}
if (targetLang === 'en') {
return text;
} else if (!text) {
return '';
}
if (yandexApiKey) {
return translateYandex(text, targetLang, yandexApiKey);
} else {
return translateGoogle(text, targetLang);
}
}

/**
Expand All @@ -51,19 +51,19 @@ async function translateText(text, targetLang, yandexApiKey) {
* @returns {Promise<string>}
*/
async function translateYandex(text, targetLang, apiKey) {
if (targetLang === "zh-cn") {
targetLang = "zh";
}
try {
const url = `https://translate.yandex.net/api/v1.5/tr.json/translate?key=${apiKey}&text=${encodeURIComponent(text)}&lang=en-${targetLang}`;
const response = await axios({url, timeout: 15000});
if (response.data && response.data.text && isArray(response.data.text)) {
return response.data.text[0];
}
throw new Error("Invalid response for translate request");
} catch (e) {
throw new Error(`Could not translate to "${targetLang}": ${e}`);
if (targetLang === 'zh-cn') {
targetLang = 'zh';
}
try {
const url = `https://translate.yandex.net/api/v1.5/tr.json/translate?key=${apiKey}&text=${encodeURIComponent(text)}&lang=en-${targetLang}`;
const response = await axios({url, timeout: 15000});
if (response.data && response.data.text && isArray(response.data.text)) {
return response.data.text[0];
}
throw new Error('Invalid response for translate request');
} catch (e) {
throw new Error(`Could not translate to "${targetLang}": ${e}`);
}
}

/**
Expand All @@ -73,27 +73,27 @@ async function translateYandex(text, targetLang, apiKey) {
* @returns {Promise<string>}
*/
async function translateGoogle(text, targetLang) {
try {
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`;
const response = await axios({url, timeout: 15000});
if (isArray(response.data)) {
// we got a valid response
return response.data[0][0][0];
}
throw new Error("Invalid response for translate request");
} catch (e) {
if (e.response && e.response.status === 429) {
throw new Error(
`Could not translate to "${targetLang}": Rate-limited by Google Translate`
);
} else {
throw new Error(`Could not translate to "${targetLang}": ${e}`);
}
try {
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`;
const response = await axios({url, timeout: 15000});
if (isArray(response.data)) {
// we got a valid response
return response.data[0][0][0];
}
throw new Error('Invalid response for translate request');
} catch (e) {
if (e.response && e.response.status === 429) {
throw new Error(
`Could not translate to "${targetLang}": Rate-limited by Google Translate`
);
} else {
throw new Error(`Could not translate to "${targetLang}": ${e}`);
}
}
}

module.exports = {
isArray,
isObject,
translateText
isArray,
isObject,
translateText
};
Loading

0 comments on commit fc93b1c

Please sign in to comment.