feat: cached translations, use translation coremod, add terrible german
This commit is contained in:
parent
becf4a4c4f
commit
d1242633e5
|
@ -108,9 +108,11 @@ function ContributorModal({ user }: { user: User; }) {
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<Translate i18nKey="vencord.components.pluginSettings.contributorModal.contributed" variables={{ count: plugins.length }}>
|
||||
<Link href="https://vencord.dev/source" />
|
||||
</Translate>
|
||||
<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")}>
|
||||
|
|
27
src/plugins/_core/translation.ts
Normal file
27
src/plugins/_core/translation.ts
Normal 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());
|
||||
}
|
||||
});
|
|
@ -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;
|
||||
|
||||
reloadLocale();
|
||||
}
|
||||
});
|
||||
localStorage.setItem("vcLocale", locale);
|
||||
|
||||
reloadLocale();
|
||||
lastDiscordLocale = locale;
|
||||
|
||||
reloadLocale();
|
||||
}
|
||||
|
||||
if (lastDiscordLocale) reloadLocale();
|
||||
|
||||
function reloadLocale() {
|
||||
// finds the best locale based on the available ones
|
||||
|
|
|
@ -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>!"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue