Skip to content

Commit

Permalink
feat: use LANG cache (speeds up generation on Windows)
Browse files Browse the repository at this point in the history
  • Loading branch information
jersou committed Feb 17, 2024
1 parent c236eba commit 8634ae0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 22 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### v0.3.2 / 2024.02.27

- feat: use LANG cache (speeds up generation on Windows)

### v0.3.1 / 2024.02.27

- feat: add openAI TTS
Expand Down
46 changes: 25 additions & 21 deletions utils/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,32 @@ export async function initI18n(lng: string) {
);
}

let LANG: string | undefined;
export async function getLang() {
let LANG;
if (Deno.build.os === "windows") {
LANG =
await $`powershell -NoProfile "Get-UICulture|select -ExpandProperty Name"`
.noThrow().text();
} else if (
(await Deno.permissions.query({ name: "env" })).state === "granted"
) {
LANG = Deno.env.get("LANG");
} else {
console.error(
yellow(
`Missing Deno env permission ! add "--allow-env" to permit lang detection`,
),
);
}
if (!LANG) {
if (Deno.build.os === "windows") {
LANG =
await $`powershell -NoProfile "Get-UICulture|select -ExpandProperty Name"`
.noThrow().text();
} else if (
(await Deno.permissions.query({ name: "env" })).state === "granted"
) {
LANG = Deno.env.get("LANG");
} else {
console.error(
yellow(
`Missing Deno env permission ! add "--allow-env" to permit lang detection`,
),
);
}

let lang;
const langRegex = /^([a-zA-Z_-]{2,})\.?/;
if (LANG && langRegex.test(LANG)) {
lang = langRegex.exec(LANG)![1].replace(/_/g, "-");
let lang;
const langRegex = /^([a-zA-Z_-]{2,})\.?/;
if (LANG && langRegex.test(LANG)) {
lang = langRegex.exec(LANG)![1].replace(/_/g, "-");
}
LANG = lang || "en-US";
}
return lang || "en-US";

return LANG;
}
2 changes: 1 addition & 1 deletion version.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env -S deno run -A

export const version = "v0.3.1";
export const version = "v0.3.2";

if (import.meta.main) {
console.log(version);
Expand Down

0 comments on commit 8634ae0

Please sign in to comment.