Skip to content

Commit

Permalink
apply biome lint
Browse files Browse the repository at this point in the history
  • Loading branch information
sigmaSd committed Mar 24, 2024
1 parent d01b34f commit 67dec27
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
22 changes: 11 additions & 11 deletions scripts/compileTranslations.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
#!/usr/bin/env -S deno run --allow-read=./po,./src/locales --allow-write=./src/locales,./distro/,./po --allow-run=deno
#!/usr/bin/env -S deno run --allow-env --allow-read=./po,./src/locales --allow-write=./src/locales,./distro/,./po --allow-run=deno
import { gettextToI18next } from "npm:[email protected]";
import { APP_ID, EN_UI_LABELS } from "../src/consts.ts";
import i18n, { i18next } from "../src/i18n.ts";

async function genTranslations() {
for await (const lang of Deno.readDir("./po")) {
const langName = lang.name.slice(0, -3);
const poFilePath = "./po/" + lang.name;
const poFilePath = `./po/${lang.name}`;
const compiled = await gettextToI18next(
langName,
await Deno.readTextFile(poFilePath),
).then((data: string) => JSON.parse(data));
const verified = verifyAndFixPoFiles(poFilePath, compiled);

let targetDir = "./src/locales/" + langName;
let targetDir = `./src/locales/${langName}`;
// i18 expectes the translation folders to be aa-AA instead of aa_AA
targetDir = targetDir.replace("_", "-");
if (fewTranslations(verified)) {
await Deno.remove(targetDir, { recursive: true }).catch(() => {});
} else {
await Deno.mkdir(targetDir, { recursive: true });
await Deno.writeTextFile(
targetDir + "/translation.json",
`${targetDir}/translation.json`,
JSON.stringify(verified),
);
}
}
}

async function genDesktopFile() {
const names = [`Name=${EN_UI_LABELS["Stimulator"]}`];
const names = [`Name=${EN_UI_LABELS.Stimulator}`];
const comments = [`Comment=${EN_UI_LABELS["Keep your computer awake"]}`];
const keywords = [
`Keywords=${EN_UI_LABELS["caffeine;nosleep;awake;keepawake;keepon;"]}`,
Expand All @@ -44,7 +44,7 @@ async function genDesktopFile() {
// i18 expectes the translation code to be aa-AA instead of aa_AA
lang = lang.replace("_", "-");
await i18next.changeLanguage(lang);
const name = i18n(lang)(EN_UI_LABELS["Stimulator"]);
const name = i18n(lang)(EN_UI_LABELS.Stimulator);
const comment = i18n(lang)(EN_UI_LABELS["Keep your computer awake"]);
const keyword = i18n(lang)(
EN_UI_LABELS["caffeine;nosleep;awake;keepawake;keepon;"],
Expand Down Expand Up @@ -86,18 +86,18 @@ function verifyAndFixPoFiles(

const is_english = poFilePath.endsWith("en.po");
let changes = false;
Object.values(EN_UI_LABELS).forEach((prop) => {
for (const prop of Object.values(EN_UI_LABELS)) {
if (!(prop in updatedTranslateRecord)) {
updatedTranslateRecord[prop] = is_english ? prop : "";
changes = true;
}
});
Object.keys(updatedTranslateRecord).forEach((prop) => {
}
for (const prop of Object.keys(updatedTranslateRecord)) {
if (!(prop in EN_UI_LABELS)) {
delete updatedTranslateRecord[prop];
changes = true;
}
});
}

if (changes) {
Deno.writeTextFileSync(
Expand Down Expand Up @@ -135,5 +135,5 @@ function fewTranslations(locales: Record<string, string>) {
const translatedPercentage = ((total - empty) / total) * 100;

if (translatedPercentage >= CUT_OFF) return false;
else return true;
return true;
}
2 changes: 1 addition & 1 deletion scripts/translationsPercantage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ ${mdHeader}
langs.sort();

for (const langPath of langs) {
await Deno.readTextFile("./po/" + langPath).then((data) => {
await Deno.readTextFile(`./po/${langPath}`).then((data) => {
const msgIdNum = [...data.matchAll(/msgid/g)].length;
if (msgIdNum !== TOTAL_TRANSLATIONS + 1 /*first empty string*/) {
throw new Error(`po file: ${langPath} is missing some entries`);
Expand Down

0 comments on commit 67dec27

Please sign in to comment.