Skip to content

Commit

Permalink
Fix localization in packaged GoofCord
Browse files Browse the repository at this point in the history
  • Loading branch information
Milkshiift committed Sep 18, 2024
1 parent 07f66b0 commit ffe946b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,19 @@ jobs:
- name: Build GoofCord
run: pnpm run build

- name: Load Electron Cache
uses: actions/cache/restore@v4
with:
path: .cache
key: electron-zips.stable.${{matrix.os}}

- name: Package GoofCord
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: electron-builder ${{ matrix.arch }} --${{ matrix.name }} ${{ matrix.targets }} --publish=always

- name: Save Electron Cache
uses: actions/cache/save@v4
with:
path: .cache
key: electron-zips.stable.${{matrix.os}}
14 changes: 12 additions & 2 deletions src/modules/localization.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
import fs from "node:fs";
import path from "node:path";
import { ipcMain, ipcRenderer } from "electron";

const lang = "en-US";
const localization = JSON.parse(fs.readFileSync(path.join(__dirname, "..", "assets", "lang", lang + ".json"), "utf-8"));
const defaultLang = JSON.parse(fs.readFileSync(path.join(__dirname, "..", "assets", "lang", "en-US.json"), "utf-8"));
let localization: object;
let defaultLang: object;
if (process.type === "browser") {
localization = JSON.parse(fs.readFileSync(path.join(__dirname, "assets", "lang", lang + ".json"), "utf-8"));
defaultLang = JSON.parse(fs.readFileSync(path.join(__dirname, "assets", "lang", "en-US.json"), "utf-8"));
ipcMain.on("localization:getObjects", (event) => {
event.returnValue = [localization, defaultLang];
});
} else {
[localization, defaultLang] = ipcRenderer.sendSync("localization:getObjects");
}

// Gets localized string. Shortened because it's used very often
export function i(key: string) {
Expand Down

0 comments on commit ffe946b

Please sign in to comment.