feat: cached translations, use translation coremod, add terrible german

This commit is contained in:
Lewis Crichton 2024-06-08 19:23:56 +01:00
parent becf4a4c4f
commit d1242633e5
No known key found for this signature in database
4 changed files with 55 additions and 13 deletions

View file

@ -108,9 +108,11 @@ function ContributorModal({ user }: { user: User; }) {
</div> </div>
</div> </div>
<Forms.FormText>
<Translate i18nKey="vencord.components.pluginSettings.contributorModal.contributed" variables={{ count: plugins.length }}> <Translate i18nKey="vencord.components.pluginSettings.contributorModal.contributed" variables={{ count: plugins.length }}>
<Link href="https://vencord.dev/source" /> <Link href="https://vencord.dev/source" />
</Translate> </Translate>
</Forms.FormText>
{!!plugins.length && ( {!!plugins.length && (
<div className={cl("plugins")}> <div className={cl("plugins")}>

View file

@ -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());
}
});

View file

@ -5,28 +5,31 @@
*/ */
import { negotiateLanguages } from "@fluent/langneg"; import { negotiateLanguages } from "@fluent/langneg";
import { FluxDispatcher, i18n, React } from "@webpack/common"; import { React } from "@webpack/common";
import translations from "~translations"; import translations from "~translations";
import { localStorage } from "./localStorage";
import { Logger } from "./Logger"; import { Logger } from "./Logger";
const logger = new Logger("Translations", "#7bc876"); const logger = new Logger("Translations", "#7bc876");
let loadedLocale: Record<string, any>; let loadedLocale: Record<string, any>;
let lastDiscordLocale = i18n.getLocale(); let lastDiscordLocale: string = localStorage.getItem("vcLocale")!;
let bestLocale: string; let bestLocale: string;
FluxDispatcher.subscribe("USER_SETTINGS_PROTO_UPDATE", ({ settings }) => { export function setLocale(locale: string) {
if (settings.proto.localization.locale.value !== lastDiscordLocale) { if (locale === lastDiscordLocale) return;
lastDiscordLocale = settings.proto.localization.locale.value;
localStorage.setItem("vcLocale", locale);
lastDiscordLocale = locale;
reloadLocale(); reloadLocale();
} }
});
reloadLocale(); if (lastDiscordLocale) reloadLocale();
function reloadLocale() { function reloadLocale() {
// finds the best locale based on the available ones // finds the best locale based on the available ones

View file

@ -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</0>!",
"one": "Diese Person hat zu einem Plugin <0>beigetragen</0>!",
"other": "Diese Person hat zu {count} Plugins <0>beigetragen</0>!"
}
}
}
}
} }