Skip to content

Commit

Permalink
some sonarcube suggested fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
reZach committed May 4, 2021
1 parent 56430ea commit d134b38
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
22 changes: 11 additions & 11 deletions app/localization/translateMissing.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ async function updateTranslations() {

// For each language, read in any missing translations
// and translate
for (let i = 0; i < languageDirectories.length; i++) {
for (const languageDirectory of languageDirectories) {

// Check to make sure each language has the proper files
try {
const languageRoot = `${root}/${languageDirectories[i]}`;
const languageRoot = `${root}/${languageDirectory}`;
const translationFile = `${languageRoot}/translation.json`;
const missingTranslationFile = `${languageRoot}/translation.missing.json`;

Expand All @@ -80,7 +80,7 @@ async function updateTranslations() {
if (translationExists && translationMissingExists) {

// Read in contents of files
let translations = JSON.parse(fs.readFileSync(translationFile, {
const translations = JSON.parse(fs.readFileSync(translationFile, {
encoding: "utf8"
}));
const missing = JSON.parse(fs.readFileSync(missingTranslationFile, {
Expand All @@ -92,33 +92,33 @@ async function updateTranslations() {
if (missingKeys.length > 0){

// Translate each of the missing keys to the target language
for (let j = 0; j < missingKeys.length; j++){
const googleTranslation = await translate.translate(missingKeys[j], {
for (const missingKey of missingKeys){
const googleTranslation = await translate.translate(missingKey, {
from: fromLanguage,
to: languageDirectories[i]
to: languageDirectory
});

// Only set if a value is returned
if (googleTranslation.length > 0){
translations[missingKeys[j]] = googleTranslation[0];
translations[missingKey] = googleTranslation[0];
}
}

// Write output back to file
fs.writeFileSync(translationFile, JSON.stringify(translations, null, 2));
fs.writeFileSync(missingTranslationFile, JSON.stringify({}, null, 2));

console.log(`Successfully updated translations for ${languageDirectories[i]}`);
console.log(`Successfully updated translations for ${languageDirectory}`);
} else {
console.log(`Skipped creating translations for ${languageDirectories[i]}; none found!`);
console.log(`Skipped creating translations for ${languageDirectory}; none found!`);
}
} else {

// Log if we failed
if (!translationExists) {
console.error(`Could not generate translations for language '${languageDirectories[i]}' because ${translationFile} does not exist, skipping!`);
console.error(`Could not generate translations for language '${languageDirectory}' because ${translationFile} does not exist, skipping!`);
} else if (!translationMissingExists) {
console.error(`Could not generate translations for language '${languageDirectories[i]}' because ${missingTranslationFile} does not exist, skipping!`);
console.error(`Could not generate translations for language '${languageDirectory}' because ${missingTranslationFile} does not exist, skipping!`);
}
}
} catch (error) {
Expand Down
6 changes: 3 additions & 3 deletions app/localization/whitelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ const Whitelist = (function() {
buildSubmenu: function(channel, i18nextMainBackend) {
let submenu = [];

for (let i = 0; i < keys.length; i++) {
for (const key of keys) {
submenu.push({
label: whitelistMap[keys[i]],
click: clickFunction(channel, keys[i], i18nextMainBackend)
label: whitelistMap[key],
click: clickFunction(channel, key, i18nextMainBackend)
});
}

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "secure-electron-template",
"version": "10.1.0",
"version": "10.1.1",
"description": "The best way to build Electron apps with security in mind.",
"private": true,
"main": "app/electron/main.js",
Expand Down

0 comments on commit d134b38

Please sign in to comment.