Merge pull request #1735 from ciderapp/crowdin-api

janky ass implementation of crowdin api
This commit is contained in:
Core 2023-06-06 02:28:42 +01:00 committed by GitHub
commit 27a3a73124
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 279 additions and 259 deletions

3
.gitmodules vendored
View file

@ -1,3 +0,0 @@
[submodule "src/cider-i18n"]
path = src/cider-i18n
url = https://github.com/ciderapp/cider-i18n

View file

@ -1,3 +0,0 @@
files:
- source: /src/i18n/source/en_US.json
translation: /src/i18n/%locale_with_underscore%.json

View file

@ -30,6 +30,7 @@
},
"dependencies": {
"@achingbrain/ssdp": "^4.0.4",
"@crowdin/ota-client": "^1.0.0",
"@sentry/electron": "^4.6.0",
"@sentry/integrations": "^7.54.0",
"adm-zip": "^0.5.10",

@ -1 +0,0 @@
Subproject commit 1a427976edb6c19bf16620c15cba75f5052f7313

View file

@ -1048,22 +1048,19 @@ export class BrowserWindow {
});
ipcMain.on("get-i18n-listing", (event) => {
console.debug("[i18n] Getting i18n listing from " + utils.getPath("i18nPath"));
const i18nFiles = readdirSync(utils.getPath("i18nPath")).filter((file) => file.endsWith(".json")),
i18nListing = [];
const translations = utils.i18n
const i18nListing: any = [];
for (let i = 0; i < i18nFiles.length; i++) {
if (i18nFiles[i] == "index.json") continue;
console.debug("[i18n] Processing file: " + join(utils.getPath("i18nPath"), i18nFiles[i]));
const i18n: { [index: string]: Object } = JSON.parse(readFileSync(join(utils.getPath("i18nPath"), i18nFiles[i]), "utf8"));
for (const lang in translations) {
i18nListing.push({
code: i18nFiles[i].replace(".json", ""),
nameNative: i18n["i18n.languageName"] ?? i18nFiles[i].replace(".json", ""),
nameEnglish: i18n["i18n.languageNameEnglish"] ?? i18nFiles[i].replace(".json", ""),
category: i18n["i18n.category"] ?? "",
authors: i18n["i18n.authors"] ?? "",
code: lang,
nameNative: translations[lang][0].content["i18n.languageName"] ?? lang,
nameEnglish: translations[lang][0].content["i18n.languageNameEnglish"] ?? lang,
category: translations[lang][0].content["i18n.category"] ?? "",
authors: translations[lang][0].content["i18n.authors"] ?? "",
});
}
event.returnValue = i18nListing;
});

View file

@ -3,10 +3,14 @@ import * as path from "path";
import { Store } from "./store";
import { BrowserWindow as bw } from "./browserwindow";
import { app, BrowserWindow, ipcMain } from "electron";
import OtaClient from "@crowdin/ota-client";
import fetch from "electron-fetch";
import ElectronStore from "electron-store";
export class utils {
static crowdinClient: OtaClient = new OtaClient('fda9a6528649ea90dee35390wog')
static i18n: any = {};
/**
* Playback Functions
*/
@ -38,8 +42,6 @@ export class utils {
rendererPath: path.join(__dirname, "../../src/renderer"),
mainPath: path.join(__dirname, "../../src/main"),
resourcePath: path.join(__dirname, "../../resources"),
i18nPath: path.join(__dirname, "../../src/cider-i18n"),
i18nPathSrc: path.join(__dirname, "../../src/il8n/source"),
ciderCache: path.resolve(app.getPath("userData"), "CiderCache"),
themes: path.resolve(app.getPath("userData"), "Themes"),
plugins: path.resolve(app.getPath("userData"), "Plugins"),
@ -102,6 +104,11 @@ export class utils {
return await fetch(url, opts);
}
}
static async initializeTranslations() {
this.i18n = await this.crowdinClient.getTranslations()
}
/**
* Fetches the i18n locale for the given language.
* @param language {string} The language to fetch the locale for.
@ -109,23 +116,12 @@ export class utils {
* @returns {string | Object} The locale value.
*/
static getLocale(language: string, key?: string): string | object {
let i18n: { [index: string]: Object } = JSON.parse(fs.readFileSync(path.join(this.paths.i18nPath, "en_US.json"), "utf8"));
if (language !== "en_US" && fs.existsSync(path.join(this.paths.i18nPath, `${language}.json`))) {
i18n = Object.assign(i18n, JSON.parse(fs.readFileSync(path.join(this.paths.i18nPath, `${language}.json`), "utf8")));
}
/* else if (!fs.existsSync(path.join(this.paths.i18nPath, `${language}.json`))) {
fetch(`https://raw.githubusercontent.com/ciderapp/Cider/main/src/i18n/${language}.json`)
.then(res => res.json())
.then(res => {
if (res) {
i18n = Object.assign(i18n, res);
fs.writeFileSync(path.join(this.paths.i18nPath, `${language}.json`), JSON.stringify(res));
let i18n: any = {}
if (!this.i18n[language]) {
i18n = this.i18n["en"][0].content;
} else {
i18n = Object.assign(i18n, JSON.parse(fs.readFileSync(path.join(this.paths.i18nPath, `en_US.json`), "utf8")));
i18n = this.i18n[language ?? "en"][0].content;
}
})
} */
if (key) {
return i18n[key];

View file

@ -8,6 +8,7 @@ import { Plugins } from "./base/plugins";
import { BrowserWindow } from "./base/browserwindow";
import { init as Sentry } from "@sentry/electron";
import { RewriteFrames } from "@sentry/integrations";
import { utils } from "./base/utils";
if (!app.isPackaged) {
app.setPath("userData", join(app.getPath("appData"), "Cider"));
@ -30,8 +31,8 @@ const CiderPlug = new Plugins();
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* App Event Handlers
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
app.on("ready", () => {
app.on("ready", async () => {
await utils.initializeTranslations()
Cider.ready(CiderPlug);
console.log("[Cider] Application is Ready. Creating Window.");
@ -39,9 +40,10 @@ app.on("ready", () => {
console.info("[Cider] Running in development mode.");
require("vue-devtools").install();
}
console.log("aa")
components.whenReady().then(async () => {
const bw = new BrowserWindow();
console.log("[Cider] Creating Window.")
const win = await bw.createWindow();
app.getGPUInfo("complete").then((gpuInfo) => {
@ -110,3 +112,4 @@ app.on("widevine-error", (error) => {
console.log("[Cider][Widevine] Widevine installation encountered an error: " + error);
app.exit();
});

View file

@ -18,7 +18,24 @@ export default class Thumbar {
private isNotMac: boolean = process.platform !== "darwin";
private isMac: boolean = process.platform === "darwin";
private _menuTemplate: any = [
private _menuTemplate: any = []
/*******************************************************************************************
* Public Methods
* ****************************************************************************************/
/**
* Runs on plugin load (Currently run on application start)
*/
constructor(_utils: utils) {
console.debug(`[Plugin][${this.name}] Loading Complete.`);
}
/**
* Runs on app ready
*/
onReady(_win: Electron.BrowserWindow): void {
this._menuTemplate = [
{
label: app.getName(),
submenu: [
@ -285,21 +302,6 @@ export default class Thumbar {
},
];
/*******************************************************************************************
* Public Methods
* ****************************************************************************************/
/**
* Runs on plugin load (Currently run on application start)
*/
constructor(_utils: utils) {
console.debug(`[Plugin][${this.name}] Loading Complete.`);
}
/**
* Runs on app ready
*/
onReady(_win: Electron.BrowserWindow): void {
const menu = Menu.buildFromTemplate(this._menuTemplate);
Menu.setApplicationMenu(menu);
}

View file

@ -19,7 +19,7 @@ const app = new Vue({
pluginInstalled: false,
pluginMenuEntries: [],
pluginMenuTopEntries: [],
lz: ipcRenderer.sendSync("get-i18n", "en_US"),
lz: ipcRenderer.sendSync("get-i18n", "en"),
lzListing: ipcRenderer.sendSync("get-i18n-listing"),
radiohls: null,
search: {

View file

@ -1347,6 +1347,15 @@ __metadata:
languageName: node
linkType: hard
"@crowdin/ota-client@npm:^1.0.0":
version: 1.0.0
resolution: "@crowdin/ota-client@npm:1.0.0"
dependencies:
axios: ^1
checksum: b416632208cccf87235bd2ce7817c6b61c5069d626130f11e1034681ba9ff2ed6771f8b39e8a6afbde94f0274521cf1b2f5c02cc4dada31efe8881e5c9379952
languageName: node
linkType: hard
"@develar/schema-utils@npm:~2.6.5":
version: 2.6.5
resolution: "@develar/schema-utils@npm:2.6.5"
@ -3286,6 +3295,17 @@ __metadata:
languageName: node
linkType: hard
"axios@npm:^1":
version: 1.4.0
resolution: "axios@npm:1.4.0"
dependencies:
follow-redirects: ^1.15.0
form-data: ^4.0.0
proxy-from-env: ^1.1.0
checksum: 7fb6a4313bae7f45e89d62c70a800913c303df653f19eafec88e56cea2e3821066b8409bc68be1930ecca80e861c52aa787659df0ffec6ad4d451c7816b9386b
languageName: node
linkType: hard
"axlsign@git+https://github.com/ciderapp/curve25519-js.git":
version: 1.0.0
resolution: "axlsign@https://github.com/ciderapp/curve25519-js.git#commit=cae68782564b83ffa1c7c757e40a3944cb140290"
@ -3999,6 +4019,7 @@ __metadata:
resolution: "cider@workspace:."
dependencies:
"@achingbrain/ssdp": ^4.0.4
"@crowdin/ota-client": ^1.0.0
"@sentry/electron": ^4.6.0
"@sentry/integrations": ^7.54.0
"@types/adm-zip": ^0.5.0
@ -6062,7 +6083,7 @@ __metadata:
languageName: node
linkType: hard
"follow-redirects@npm:^1.0.0":
"follow-redirects@npm:^1.0.0, follow-redirects@npm:^1.15.0":
version: 1.15.2
resolution: "follow-redirects@npm:1.15.2"
peerDependenciesMeta:
@ -10080,6 +10101,13 @@ __metadata:
languageName: node
linkType: hard
"proxy-from-env@npm:^1.1.0":
version: 1.1.0
resolution: "proxy-from-env@npm:1.1.0"
checksum: ed7fcc2ba0a33404958e34d95d18638249a68c430e30fcb6c478497d72739ba64ce9810a24f53a7d921d0c065e5b78e3822759800698167256b04659366ca4d4
languageName: node
linkType: hard
"prr@npm:~1.0.1":
version: 1.0.1
resolution: "prr@npm:1.0.1"