Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: add option for the ci to check locales #312

Merged
merged 1 commit into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ jobs:
- name: Validate Formatting
run: yarn run prettier:check

- name: Validate Locale
run: yarn run check:locale

- name: Lint Extension
run: yarn run lint

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"scripts": {
"build": "yarn run build:ts && yarn run gen:locale && yarn run build:extension",
"gen:locale": "yarn run ts-node scripts/generateLocale.ts",
"check:locale": "yarn run ts-node scripts/generateLocale.ts --dry-run",
"build:ts": "yarn run clean:ts && rollup -c --failAfterWarnings && sed -i '/setTimeout/d' dist/thirdparty/prismjs.js && sed -i 's/var\\ /let\\ /g' dist/extension.js dist/prefs.js",
"clean:ts": "rm -rf ./dist",
"build:extension": "yarn run build:schema",
Expand Down
58 changes: 49 additions & 9 deletions scripts/generateLocale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as gettextParser from 'gettext-parser';
import * as glob from 'glob';
import * as path from 'path';

const extractStrings = () => {
const extractStrings = (dryRun: boolean) => {
const extractor = new GettextExtractor();

extractor
Expand All @@ -28,16 +28,18 @@ const extractStrings = () => {

extractor.savePotFile(`${path.resolve(__dirname)}/../resources/po/[email protected]`);

extractor.printStats();
if (!dryRun) {
extractor.printStats();
}
};

const mergeStrings = () => {
fillPotPo.sync({
const mergeStrings = (dryRun: boolean) => {
return fillPotPo.sync({
potSources: [`${path.resolve(__dirname)}/../resources/po/*.pot`],
poSources: [`${path.resolve(__dirname)}/../resources/po/*.po`],
writeFiles: true,
writeFiles: !dryRun,
destDir: `${path.resolve(__dirname)}/../resources/po/`,
logResults: true,
logResults: !dryRun,
wrapLength: 1000,
});
};
Expand All @@ -53,6 +55,44 @@ const compileStrings = () => {
});
};

extractStrings();
mergeStrings();
compileStrings();
function main() {
let dryRun = false;

const lastArg = process.argv.at(-1);

if (lastArg && ['--dry-run', '--dryRun', '-d'].includes(lastArg)) {
dryRun = true;
}

extractStrings(dryRun);
const result = mergeStrings(dryRun);

if (dryRun) {
let errors = 0;
for (const vinyl of result) {
const file = `${path.resolve(__dirname)}/../resources/po/${vinyl.path}`;

if (!fs.existsSync(file)) {
console.error(`FATAL ERROR: File ${file} doesn't exist, but was reported as existing, this is a bug!`);
process.exit(1);
}

const actualContent = fs.readFileSync(file);
if (!actualContent.equals(vinyl.contents)) {
console.error(`File ${file} isn't valid, please update it!`);
errors++;
}
}
if (errors > 0) {
process.exit(1);
} else {
console.log('Checked every locales files: No updates necessary');
}
}

if (!dryRun) {
compileStrings();
}
}

main();