Skip to content

Commit 4c3d79c

Browse files
committed
style: format ci workflow and locale checker with prettier
1 parent a348022 commit 4c3d79c

2 files changed

Lines changed: 32 additions & 30 deletions

File tree

.github/workflows/ci.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@ name: CI
22

33
on:
44
push:
5-
branches: [ "main" ]
5+
branches: ["main"]
66
pull_request:
7-
branches: [ "main" ]
7+
branches: ["main"]
88

99
jobs:
1010
check-locales:
1111
name: Check Locale Parity
1212
runs-on: ubuntu-latest
1313

1414
steps:
15-
- uses: actions/checkout@v4
15+
- uses: actions/checkout@v4
1616

17-
- name: Set up Node.js
18-
uses: actions/setup-node@v4
19-
with:
20-
node-version: '20'
17+
- name: Set up Node.js
18+
uses: actions/setup-node@v4
19+
with:
20+
node-version: "20"
2121

22-
- name: Check Locales Parity
23-
run: node scripts/check-locales.js
22+
- name: Check Locales Parity
23+
run: node scripts/check-locales.js

scripts/check-locales.js

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
const fs = require('fs');
2-
const path = require('path');
1+
const fs = require("fs");
2+
const path = require("path");
33

4-
const MESSAGES_DIR = path.join(__dirname, '../messages');
5-
const EN_FILE = path.join(MESSAGES_DIR, 'en.json');
6-
const OTHER_LOCALES = ['es.json', 'tl.json'];
4+
const MESSAGES_DIR = path.join(__dirname, "../messages");
5+
const EN_FILE = path.join(MESSAGES_DIR, "en.json");
6+
const OTHER_LOCALES = ["es.json", "tl.json"];
77

88
function flattenObject(ob) {
99
let toReturn = {};
1010
for (let i in ob) {
1111
if (!ob.hasOwnProperty(i)) continue;
1212

13-
if (typeof ob[i] == 'object' && ob[i] !== null) {
13+
if (typeof ob[i] == "object" && ob[i] !== null) {
1414
let flatObject = flattenObject(ob[i]);
1515
for (let x in flatObject) {
1616
if (!flatObject.hasOwnProperty(x)) continue;
17-
toReturn[i + '.' + x] = flatObject[x];
17+
toReturn[i + "." + x] = flatObject[x];
1818
}
1919
} else {
2020
toReturn[i] = ob[i];
@@ -24,54 +24,56 @@ function flattenObject(ob) {
2424
}
2525

2626
function checkLocales() {
27-
console.log('Checking locale drift...');
28-
27+
console.log("Checking locale drift...");
28+
2929
if (!fs.existsSync(EN_FILE)) {
30-
console.error('Error: en.json not found');
30+
console.error("Error: en.json not found");
3131
process.exit(1);
3232
}
3333

34-
const enContent = JSON.parse(fs.readFileSync(EN_FILE, 'utf8'));
34+
const enContent = JSON.parse(fs.readFileSync(EN_FILE, "utf8"));
3535
const enKeys = Object.keys(flattenObject(enContent)).sort();
36-
36+
3737
let hasErrors = false;
3838

39-
OTHER_LOCALES.forEach(localeFile => {
39+
OTHER_LOCALES.forEach((localeFile) => {
4040
const localePath = path.join(MESSAGES_DIR, localeFile);
4141
if (!fs.existsSync(localePath)) {
4242
console.error(`Error: ${localeFile} not found`);
4343
hasErrors = true;
4444
return;
4545
}
4646

47-
const localeContent = JSON.parse(fs.readFileSync(localePath, 'utf8'));
47+
const localeContent = JSON.parse(fs.readFileSync(localePath, "utf8"));
4848
const localeKeys = Object.keys(flattenObject(localeContent)).sort();
4949

50-
const missingKeys = enKeys.filter(k => !localeKeys.includes(k));
51-
const extraKeys = localeKeys.filter(k => !enKeys.includes(k));
50+
const missingKeys = enKeys.filter((k) => !localeKeys.includes(k));
51+
const extraKeys = localeKeys.filter((k) => !enKeys.includes(k));
5252

5353
if (missingKeys.length > 0) {
5454
console.error(`\n❌ [${localeFile}] Missing keys compared to en.json:`);
55-
missingKeys.forEach(k => console.error(` - ${k}`));
55+
missingKeys.forEach((k) => console.error(` - ${k}`));
5656
hasErrors = true;
5757
}
5858

5959
if (extraKeys.length > 0) {
6060
console.error(`\n❌ [${localeFile}] Extra keys not found in en.json:`);
61-
extraKeys.forEach(k => console.error(` - ${k}`));
61+
extraKeys.forEach((k) => console.error(` - ${k}`));
6262
hasErrors = true;
6363
}
64-
64+
6565
if (missingKeys.length === 0 && extraKeys.length === 0) {
6666
console.log(`✅ ${localeFile} is in sync with en.json`);
6767
}
6868
});
6969

7070
if (hasErrors) {
71-
console.error('\n❌ Locale drift detected! Please ensure all locale files have the exact same keys as en.json.');
71+
console.error(
72+
"\n❌ Locale drift detected! Please ensure all locale files have the exact same keys as en.json.",
73+
);
7274
process.exit(1);
7375
} else {
74-
console.log('\n✨ All locales are perfectly in sync!');
76+
console.log("\n✨ All locales are perfectly in sync!");
7577
process.exit(0);
7678
}
7779
}

0 commit comments

Comments
 (0)