feat: start translating

This commit is contained in:
Lewis Crichton 2024-06-03 18:31:56 +01:00
parent 9c9a02f9bf
commit 7ed73b49e5
No known key found for this signature in database
10 changed files with 128 additions and 58 deletions

View file

@ -24,5 +24,6 @@
"i18n-ally.localesPaths": ["./translations"], "i18n-ally.localesPaths": ["./translations"],
"i18n-ally.sourceLanguage": "en", "i18n-ally.sourceLanguage": "en",
"i18n-ally.extract.keygenStyle": "camelCase", "i18n-ally.extract.keygenStyle": "camelCase",
"i18n-ally.sortKeys": true "i18n-ally.sortKeys": true,
"i18n-ally.keystyle": "nested"
} }

View file

@ -38,6 +38,7 @@ import { patches, PMLogger, startAllPlugins } from "./plugins";
import { localStorage } from "./utils/localStorage"; import { localStorage } from "./utils/localStorage";
import { relaunch } from "./utils/native"; import { relaunch } from "./utils/native";
import { getCloudSettings, putCloudSettings } from "./utils/settingsSync"; import { getCloudSettings, putCloudSettings } from "./utils/settingsSync";
import { $t } from "./utils/translation";
import { checkForUpdates, update, UpdateLogger } from "./utils/updater"; import { checkForUpdates, update, UpdateLogger } from "./utils/updater";
import { onceReady } from "./webpack"; import { onceReady } from "./webpack";
import { SettingsRouter } from "./webpack/common"; import { SettingsRouter } from "./webpack/common";
@ -54,9 +55,8 @@ async function syncSettings() {
) { ) {
// show a notification letting them know and tell them how to fix it // show a notification letting them know and tell them how to fix it
showNotification({ showNotification({
title: "Cloud Integrations", title: $t("vencord.utils.cloud.integrations.title"),
body: "We've noticed you have cloud integrations enabled in another client! Due to limitations, you will " + body: $t("vencord.utils.cloud.integrations.reauthenticate"),
"need to re-authenticate to continue using them. Click here to go to the settings page to do so!",
color: "var(--yellow-360)", color: "var(--yellow-360)",
onClick: () => SettingsRouter.open("VencordCloud") onClick: () => SettingsRouter.open("VencordCloud")
}); });
@ -76,8 +76,8 @@ async function syncSettings() {
// there was an error to notify the user, but besides that we only want to show one notification instead of all // there was an error to notify the user, but besides that we only want to show one notification instead of all
// of the possible ones it has (such as when your settings are newer). // of the possible ones it has (such as when your settings are newer).
showNotification({ showNotification({
title: "Cloud Settings", title: $t("vencord.utils.cloud.settings.title"),
body: "Your settings have been updated! Click here to restart to fully apply changes!", body: $t("vencord.utils.cloud.settings.updated"),
color: "var(--green-360)", color: "var(--green-360)",
onClick: relaunch onClick: relaunch
}); });
@ -100,8 +100,8 @@ async function init() {
await update(); await update();
if (Settings.autoUpdateNotification) if (Settings.autoUpdateNotification)
setTimeout(() => showNotification({ setTimeout(() => showNotification({
title: "Vencord has been updated!", title: $t("vencord.update.updated"),
body: "Click here to restart", body: $t("vencord.update.clickToRestart"),
permanent: true, permanent: true,
noPersist: true, noPersist: true,
onClick: relaunch onClick: relaunch
@ -110,8 +110,8 @@ async function init() {
} }
setTimeout(() => showNotification({ setTimeout(() => showNotification({
title: "A Vencord update is available!", title: $t("vencord.update.available"),
body: "Click here to view the update", body: $t("vencord.update.clickToView"),
permanent: true, permanent: true,
noPersist: true, noPersist: true,
onClick: openUpdaterModal! onClick: openUpdaterModal!

View file

@ -19,6 +19,7 @@
import { Logger } from "@utils/Logger"; import { Logger } from "@utils/Logger";
import { Margins } from "@utils/margins"; import { Margins } from "@utils/margins";
import { LazyComponent } from "@utils/react"; import { LazyComponent } from "@utils/react";
import { $t } from "@utils/translation";
import { React } from "@webpack/common"; import { React } from "@webpack/common";
import { ErrorCard } from "./ErrorCard"; import { ErrorCard } from "./ErrorCard";
@ -85,11 +86,11 @@ const ErrorBoundary = LazyComponent(() => {
{...this.state} {...this.state}
/>; />;
const msg = this.props.message || "An error occurred while rendering this Component. More info can be found below and in your console."; const msg = this.props.message || $t("vencord.components.errorBoundary.error");
return ( return (
<ErrorCard style={{ overflow: "hidden" }}> <ErrorCard style={{ overflow: "hidden" }}>
<h1>Oh no!</h1> <h1>{$t("vencord.components.errorBoundary.ohNo")}</h1>
<p>{msg}</p> <p>{msg}</p>
<code> <code>
{this.state.message} {this.state.message}

View file

@ -21,6 +21,7 @@ import "./addonCard.css";
import { classNameFactory } from "@api/Styles"; import { classNameFactory } from "@api/Styles";
import { Badge } from "@components/Badge"; import { Badge } from "@components/Badge";
import { Switch } from "@components/Switch"; import { Switch } from "@components/Switch";
import { $t } from "@utils/translation";
import { Text, useRef } from "@webpack/common"; import { Text, useRef } from "@webpack/common";
import type { MouseEventHandler, ReactNode } from "react"; import type { MouseEventHandler, ReactNode } from "react";
@ -67,7 +68,7 @@ export function AddonCard({ disabled, isNew, name, infoButton, footer, author, e
> >
{name} {name}
</div> </div>
</div>{isNew && <Badge text="NEW" color="#ED4245" />} </div>{isNew && <Badge text={$t("vencord.components.vencordSettings.addonCard.new")} color="#ED4245" />}
</Text> </Text>
{!!author && ( {!!author && (
<Text variant="text-md/normal" className={cl("author")}> <Text variant="text-md/normal" className={cl("author")}>

View file

@ -16,12 +16,11 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
import { $t } from "@utils/translation";
import { maybePromptToUpdate } from "@utils/updater"; import { maybePromptToUpdate } from "@utils/updater";
export function handleComponentFailed() { export function handleComponentFailed() {
maybePromptToUpdate( maybePromptToUpdate(
"Uh Oh! Failed to render this Page." + $t("vencord.components.componentFailed")
" However, there is an update available that might fix it." +
" Would you like to update and restart now?"
); );
} }

View file

@ -23,6 +23,7 @@ import { OAuth2AuthorizeModal, UserStore } from "@webpack/common";
import { Logger } from "./Logger"; import { Logger } from "./Logger";
import { openModal } from "./modal"; import { openModal } from "./modal";
import { $t } from "./translation";
export const cloudLogger = new Logger("Cloud", "#39b7e0"); export const cloudLogger = new Logger("Cloud", "#39b7e0");
export const getCloudUrl = () => new URL(Settings.cloud.url); export const getCloudUrl = () => new URL(Settings.cloud.url);
@ -83,8 +84,8 @@ export async function authorizeCloud() {
var { clientId, redirectUri } = await oauthConfiguration.json(); var { clientId, redirectUri } = await oauthConfiguration.json();
} catch { } catch {
showNotification({ showNotification({
title: "Cloud Integration", title: $t("vencord.utils.cloud.integrations.title"),
body: "Setup failed (couldn't retrieve OAuth configuration)." body: $t("vencord.utils.cloud.integrations.setupFailure.oauth")
}); });
Settings.cloud.authenticated = false; Settings.cloud.authenticated = false;
return; return;
@ -113,22 +114,22 @@ export async function authorizeCloud() {
cloudLogger.info("Authorized with secret"); cloudLogger.info("Authorized with secret");
await setAuthorization(secret); await setAuthorization(secret);
showNotification({ showNotification({
title: "Cloud Integration", title: $t("vencord.utils.cloud.integrations.title"),
body: "Cloud integrations enabled!" body: $t("vencord.utils.cloud.integrations.enabled")
}); });
Settings.cloud.authenticated = true; Settings.cloud.authenticated = true;
} else { } else {
showNotification({ showNotification({
title: "Cloud Integration", title: $t("vencord.utils.cloud.integrations.title"),
body: "Setup failed (no secret returned?)." body: $t("vencord.utils.cloud.integrations.setupFailure.missingSecret")
}); });
Settings.cloud.authenticated = false; Settings.cloud.authenticated = false;
} }
} catch (e: any) { } catch (e: any) {
cloudLogger.error("Failed to authorize", e); cloudLogger.error("Failed to authorize", e);
showNotification({ showNotification({
title: "Cloud Integration", title: $t("vencord.utils.cloud.integrations.title"),
body: `Setup failed (${e.toString()}).` body: $t("vencord.utils.cloud.integrations.setupFailure.generic", { error: e.toString() })
}); });
Settings.cloud.authenticated = false; Settings.cloud.authenticated = false;
} }

View file

@ -19,6 +19,7 @@
import { Clipboard, Toasts } from "@webpack/common"; import { Clipboard, Toasts } from "@webpack/common";
import { DevsById } from "./constants"; import { DevsById } from "./constants";
import { $t } from "./translation";
/** /**
* Calls .join(" ") on the arguments * Calls .join(" ") on the arguments
@ -35,11 +36,13 @@ export function sleep(ms: number): Promise<void> {
return new Promise(r => setTimeout(r, ms)); return new Promise(r => setTimeout(r, ms));
} }
export function copyWithToast(text: string, toastMessage = "Copied to clipboard!") { export function copyWithToast(text: string, toastMessage?: string) {
toastMessage ??= $t("vencord.utils.misc.clipboard.copied");
if (Clipboard.SUPPORTS_COPY) { if (Clipboard.SUPPORTS_COPY) {
Clipboard.copy(text); Clipboard.copy(text);
} else { } else {
toastMessage = "Your browser does not support copying to clipboard"; toastMessage = $t("vencord.utils.misc.clipboard.noSupport");
} }
Toasts.show({ Toasts.show({
message: toastMessage, message: toastMessage,

View file

@ -24,6 +24,7 @@ import { deflateSync, inflateSync } from "fflate";
import { getCloudAuth, getCloudUrl } from "./cloud"; import { getCloudAuth, getCloudUrl } from "./cloud";
import { Logger } from "./Logger"; import { Logger } from "./Logger";
import { relaunch } from "./native"; import { relaunch } from "./native";
import { $t } from "./translation";
import { chooseFile, saveFile } from "./web"; import { chooseFile, saveFile } from "./web";
export async function importSettings(data: string) { export async function importSettings(data: string) {
@ -68,10 +69,10 @@ const toast = (type: number, message: string) =>
}); });
const toastSuccess = () => const toastSuccess = () =>
toast(Toasts.Type.SUCCESS, "Settings successfully imported. Restart to apply changes!"); toast(Toasts.Type.SUCCESS, $t("vencord.utils.settingsSync.imported"));
const toastFailure = (err: any) => const toastFailure = (err: any) =>
toast(Toasts.Type.FAILURE, `Failed to import settings: ${String(err)}`); toast(Toasts.Type.FAILURE, $t("vencord.utils.settingsSync.failedToImport", { error: String(err) }));
export async function uploadSettingsBackup(showToast = true): Promise<void> { export async function uploadSettingsBackup(showToast = true): Promise<void> {
if (IS_DISCORD_DESKTOP) { if (IS_DISCORD_DESKTOP) {
@ -128,8 +129,8 @@ export async function putCloudSettings(manual?: boolean) {
if (!res.ok) { if (!res.ok) {
cloudSettingsLogger.error(`Failed to sync up, API returned ${res.status}`); cloudSettingsLogger.error(`Failed to sync up, API returned ${res.status}`);
showNotification({ showNotification({
title: "Cloud Settings", title: $t("vencord.utils.cloud.settings.title"),
body: `Could not synchronize settings to cloud (API returned ${res.status}).`, body: $t("vencord.utils.cloud.settings.syncErrorUp.api", { status: res.status.toString() }),
color: "var(--red-360)" color: "var(--red-360)"
}); });
return; return;
@ -143,16 +144,16 @@ export async function putCloudSettings(manual?: boolean) {
if (manual) { if (manual) {
showNotification({ showNotification({
title: "Cloud Settings", title: $t("vencord.utils.cloud.settings.title"),
body: "Synchronized settings to the cloud!", body: $t("vencord.utils.cloud.settings.syncSuccess"),
noPersist: true, noPersist: true,
}); });
} }
} catch (e: any) { } catch (e: any) {
cloudSettingsLogger.error("Failed to sync up", e); cloudSettingsLogger.error("Failed to sync up", e);
showNotification({ showNotification({
title: "Cloud Settings", title: $t("vencord.utils.cloud.settings.title"),
body: `Could not synchronize settings to the cloud (${e.toString()}).`, body: $t("vencord.utils.cloud.settings.syncErrorUp.generic", { error: e.toString() }),
color: "var(--red-360)" color: "var(--red-360)"
}); });
} }
@ -173,8 +174,8 @@ export async function getCloudSettings(shouldNotify = true, force = false) {
cloudSettingsLogger.info("No settings on the cloud"); cloudSettingsLogger.info("No settings on the cloud");
if (shouldNotify) if (shouldNotify)
showNotification({ showNotification({
title: "Cloud Settings", title: $t("vencord.utils.cloud.settings.title"),
body: "There are no settings in the cloud.", body: $t("vencord.utils.cloud.settings.nothingOnline"),
noPersist: true noPersist: true
}); });
return false; return false;
@ -184,8 +185,8 @@ export async function getCloudSettings(shouldNotify = true, force = false) {
cloudSettingsLogger.info("Settings up to date"); cloudSettingsLogger.info("Settings up to date");
if (shouldNotify) if (shouldNotify)
showNotification({ showNotification({
title: "Cloud Settings", title: $t("vencord.utils.cloud.settings.title"),
body: "Your settings are up to date.", body: $t("vencord.utils.cloud.settings.upToDate"),
noPersist: true noPersist: true
}); });
return false; return false;
@ -194,8 +195,8 @@ export async function getCloudSettings(shouldNotify = true, force = false) {
if (!res.ok) { if (!res.ok) {
cloudSettingsLogger.error(`Failed to sync down, API returned ${res.status}`); cloudSettingsLogger.error(`Failed to sync down, API returned ${res.status}`);
showNotification({ showNotification({
title: "Cloud Settings", title: $t("vencord.utils.cloud.settings.title"),
body: `Could not synchronize settings from the cloud (API returned ${res.status}).`, body: $t("vencord.utils.cloud.settings.syncErrorDown.api", { status: res.status.toString() }),
color: "var(--red-360)" color: "var(--red-360)"
}); });
return false; return false;
@ -208,8 +209,8 @@ export async function getCloudSettings(shouldNotify = true, force = false) {
if (!force && written < localWritten) { if (!force && written < localWritten) {
if (shouldNotify) if (shouldNotify)
showNotification({ showNotification({
title: "Cloud Settings", title: $t("vencord.utils.cloud.settings.title"),
body: "Your local settings are newer than the cloud ones.", body: $t("vencord.utils.cloud.settings.localNewer"),
noPersist: true, noPersist: true,
}); });
return; return;
@ -227,8 +228,8 @@ export async function getCloudSettings(shouldNotify = true, force = false) {
cloudSettingsLogger.info("Settings loaded from cloud successfully"); cloudSettingsLogger.info("Settings loaded from cloud successfully");
if (shouldNotify) if (shouldNotify)
showNotification({ showNotification({
title: "Cloud Settings", title: $t("vencord.utils.cloud.settings.title"),
body: "Your settings have been updated! Click here to restart to fully apply changes!", body: $t("vencord.utils.cloud.settings.updated"),
color: "var(--green-360)", color: "var(--green-360)",
onClick: IS_WEB ? () => location.reload() : relaunch, onClick: IS_WEB ? () => location.reload() : relaunch,
noPersist: true noPersist: true
@ -238,8 +239,8 @@ export async function getCloudSettings(shouldNotify = true, force = false) {
} catch (e: any) { } catch (e: any) {
cloudSettingsLogger.error("Failed to sync down", e); cloudSettingsLogger.error("Failed to sync down", e);
showNotification({ showNotification({
title: "Cloud Settings", title: $t("vencord.utils.cloud.settings.title"),
body: `Could not synchronize settings from the cloud (${e.toString()}).`, body: $t("vencord.utils.cloud.settings.syncErrorDown.generic", { error: e.toString() }),
color: "var(--red-360)" color: "var(--red-360)"
}); });
@ -257,8 +258,8 @@ export async function deleteCloudSettings() {
if (!res.ok) { if (!res.ok) {
cloudSettingsLogger.error(`Failed to delete, API returned ${res.status}`); cloudSettingsLogger.error(`Failed to delete, API returned ${res.status}`);
showNotification({ showNotification({
title: "Cloud Settings", title: $t("vencord.utils.cloud.settings.title"),
body: `Could not delete settings (API returned ${res.status}).`, body: $t("vencord.utils.cloud.settings.deleteError.api", { error: res.status.toString() }),
color: "var(--red-360)" color: "var(--red-360)"
}); });
return; return;
@ -266,15 +267,15 @@ export async function deleteCloudSettings() {
cloudSettingsLogger.info("Settings deleted from cloud successfully"); cloudSettingsLogger.info("Settings deleted from cloud successfully");
showNotification({ showNotification({
title: "Cloud Settings", title: $t("vencord.utils.cloud.settings.title"),
body: "Settings deleted from cloud!", body: $t("vencord.utils.cloud.settings.deleted"),
color: "var(--green-360)" color: "var(--green-360)"
}); });
} catch (e: any) { } catch (e: any) {
cloudSettingsLogger.error("Failed to delete", e); cloudSettingsLogger.error("Failed to delete", e);
showNotification({ showNotification({
title: "Cloud Settings", title: $t("vencord.utils.cloud.settings.title"),
body: `Could not delete settings (${e.toString()}).`, body: $t("vencord.utils.cloud.settings.deleteError.generic", { error: e.toString() }),
color: "var(--red-360)" color: "var(--red-360)"
}); });
} }

View file

@ -20,6 +20,7 @@ import gitHash from "~git-hash";
import { Logger } from "./Logger"; import { Logger } from "./Logger";
import { relaunch } from "./native"; import { relaunch } from "./native";
import { $t } from "./translation";
import { IpcRes } from "./types"; import { IpcRes } from "./types";
export const UpdateLogger = /* #__PURE__*/ new Logger("Updater", "white"); export const UpdateLogger = /* #__PURE__*/ new Logger("Updater", "white");
@ -70,7 +71,7 @@ export async function maybePromptToUpdate(confirmMessage: string, checkForDev =
const isOutdated = await checkForUpdates(); const isOutdated = await checkForUpdates();
if (isOutdated) { if (isOutdated) {
const wantsUpdate = confirm(confirmMessage); const wantsUpdate = confirm(confirmMessage);
if (wantsUpdate && isNewer) return alert("Your local copy has more recent commits. Please stash or reset them."); if (wantsUpdate && isNewer) return alert($t("vencord.utils.updater.gitNewer"));
if (wantsUpdate) { if (wantsUpdate) {
await update(); await update();
relaunch(); relaunch();
@ -78,6 +79,6 @@ export async function maybePromptToUpdate(confirmMessage: string, checkForDev =
} }
} catch (err) { } catch (err) {
UpdateLogger.error(err); UpdateLogger.error(err);
alert("That also failed :( Try updating or re-installing with the installer!"); alert($t("vencord.utils.updater.failed"));
} }
} }

View file

@ -1,7 +1,69 @@
{ {
"hello": "Hello {name}!", "components": {
"plural": { "componentFailed": "Uh Oh! Failed to render this Page. However, there is an update available that might fix it. Would you like to update and restart now?",
"one": "One thing.", "errorBoundary": {
"other": "{count} things." "error": "An error occurred while rendering this Component. More info can be found below and in your console.",
"ohNo": "Oh no!"
},
"vencordSettings": {
"addonCard": {
"new": "NEW"
}
}
},
"update": {
"available": "A Vencord update is available!",
"clickToRestart": "Click here to restart",
"clickToView": "Click here to view the update",
"updated": "Vencord has been updated!"
},
"utils": {
"cloud": {
"integrations": {
"enabled": "Cloud integrations enabled!",
"reauthenticate": "We've noticed you have cloud integrations enabled in another client! Due to limitations, you will need to re-authenticate to continue using them. Click here to go to the settings page to do so!",
"setupFailure": {
"generic": "Setup failed ({error}).",
"missingSecret": "Setup failed (no secret returned?).",
"oauth": "Setup failed (couldn't retrieve OAuth configuration)."
},
"title": "Cloud Integrations"
},
"settings": {
"deleteError": {
"api": "Could not delete settings (API returned {status}).",
"generic": "Could not delete settings ({error})."
},
"deleted": "Settings deleted from cloud!",
"localNewer": "Your local settings are newer than the cloud ones.",
"nothingOnline": "There are no settings in the cloud.",
"syncErrorDown": {
"api": "Could not synchronize settings from the cloud (API returned {status}).",
"generic": "Could not synchronize settings from the cloud ({error})."
},
"syncErrorUp": {
"api": "Could not synchronize settings to the cloud (API returned {status}).",
"generic": "Could not synchronize settings to the cloud ({error})."
},
"syncSuccess": "Synchronized settings to the cloud!",
"title": "Cloud Settings",
"upToDate": "Your settings are up to date.",
"updated": "Your settings have been updated! Click here to restart to fully apply changes!"
}
},
"misc": {
"clipboard": {
"copied": "Copied to clipboard!",
"noSupport": "Your browser does not support copying to clipboard"
}
},
"settingsSync": {
"failedToImport": "Failed to import settings: {error}",
"imported": "Settings successfully imported. Restart to apply changes!"
},
"updater": {
"failed": "That also failed :( Try updating or re-installing with the installer!",
"gitNewer": "Your local copy has more recent commits. Please stash or reset them."
}
} }
} }