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>
<Forms.FormText>
<Translate i18nKey="vencord.components.pluginSettings.contributorModal.contributed" variables={{ count: plugins.length }}>
<Link href="https://vencord.dev/source" />
</Translate>
</Forms.FormText>
{!!plugins.length && (
<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 { 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<string, any>;
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;
localStorage.setItem("vcLocale", locale);
lastDiscordLocale = locale;
reloadLocale();
}
});
}
reloadLocale();
if (lastDiscordLocale) reloadLocale();
function reloadLocale() {
// 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>!"
}
}
}
}
}