Skip to content
This repository has been archived by the owner on Oct 13, 2021. It is now read-only.

Commit

Permalink
Review translations for errors/brand misuse #225
Browse files Browse the repository at this point in the history
Revert 4 keys in zh/tr to remove brand misuse. Added script to help determine issues with translation files beyond what is provided by default.
  • Loading branch information
autumnfound committed May 14, 2021
1 parent 64abfb6 commit be32f7c
Show file tree
Hide file tree
Showing 5 changed files with 12,211 additions and 14 deletions.
127 changes: 127 additions & 0 deletions bin/i18nChecker.js
@@ -0,0 +1,127 @@
var argv = require('yargs')
.usage('Usage: $0 [options]')
.example('$0', '')
.option('p', {
alias: 'path',
})
.help('h')
.alias('h', 'help')
.version('0.1')
.alias('v', 'version')
.epilog('Copyright 2019 Eclipse Foundation inc.').argv;
var toml = require('toml');
const fs = require('fs');
const baseConfig = {
root: '/run/secrets/',
encoding: 'utf-8',
baseLang: 'en',
};

class I18nChecker {
#config;
constructor(config) {
// check that our config exists or isn't unset. Deep cloning not needed
if (config !== undefined && config !== null) {
this.#config = Object.assign({}, baseConfig, config);
} else {
this.#config = Object.assign({}, baseConfig);
}
fs.accessSync(this.#config.root, fs.constants.R_OK);
}

checkFiles = function () {
let out = {};
try {
fs.readdirSync(this.#config.root).forEach(file => {
let name = file.substring(0, file.lastIndexOf('.'));
let d = this.readFile(file);
out[name] = toml.parse(d);
});
} catch (e) {
console.log(e);
}
let totalIss = 0;
for (let idx in out) {
let langData = out[idx];
console.log(`Language '${idx}' had ${Object.keys(langData).length} keys`);
// don't process the base lang
if (idx === this.#config.baseLang) {
console.log(
`Skipping processing of '${idx}' as it is the configured base lang.\n`
);
continue;
}
let issues = [];
let goodKeys = [];
for (let key in langData) {
let tObject = langData[key];
let baseTranslationObject = out[this.#config.baseLang][key];
if (baseTranslationObject === undefined) {
issues.push(
`ERR1: Key '${key}' does not exist in base '${
this.#config.baseLang
}' file (but exists in '${idx}')`
);
} else if (tObject === undefined) {
issues.push(`ERR2: Key '${key}' does not exist in base '${idx}' file`);
} else if (tObject.other === baseTranslationObject.other) {
issues.push(
`WARN: Key '${key}' has the same value in '${idx}' as base ${
this.#config.baseLang
}`
);
} else if (
baseTranslationObject.other.indexOf('Eclipse Foundation') !== -1 &&
tObject.other.indexOf('Eclipse Foundation') === -1
) {
issues.push(
`ERR3: Key '${key}' value contains 'Eclipse Foundation' in '${
this.#config.baseLang
}' but not in '${idx}'`
);
} else {
goodKeys.push(key);
}
}
console.log(`Good keys for ${idx}: ${goodKeys.length}`);
if (issues.length > 0) {
console.log(`Issues:`);
issues.forEach(iss => {
console.log(`\t- ${iss}`);
});
totalIss += issues.length;
}
console.log('\n');
}
console.log(`Issues discovered: ${totalIss}`);
};

readFile = function (name, encoding = this.#config.encoding) {
var filepath = `${this.#config.root}/${name}`;
try {
var data = fs.readFileSync(filepath, { encoding: encoding });
if (data !== undefined && (data = data.trim()) !== '') {
return data;
}
} catch (err) {
if (err.code === 'ENOENT') {
console.log(`File at path ${filepath} does not exist`);
} else if (err.code === 'EACCES') {
console.log(`File at path ${filepath} cannot be read`);
} else {
console.log('An unknown error occurred while reading the secret');
}
}
return null;
};
}

let check = new I18nChecker({ root: argv.p });
check.checkFiles();

/**
* Get modifiable deep copy of the base configuration for this class.
*/
function getBaseConfig() {
return JSON.parse(JSON.stringify(baseConfig));
}
4 changes: 2 additions & 2 deletions i18n/tr.toml
@@ -1,5 +1,5 @@
[eclipse-foundation-text]
other = "Eclipse Vakfı"
other = "Eclipse Foundation"

[navbar-manage-cookies-label]
other = "Çerezleri Yönet"
Expand Down Expand Up @@ -182,7 +182,7 @@ other = "IDE ve Araçlar"
other = "Yeni Gelen Forumu"

[footer-copyright-text]
other = "Copyright © Eclipse Vakfı. Tüm hakları saklıdır."
other = "Copyright © Eclipse Foundation. Tüm hakları saklıdır."

[search-section-label]
other = "Ara"
Expand Down
4 changes: 2 additions & 2 deletions i18n/zh.toml
Expand Up @@ -8,7 +8,7 @@
other = "相关链接"

[eclipse-foundation-text]
other = "Eclipse 基金会"
other = "Eclipse Foundation"

[jakarta-ee-website]
other = "Jakarta EE 官网网站"
Expand Down Expand Up @@ -221,7 +221,7 @@
other = "新人论坛"

[footer-copyright-text]
other = "版权所有 © Eclipse 基金会. 保留所有权利."
other = "Copyright © Eclipse Foundation. All Rights Reserved."

[search-section-label]
other = "搜索"
Expand Down

0 comments on commit be32f7c

Please sign in to comment.