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

Commit

Permalink
pr template & placeholders
Browse files Browse the repository at this point in the history
  • Loading branch information
Katsute committed Sep 2, 2024
1 parent 2559580 commit 20ba573
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 16 deletions.
4 changes: 4 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"image": "node:20",
"shutdownAction": "stopContainer"
}
12 changes: 12 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
### Requirements:
*Please follow the below requirements for the PR*

* Not generated using an online translator.
* Updates only a single language.
* Added account to [`contributors.json`](https://github.com/KatsuteDev/Background-Localization/blob/main/contributors.json).
* Strings contain correct amount of placeholders `{#}`.

### Changes:
*List the translations that were updated*

*
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,10 @@
<p>Localization strings for the <a href="https://github.com/KatsuteDev/Background">Background</a> VSCode extension</p>
<br>
<br>
</div>
</div>

For localization issues, open a [localization ticket](https://github.com/KatsuteDev/Background/issues/new?template=localization.yml).

Please follow the template when submitting a translation [pull request](https://github.com/KatsuteDev/Background/pulls).

Updates from online translators are not accepted, they lack context and are often incorrect, please only submit a PR if you are fluent in said language.
52 changes: 37 additions & 15 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,53 @@
const fs = require("fs");
const path = require("path");

const r1 = Object.keys(JSON.parse(fs.readFileSync(path.join(__dirname, "en", "readme.json"), "utf-8")));
const t1 = Object.keys(JSON.parse(fs.readFileSync(path.join(__dirname, "en", "translations.json"), "utf-8")));
const readme = JSON.parse(fs.readFileSync(path.join(__dirname, "en", "readme.json"), "utf-8"));
const translations = JSON.parse(fs.readFileSync(path.join(__dirname, "en", "translations.json"), "utf-8"));

let error = false;

const wildcard = (str) => ((str ?? "").match(/{[a-zA-Z0-9]+}/g) ?? []).length;

for(const folder of fs.readdirSync(__dirname).filter(f => !f.includes('.') && f !== "en")){
const r2 = Object.keys(JSON.parse(fs.readFileSync(path.join(__dirname, folder, "readme.json"), "utf-8")));
/* readme */ {
const obj = JSON.parse(fs.readFileSync(path.join(__dirname, folder, "readme.json"), "utf-8"));

for(const key of Object.keys(readme)){
if(!Object.keys(obj).includes(key)){
console.error(`[${folder}] Missing README translation for '${key}'`);
error = true;
continue;
}

const [wcO, wcT] = [wildcard(obj[key]), wildcard(readme[key])];

for(const key of r1){
if(!r2.includes(key)){
console.error(`[${folder}] Missing README translation for '${key}'`);
error = true;
if(wcO !== wcT){
console.error(`[${folder}] '${key}' has incorrect amount of placeholders (${wcO}${wcT})`);
error = true;
continue;
}
}
}

const t2 = Object.keys(JSON.parse(fs.readFileSync(path.join(__dirname, folder, "translations.json"), "utf-8")));
/* translations */ {
const obj = JSON.parse(fs.readFileSync(path.join(__dirname, folder, "translations.json"), "utf-8"));

for(const key of Object.keys(translations)){
if(!Object.keys(obj).includes(key)){
console.error(`[${folder}] Missing translation for '${key}'`);
error = true;
continue;
}

const [wcO, wcT] = [wildcard(obj[key]), wildcard(translations[key])];

for(const key of t1){
if(!t2.includes(key)){
console.error(`[${folder}] Missing package translation for '${key}'`);
error = true;
if(wcO !== wcT){
console.error(`[${folder}] '${key}' has incorrect amount of placeholders (${wcO}${wcT})`);
error = true;
continue;
}
}
}
}

if(error){
process.exit(1);
}
error && process.exit(1);

0 comments on commit 20ba573

Please sign in to comment.