From d1242633e5ec1affa6bf6cda7da8a4bb19336f9e Mon Sep 17 00:00:00 2001 From: Lewis Crichton Date: Sat, 8 Jun 2024 19:23:56 +0100 Subject: [PATCH] feat: cached translations, use translation coremod, add terrible german --- .../PluginSettings/ContributorModal.tsx | 8 +++--- src/plugins/_core/translation.ts | 27 +++++++++++++++++++ src/utils/translation.tsx | 21 ++++++++------- translations/de/vencord.json | 12 ++++++++- 4 files changed, 55 insertions(+), 13 deletions(-) create mode 100644 src/plugins/_core/translation.ts diff --git a/src/components/PluginSettings/ContributorModal.tsx b/src/components/PluginSettings/ContributorModal.tsx index 022160c2e..2ab897d06 100644 --- a/src/components/PluginSettings/ContributorModal.tsx +++ b/src/components/PluginSettings/ContributorModal.tsx @@ -108,9 +108,11 @@ function ContributorModal({ user }: { user: User; }) { - - - + + + + + {!!plugins.length && (
diff --git a/src/plugins/_core/translation.ts b/src/plugins/_core/translation.ts new file mode 100644 index 000000000..aeb6cb547 --- /dev/null +++ b/src/plugins/_core/translation.ts @@ -0,0 +1,27 @@ +/* + * Vencord, a Discord client mod + * Copyright (c) 2024 Vendicated and contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +import { Devs } from "@utils/constants"; +import { setLocale } from "@utils/translation"; +import definePlugin from "@utils/types"; +import { i18n } from "@webpack/common"; + +export default definePlugin({ + name: "Translation", + required: true, + description: "Assists with translating Vencord", + authors: [Devs.lewisakura], + + flux: { + USER_SETTINGS_PROTO_UPDATE({ settings }) { + setLocale(settings.proto.localization.locale.value); + } + }, + + start() { + setLocale(i18n.getLocale()); + } +}); diff --git a/src/utils/translation.tsx b/src/utils/translation.tsx index 14ea8657f..6da989bea 100644 --- a/src/utils/translation.tsx +++ b/src/utils/translation.tsx @@ -5,28 +5,31 @@ */ import { negotiateLanguages } from "@fluent/langneg"; -import { FluxDispatcher, i18n, React } from "@webpack/common"; +import { React } from "@webpack/common"; import translations from "~translations"; +import { localStorage } from "./localStorage"; import { Logger } from "./Logger"; const logger = new Logger("Translations", "#7bc876"); let loadedLocale: Record; -let lastDiscordLocale = i18n.getLocale(); +let lastDiscordLocale: string = localStorage.getItem("vcLocale")!; let bestLocale: string; -FluxDispatcher.subscribe("USER_SETTINGS_PROTO_UPDATE", ({ settings }) => { - if (settings.proto.localization.locale.value !== lastDiscordLocale) { - lastDiscordLocale = settings.proto.localization.locale.value; +export function setLocale(locale: string) { + if (locale === lastDiscordLocale) return; - reloadLocale(); - } -}); + localStorage.setItem("vcLocale", locale); -reloadLocale(); + lastDiscordLocale = locale; + + reloadLocale(); +} + +if (lastDiscordLocale) reloadLocale(); function reloadLocale() { // finds the best locale based on the available ones diff --git a/translations/de/vencord.json b/translations/de/vencord.json index e0eb9c77a..da9941495 100644 --- a/translations/de/vencord.json +++ b/translations/de/vencord.json @@ -1,3 +1,13 @@ { - "hello": "Hallo {name}!" + "components": { + "pluginSettings": { + "contributorModal": { + "contributed": { + "zero": "Diese Person hat keine Plugins erstellt. Sie haben wahrscheinlich auf andere Weise <0>zu Vencord beigetragen!", + "one": "Diese Person hat zu einem Plugin <0>beigetragen!", + "other": "Diese Person hat zu {count} Plugins <0>beigetragen!" + } + } + } + } }