i18n.messages -> getIntlMessage

This commit is contained in:
thororen1234 2024-11-03 14:54:36 -05:00
commit 66d921620b
51 changed files with 230 additions and 225 deletions

View file

@ -18,9 +18,8 @@
import "./iconStyles.css";
import { getTheme, Theme } from "@utils/discord";
import { getIntlMessage, getTheme, Theme } from "@utils/discord";
import { classes } from "@utils/misc";
import { i18n } from "@webpack/common";
import type { PropsWithChildren } from "react";
interface BaseIconProps extends IconProps {
@ -133,7 +132,7 @@ export function InfoIcon(props: IconProps) {
export function OwnerCrownIcon(props: IconProps) {
return (
<Icon
aria-label={i18n.Messages.GUILD_OWNER}
aria-label={getIntlMessage("GUILD_OWNER")}
{...props}
className={classes(props.className, "vc-owner-crown-icon")}
role="img"

View file

@ -31,9 +31,7 @@ export async function loadLazyChunks() {
const lazyChunks = factoryCode.matchAll(LazyChunkRegex);
const validChunkGroups = new Set<[chunkIds: number[], entryPoint: number]>();
// Workaround for a chunk that depends on the ChannelMessage component but may be be force loaded before
// the chunk containing the component
const shouldForceDefer = factoryCode.includes(".Messages.GUILD_FEED_UNFEATURE_BUTTON_TEXT");
const shouldForceDefer = false;
await Promise.all(Array.from(lazyChunks).map(async ([, rawChunkIds, entryPoint]) => {
const chunkIds = rawChunkIds ? Array.from(rawChunkIds.matchAll(Webpack.ChunkIdsRegex)).map(m => Number(m[1])) : [];

View file

@ -8,8 +8,9 @@ import "./style.css";
import { definePluginSettings } from "@api/Settings";
import { Devs } from "@utils/constants";
import { getIntlMessage } from "@utils/discord";
import definePlugin, { OptionType } from "@utils/types";
import { Button, Forms, i18n, TextInput } from "@webpack/common";
import { Button, Forms, TextInput } from "@webpack/common";
function ReasonsComponent() {
const { reasons } = settings.use(["reasons"]);
@ -87,9 +88,9 @@ export default definePlugin({
const reasons = settings.store.reasons.length
? settings.store.reasons
: [
i18n.Messages.BAN_REASON_OPTION_SPAM_ACCOUNT,
i18n.Messages.BAN_REASON_OPTION_HACKED_ACCOUNT,
i18n.Messages.BAN_REASON_OPTION_BREAKING_RULES
getIntlMessage("BAN_REASON_OPTION_SPAM_ACCOUNT"),
getIntlMessage("BAN_REASON_OPTION_HACKED_ACCOUNT"),
getIntlMessage("BAN_REASON_OPTION_BREAKING_RULES")
];
return reasons.map(s => ({ name: s, value: s }));
},

View file

@ -5,10 +5,11 @@
*/
import { classNameFactory } from "@api/Styles";
import { getIntlMessage } from "@utils/discord";
import { classes } from "@utils/misc";
import { closeModal, openModal } from "@utils/modal";
import { findByPropsLazy } from "@webpack";
import { Avatar, ChannelStore, ContextMenuApi, FluxDispatcher, GuildStore, i18n, Menu, ReadStateStore, ReadStateUtils, Text, Tooltip, useDrag, useDrop, useEffect, useRef, UserStore } from "@webpack/common";
import { Avatar, ChannelStore, ContextMenuApi, FluxDispatcher, GuildStore, Menu, ReadStateStore, ReadStateUtils, Text, Tooltip, useDrag, useDrop, useEffect, useRef, UserStore } from "@webpack/common";
import { BasicChannelTabsProps, Bookmark, BookmarkFolder, BookmarkProps, CircleQuestionIcon, isBookmarkFolder, settings, switchChannel, useBookmarks } from "../util";
import { NotificationDot } from "./ChannelTab";
@ -108,7 +109,7 @@ function BookmarkFolderOpenMenu(props: BookmarkProps) {
<Menu.MenuItem
key="mark-as-read"
id="mark-as-read"
label={i18n.Messages.MARK_AS_READ}
label={getIntlMessage("MARK_AS_READ")}
disabled={!ReadStateStore.hasUnread(b.channelId)}
action={() => ReadStateUtils.ackChannel(ChannelStore.getChannel(b.channelId))}
/>

View file

@ -5,10 +5,10 @@
*/
import { classNameFactory } from "@api/Styles";
import { getUniqueUsername } from "@utils/discord";
import { getIntlMessage, getUniqueUsername } from "@utils/discord";
import { classes } from "@utils/misc";
import { findByPropsLazy, findComponentByCodeLazy } from "@webpack";
import { Avatar, ChannelStore, ContextMenuApi, Dots, GuildStore, i18n, PresenceStore, ReadStateStore, Text, TypingStore, useDrag, useDrop, useRef, UserStore, useStateFromStores } from "@webpack/common";
import { Avatar, ChannelStore, ContextMenuApi, Dots, GuildStore, PresenceStore, ReadStateStore, Text, TypingStore, useDrag, useDrop, useRef, UserStore, useStateFromStores } from "@webpack/common";
import { Channel, Guild, User } from "discord-types/general";
import { ChannelTabsProps, CircleQuestionIcon, closeTab, isTabSelected, moveDraggedTabs, moveToTab, openedTabs, settings } from "../util";
@ -113,22 +113,22 @@ function ChannelTabContent(props: ChannelTabsProps & {
</>
);
else {
let name = `${i18n.Messages.UNKNOWN_CHANNEL} (${channelId})`;
let name = `${getIntlMessage("UNKNOWN_CHANNEL")} (${channelId})`;
switch (channelId) {
case "customize-community":
name = i18n.Messages.CHANNELS_AND_ROLES;
name = getIntlMessage("CHANNELS_AND_ROLES");
break;
case "channel-browser":
name = i18n.Messages.GUILD_SIDEBAR_CHANNEL_BROWSER;
name = getIntlMessage("GUILD_SIDEBAR_CHANNEL_BROWSER");
break;
case "shop":
name = i18n.Messages.GUILD_SHOP_CHANNEL_LABEL;
name = getIntlMessage("GUILD_SHOP_CHANNEL_LABEL");
break;
case "member-safety":
name = i18n.Messages.MEMBER_SAFETY_CHANNEL_TITLE;
name = getIntlMessage("MEMBER_SAFETY_CHANNEL_TITLE");
break;
case "@home":
name = i18n.Messages.SERVER_GUIDE;
name = getIntlMessage("SERVER_GUIDE");
break;
}
return (
@ -168,7 +168,7 @@ function ChannelTabContent(props: ChannelTabsProps & {
return (
<>
<ChannelIcon channel={channel} />
{!compact && <Text className={cl("name-text")}>{channel?.name || i18n.Messages.GROUP_DM}</Text>}
{!compact && <Text className={cl("name-text")}>{channel?.name || getIntlMessage("GROUP_DM")}</Text>}
<NotificationDot channelIds={[channel.id]} />
<TypingIndicator isTyping={isTyping} />
</>
@ -180,14 +180,14 @@ function ChannelTabContent(props: ChannelTabsProps & {
return (
<>
<FriendsIcon />
{!compact && <Text className={cl("name-text")}>{i18n.Messages.FRIENDS}</Text>}
{!compact && <Text className={cl("name-text")}>{getIntlMessage("FRIENDS")}</Text>}
</>
);
return (
<>
<CircleQuestionIcon />
{!compact && <Text className={cl("name-text")}>{i18n.Messages.UNKNOWN_CHANNEL}</Text>}
{!compact && <Text className={cl("name-text")}>{getIntlMessage("UNKNOWN_CHANNEL")}</Text>}
</>
);
}

View file

@ -4,9 +4,10 @@
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import { getIntlMessage } from "@utils/discord";
import { Margins } from "@utils/margins";
import { closeModal, ModalContent, ModalFooter, ModalHeader, ModalProps, ModalRoot, openModal } from "@utils/modal";
import { Button, ChannelStore, FluxDispatcher, Forms, i18n, Menu, ReadStateStore, ReadStateUtils, Select, Text, TextInput, useState } from "@webpack/common";
import { Button, ChannelStore, FluxDispatcher, Forms, Menu, ReadStateStore, ReadStateUtils, Select, Text, TextInput, useState } from "@webpack/common";
import { bookmarkFolderColors, bookmarkPlaceholderName, closeOtherTabs, closeTab, closeTabsToTheLeft, closeTabsToTheRight, createTab, hasClosedTabs, isBookmarkFolder, openedTabs, reopenClosedTab, settings, toggleCompactTab } from "../util";
import { Bookmark, BookmarkFolder, Bookmarks, ChannelTabsProps, UseBookmarkMethods } from "../util/types";
@ -177,7 +178,7 @@ export function BookmarkContextMenu({ bookmarks, index, methods }: { bookmarks:
{bookmarkNotificationDot && !isFolder &&
<Menu.MenuItem
id="mark-as-read"
label={i18n.Messages.MARK_AS_READ}
label={getIntlMessage("MARK_AS_READ")}
disabled={!ReadStateStore.hasUnread(bookmark.channelId)}
action={() => ReadStateUtils.ackChannel(ChannelStore.getChannel(bookmark.channelId))}
/>
@ -287,7 +288,7 @@ export function TabContextMenu({ tab }: { tab: ChannelTabsProps; }) {
{channel &&
<Menu.MenuItem
id="mark-as-read"
label={i18n.Messages.MARK_AS_READ}
label={getIntlMessage("MARK_AS_READ")}
disabled={!ReadStateStore.hasUnread(channel.id)}
action={() => ReadStateUtils.ackChannel(channel)}
/>

View file

@ -6,8 +6,9 @@
import { definePluginSettings } from "@api/Settings";
import { EquicordDevs } from "@utils/constants";
import { getIntlMessage } from "@utils/discord";
import definePlugin, { OptionType } from "@utils/types";
import { Button, Forms, i18n, Menu } from "@webpack/common";
import { Button, Forms, Menu } from "@webpack/common";
import { ReactElement } from "react";
import { preload, unload } from "./images";
@ -33,7 +34,7 @@ export default definePlugin({
return (
<Button size={Button.Sizes.SMALL} onClick={openQrModal}>
{i18n.Messages.USER_SETTINGS_SCAN_QR_CODE}
{getIntlMessage("USER_SETTINGS_SCAN_QR_CODE")}
</Button>
);
},
@ -94,21 +95,21 @@ export default definePlugin({
insertScanQrButton: (button: ReactElement) => (
<div className={cl("settings-btns")}>
<Button size={Button.Sizes.SMALL} onClick={openQrModal}>
{i18n.Messages.USER_SETTINGS_SCAN_QR_CODE}
{getIntlMessage("USER_SETTINGS_SCAN_QR_CODE")}
</Button>
{button}
</div>
),
get ScanQrMenuItem() {
return <Menu.MenuItem id="scan-qr" label={i18n.Messages.USER_SETTINGS_SCAN_QR_CODE} action={openQrModal} />;
return <Menu.MenuItem id="scan-qr" label={getIntlMessage("USER_SETTINGS_SCAN_QR_CODE")} action={openQrModal} />;
},
get ScanQrSettingsSheet() {
return {
section: i18n.Messages.USER_SETTINGS_SCAN_QR_CODE,
section: getIntlMessage("USER_SETTINGS_SCAN_QR_CODE"),
onClick: openQrModal,
searchableTitles: [i18n.Messages.USER_SETTINGS_SCAN_QR_CODE],
label: i18n.Messages.USER_SETTINGS_SCAN_QR_CODE,
ariaLabel: i18n.Messages.USER_SETTINGS_SCAN_QR_CODE
searchableTitles: [getIntlMessage("USER_SETTINGS_SCAN_QR_CODE")],
label: getIntlMessage("USER_SETTINGS_SCAN_QR_CODE"),
ariaLabel: getIntlMessage("USER_SETTINGS_SCAN_QR_CODE")
};
},

View file

@ -4,6 +4,7 @@
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import { getIntlMessage } from "@utils/discord";
import {
ModalContent,
ModalHeader,
@ -15,7 +16,6 @@ import {
import { findByPropsLazy } from "@webpack";
import {
Button,
i18n,
RestAPI,
Text,
useEffect,
@ -372,7 +372,7 @@ function QrModal(props: ModalProps) {
tag="h1"
style={{ flexGrow: 1 }}
>
{i18n.Messages.USER_SETTINGS_SCAN_QR_CODE}
{getIntlMessage("USER_SETTINGS_SCAN_QR_CODE")}
</Text>
</ModalHeader>
<ModalContent scrollbarType="none">

View file

@ -4,6 +4,7 @@
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import { getIntlMessage } from "@utils/discord";
import {
ModalContent,
ModalFooter,
@ -15,7 +16,6 @@ import {
import { findByPropsLazy } from "@webpack";
import {
Button,
i18n,
RestAPI,
Text,
useEffect,
@ -131,14 +131,14 @@ function VerifyModal({
tag="h1"
className={cl("device-header")}
>
{i18n.Messages.QR_CODE_LOGIN_SUCCESS}
{getIntlMessage("QR_CODE_LOGIN_SUCCESS")}
</Text>
<Text
variant="text-md/semibold"
color="text-normal"
style={{ width: "30rem" }}
>
{i18n.Messages.QR_CODE_LOGIN_SUCCESS_FLAVOR}
{getIntlMessage("QR_CODE_LOGIN_SUCCESS_FLAVOR")}
</Text>
</>
) : state === VerifyState.NotFound ? (
@ -155,14 +155,14 @@ function VerifyModal({
tag="h1"
className={cl("device-header")}
>
{i18n.Messages.QR_CODE_NOT_FOUND}
{getIntlMessage("QR_CODE_NOT_FOUND")}
</Text>
<Text
variant="text-md/semibold"
color="text-normal"
style={{ width: "30rem" }}
>
{i18n.Messages.QR_CODE_NOT_FOUND_DESCRIPTION}
{getIntlMessage("QR_CODE_NOT_FOUND_DESCRIPTION")}
</Text>
</>
) : (
@ -179,7 +179,7 @@ function VerifyModal({
tag="h1"
className={cl("device-header")}
>
{i18n.Messages.QR_CODE_LOGIN_CONFIRM}
{getIntlMessage("QR_CODE_LOGIN_CONFIRM")}
</Text>
<Text variant="text-md/semibold" color="text-danger">
Never scan a login QR code from another user or application.
@ -205,7 +205,7 @@ function VerifyModal({
<ModalFooter className={cl("device-footer")}>
{state === VerifyState.LoggedIn ? (
<Button onClick={props.onClose}>
{i18n.Messages.QR_CODE_LOGIN_FINISH_BUTTON}
{getIntlMessage("QR_CODE_LOGIN_FINISH_BUTTON")}
</Button>
) : (
<Button
@ -214,8 +214,8 @@ function VerifyModal({
onClick={props.onClose}
>
{state === VerifyState.NotFound
? i18n.Messages.CLOSE
: i18n.Messages.CANCEL}
? getIntlMessage("CLOSE")
: getIntlMessage("CANCEL")}
</Button>
)}
</ModalFooter>

View file

@ -5,9 +5,10 @@
*/
import { Devs } from "@utils/constants";
import { getIntlMessage } from "@utils/discord";
import definePlugin from "@utils/types";
import { findByCodeLazy, findByPropsLazy } from "@webpack";
import { ChannelStore, GuildStore, i18n, RelationshipStore, UserStore } from "@webpack/common";
import { ChannelStore, GuildStore, RelationshipStore, UserStore } from "@webpack/common";
const { getName } = findByPropsLazy("getName", "useName", "getNickname");
const computeChannelName = findByCodeLazy(".isThread())return'\"'.concat(");
@ -39,7 +40,7 @@ export default definePlugin({
if (message.type === MessageTypes.REPLY && message.referenced_message?.author) {
const replyUser = UserStore.getUser(message.referenced_message.author.id);
const replyUsername = getName(channel.guild_id, channel.id, replyUser);
title = i18n.Messages.CHANNEL_MESSAGE_REPLY_A11Y_LABEL.format({
title = getIntlMessage("CHANNEL_MESSAGE_REPLY_A11Y_LABEL", {
author: username,
repliedAuthor: replyUsername,
});

View file

@ -8,10 +8,11 @@ import { NavContextMenuPatchCallback } from "@api/ContextMenu";
import { CodeBlock } from "@components/CodeBlock";
import ErrorBoundary from "@components/ErrorBoundary";
import { Devs } from "@utils/constants";
import { getIntlMessage } from "@utils/discord";
import { Margins } from "@utils/margins";
import { closeModal, ModalCloseButton, ModalContent, ModalHeader, ModalRoot, ModalSize, openModal } from "@utils/modal";
import definePlugin from "@utils/types";
import { Forms, i18n, Menu, Text } from "@webpack/common";
import { Forms, Menu, Text } from "@webpack/common";
import { Message } from "discord-types/general";
type CustomMessage = Message & { editHistory?: any; deleted?: any; firstEditTimestamp?: any; };
@ -64,7 +65,7 @@ function openViewRawModal(obj: any, type: string, isMessage?: boolean) {
function makeContextCallback(name: string, action: (any) => void): NavContextMenuPatchCallback {
return (children, props) => {
if (props.label === i18n.Messages.CHANNEL_ACTIONS_MENU_LABEL) return; // random shit like notification settings
if (props.label === getIntlMessage("CHANNEL_ACTIONS_MENU_LABEL")) return; // random shit like notification settings
const value = props[name];
if (!value) return;

View file

@ -9,12 +9,12 @@ import { classNameFactory } from "@api/Styles";
import ErrorBoundary from "@components/ErrorBoundary";
import { Flex } from "@components/Flex";
import { EquicordDevs } from "@utils/constants";
import { openUserProfile } from "@utils/discord";
import { getIntlMessage, openUserProfile } from "@utils/discord";
import { Margins } from "@utils/margins";
import { classes } from "@utils/misc";
import definePlugin, { OptionType } from "@utils/types";
import { findByPropsLazy, findComponentByCodeLazy, findStoreLazy } from "@webpack";
import { Clickable, Forms, i18n, RelationshipStore, Tooltip, UserStore, useStateFromStores } from "@webpack/common";
import { Clickable, Forms, RelationshipStore, Tooltip, UserStore, useStateFromStores } from "@webpack/common";
import { User } from "discord-types/general";
interface WatchingProps {
@ -46,7 +46,7 @@ function Watching({ userIds, guildId }: WatchingProps): JSX.Element {
<div className={cl("content")}>
{userIds.length ?
(<>
<Forms.FormTitle>{i18n.Messages.SPECTATORS.format({ numViewers: userIds.length })}</Forms.FormTitle>
<Forms.FormTitle>{getIntlMessage("SPECTATORS", { numViewers: userIds.length })}</Forms.FormTitle>
<Flex flexDirection="column" style={{ gap: 6 }} >
{users.map(user => (
<Flex flexDirection="row" style={{ gap: 6, alignContent: "center" }} className={cl("user")} >
@ -54,7 +54,7 @@ function Watching({ userIds, guildId }: WatchingProps): JSX.Element {
{getUsername(user)}
</Flex>
))}
{missingUsers > 0 && <span className={cl("more_users")}>{`+${i18n.Messages.NUM_USERS.format({ num: missingUsers })}`}</span>}
{missingUsers > 0 && <span className={cl("more_users")}>{`+${getIntlMessage("NUM_USERS", { num: missingUsers })}`}</span>}
</Flex>
</>)
: (<span className={cl("no_viewers")}>No spectators</span>)}
@ -121,7 +121,7 @@ export default definePlugin({
{users.length ?
<>
<Forms.FormTitle tag="h3" style={{ marginTop: 8, marginBottom: 0, textTransform: "uppercase" }}>
{i18n.Messages.SPECTATORS.format({ numViewers: userIds.length })}
{getIntlMessage("SPECTATORS", { numViewers: userIds.length })}
</Forms.FormTitle>
<UserSummaryItem
users={users}

View file

@ -24,8 +24,9 @@ import PluginsTab from "@components/VencordSettings/PluginsTab";
import UpdaterTab from "@components/VencordSettings/UpdaterTab";
import VencordTab from "@components/VencordSettings/VencordTab";
import { Devs } from "@utils/constants";
import { getIntlMessage } from "@utils/discord";
import definePlugin, { OptionType } from "@utils/types";
import { i18n, React } from "@webpack/common";
import { React } from "@webpack/common";
import gitHash from "~git-hash";
@ -162,11 +163,12 @@ export default definePlugin({
try {
const names = {
top: i18n.Messages.USER_SETTINGS,
aboveNitro: i18n.Messages.BILLING_SETTINGS,
belowNitro: i18n.Messages.APP_SETTINGS,
aboveActivity: i18n.Messages.ACTIVITY_SETTINGS
top: getIntlMessage("USER_SETTINGS"),
aboveNitro: getIntlMessage("BILLING_SETTINGS"),
belowNitro: getIntlMessage("APP_SETTINGS"),
aboveActivity: getIntlMessage("ACTIVITY_SETTINGS")
};
return header === names[settingsLocation];
} catch {
return firstChild === "PREMIUM";

View file

@ -149,7 +149,7 @@ export default definePlugin({
patches: [{
find: "#{intl::BEGINNING_DM}",
replacement: {
match: /#{intl::BEGINNING_DM}"\],{.+?}\),(?=.{0,300}(\i)\.isMultiUserDM)/,
match: /#{intl::BEGINNING_DM},{.+?}\),(?=.{0,300}(\i)\.isMultiUserDM)/,
replace: "$& $self.renderContributorDmWarningCard({ channel: $1 }),"
}
}],

View file

@ -18,9 +18,10 @@
import { definePluginSettings } from "@api/Settings";
import { Devs } from "@utils/constants";
import { getIntlMessage } from "@utils/discord";
import definePlugin, { OptionType } from "@utils/types";
import { findByPropsLazy, findLazy, findStoreLazy } from "@webpack";
import { FluxDispatcher, i18n, useMemo } from "@webpack/common";
import { FluxDispatcher, useMemo } from "@webpack/common";
import FolderSideBar from "./FolderSideBar";
@ -274,12 +275,16 @@ export default definePlugin({
},
makeGuildsBarGuildListFilter(isBetterFolders: boolean) {
return child => {
if (isBetterFolders) {
return child?.props?.["aria-label"] === i18n.Messages.SERVERS;
}
try {
return child => {
if (isBetterFolders) {
return child?.props?.["aria-label"] === getIntlMessage("SERVERS");
}
return true;
};
} catch {
return true;
};
}
},
makeGuildsBarTreeFilter(isBetterFolders: boolean) {

View file

@ -47,7 +47,7 @@ export default definePlugin({
},
{
find: ".ADD_ROLE_A11Y_LABEL",
find: "#{intl::ADD_ROLE_A11Y_LABEL}",
all: true,
predicate: () => Settings.plugins.BetterRoleDot.copyRoleColorInProfilePopout && !Settings.plugins.BetterRoleDot.bothStyles,
noWarn: true,

View file

@ -5,8 +5,9 @@
*/
import { openPluginModal } from "@components/PluginSettings/PluginModal";
import { getIntlMessage } from "@utils/discord";
import { isObjectEmpty } from "@utils/misc";
import { Alerts, i18n, Menu, useMemo, useState } from "@webpack/common";
import { Alerts, Menu, useMemo, useState } from "@webpack/common";
import Plugins from "~plugins";
@ -48,7 +49,7 @@ export default function PluginsSubmenu() {
query={query}
onChange={setQuery}
ref={ref}
placeholder={i18n.Messages.SEARCH}
placeholder={getIntlMessage("SEARCH")}
/>
)}
/>

View file

@ -7,10 +7,11 @@
import { definePluginSettings } from "@api/Settings";
import { classNameFactory } from "@api/Styles";
import { Devs } from "@utils/constants";
import { getIntlMessage } from "@utils/discord";
import { Logger } from "@utils/Logger";
import definePlugin, { OptionType } from "@utils/types";
import { waitFor } from "@webpack";
import { ComponentDispatch, FocusLock, i18n, Menu, useEffect, useRef } from "@webpack/common";
import { ComponentDispatch, FocusLock, Menu, useEffect, useRef } from "@webpack/common";
import type { HTMLAttributes, ReactElement } from "react";
import PluginsSubmenu from "./PluginsSubmenu";
@ -162,7 +163,7 @@ export default definePlugin({
if (item.section === "HEADER") {
items.push({ label: item.label, items: [] });
} else if (item.section === "DIVIDER") {
items.push({ label: i18n.Messages.OTHER_OPTIONS, items: [] });
items.push({ label: getIntlMessage("OTHER_OPTIONS"), items: [] });
} else {
items.at(-1)!.items.push(item);
}

View file

@ -14,7 +14,7 @@ import definePlugin, { OptionType, StartAt } from "@utils/types";
import { findByCodeLazy, findComponentByCodeLazy, findStoreLazy } from "@webpack";
import { Button, Forms, ThemeStore, useStateFromStores } from "@webpack/common";
const ColorPicker = findComponentByCodeLazy(".Messages.USER_SETTINGS_PROFILE_COLOR_SELECT_COLOR", ".BACKGROUND_PRIMARY)");
const ColorPicker = findComponentByCodeLazy("#{intl::USER_SETTINGS_PROFILE_COLOR_SELECT_COLOR}", ".BACKGROUND_PRIMARY)");
const colorPresets = [
"#1E1514", "#172019", "#13171B", "#1C1C28", "#402D2D",

View file

@ -18,6 +18,7 @@
import { Devs } from "@utils/constants";
import { getCurrentChannel, getCurrentGuild } from "@utils/discord";
import { runtimeHashMessageKey } from "@utils/intlHash";
import { SYM_LAZY_CACHED, SYM_LAZY_GET } from "@utils/lazy";
import { relaunch } from "@utils/native";
import { canonicalizeMatch, canonicalizeReplace, canonicalizeReplacement } from "@utils/patches";
@ -104,6 +105,7 @@ function makeShortcuts() {
canonicalizeMatch,
canonicalizeReplace,
canonicalizeReplacement,
runtimeHashMessageKey,
fakeRender: (component: ComponentType, props: any) => {
const prevWin = fakeRenderWin?.deref();
const win = prevWin?.closed === false

View file

@ -41,7 +41,7 @@ export default definePlugin({
{
find: "DefaultCustomizationSections",
replacement: {
match: /(?<=#{intl::USER_SETTINGS_AVATAR_DECORATION}"\]\)},"decoration"\),)/,
match: /(?<=#{intl::USER_SETTINGS_AVATAR_DECORATION}\)},"decoration"\),)/,
replace: "$self.DecorSection(),"
}
},

View file

@ -5,7 +5,8 @@
*/
import { PlusIcon } from "@components/Icons";
import { i18n, Text } from "@webpack/common";
import { getIntlMessage } from "@utils/discord";
import { Text } from "@webpack/common";
import { HTMLProps } from "react";
import { DecorationGridItem } from ".";
@ -24,7 +25,7 @@ export default function DecorationGridCreate(props: DecorationGridCreateProps) {
variant="text-xs/normal"
color="header-primary"
>
{i18n.Messages.CREATE}
{getIntlMessage("CREATE")}
</Text>
</DecorationGridItem >;
}

View file

@ -5,7 +5,8 @@
*/
import { NoEntrySignIcon } from "@components/Icons";
import { i18n, Text } from "@webpack/common";
import { getIntlMessage } from "@utils/discord";
import { Text } from "@webpack/common";
import { HTMLProps } from "react";
import { DecorationGridItem } from ".";
@ -24,7 +25,7 @@ export default function DecorationGridNone(props: DecorationGridNoneProps) {
variant="text-xs/normal"
color="header-primary"
>
{i18n.Messages.NONE}
{getIntlMessage("NONE")}
</Text>
</DecorationGridItem >;
}

View file

@ -108,10 +108,10 @@ interface ProfileModalProps {
isTryItOutFlow: boolean;
}
const ColorPicker = findComponentByCodeLazy<ColorPickerProps>(".Messages.USER_SETTINGS_PROFILE_COLOR_SELECT_COLOR", ".BACKGROUND_PRIMARY)");
const ColorPicker = findComponentByCodeLazy<ColorPickerProps>("#{intl::USER_SETTINGS_PROFILE_COLOR_SELECT_COLOR}", ".BACKGROUND_PRIMARY)");
const ProfileModal = findComponentByCodeLazy<ProfileModalProps>("isTryItOutFlow:", "pendingThemeColors:", "pendingAvatarDecoration:", "EDIT_PROFILE_BANNER");
const requireColorPicker = extractAndLoadChunksLazy(["USER_SETTINGS_PROFILE_COLOR_DEFAULT_BUTTON.format"], /createPromise:\(\)=>\i\.\i(\("?.+?"?\)).then\(\i\.bind\(\i,"?(.+?)"?\)\)/);
const requireColorPicker = extractAndLoadChunksLazy(["#{intl::USER_SETTINGS_PROFILE_COLOR_DEFAULT_BUTTON}"], /createPromise:\(\)=>\i\.\i(\("?.+?"?\)).then\(\i\.bind\(\i,"?(.+?)"?\)\)/);
export default definePlugin({
name: "FakeProfileThemes",
@ -128,7 +128,7 @@ export default definePlugin({
{
find: "#{intl::USER_SETTINGS_RESET_PROFILE_THEME}",
replacement: {
match: /#{intl::USER_SETTINGS_RESET_PROFILE_THEME}"\]\)}\)(?<=color:(\i),.{0,500}?color:(\i),.{0,500}?)/,
match: /#{intl::USER_SETTINGS_RESET_PROFILE_THEME}\)}\)(?<=color:(\i),.{0,500}?color:(\i),.{0,500}?)/,
replace: "$&,$self.addCopy3y3Button({primary:$1,accent:$2})"
}
}

View file

@ -19,10 +19,11 @@
import { findGroupChildrenByChildId, NavContextMenuPatchCallback } from "@api/ContextMenu";
import { migratePluginSettings } from "@api/Settings";
import { Devs } from "@utils/constants";
import { getIntlMessage } from "@utils/discord";
import { NoopComponent } from "@utils/react";
import definePlugin from "@utils/types";
import { filters, findByPropsLazy, waitFor } from "@webpack";
import { ChannelStore, ContextMenuApi, i18n, UserStore } from "@webpack/common";
import { ChannelStore, ContextMenuApi, UserStore } from "@webpack/common";
import { Message } from "discord-types/general";
const { useMessageMenu } = findByPropsLazy("useMessageMenu");
@ -41,7 +42,7 @@ function MessageMenu({ message, channel, onHeightUpdate }) {
return useMessageMenu({
navId: "message-actions",
ariaLabel: i18n.Messages.MESSAGE_UTILITIES_A11Y_LABEL,
ariaLabel: getIntlMessage("MESSAGE_UTILITIES_A11Y_LABEL"),
message,
channel,
@ -72,7 +73,7 @@ const contextMenuPatch: NavContextMenuPatchCallback = (children, props: MessageA
const group = findGroupChildrenByChildId("devmode-copy-id", children, true);
group?.push(
CopyIdMenuItem({ id: props.message.author.id, label: i18n.Messages.COPY_ID_AUTHOR })
CopyIdMenuItem({ id: props.message.author.id, label: getIntlMessage("COPY_ID_AUTHOR") })
);
};

View file

@ -50,7 +50,7 @@ export default definePlugin({
{
find: "#{intl::FRIENDS_SECTION_ONLINE}",
replacement: {
match: /(\(0,\i\.jsx\)\(\i\.TabBar\.Item,\{id:\i\.\i)\.BLOCKED,className:([^\s]+?)\.item,children:\i\.\i\.Messages\.BLOCKED\}\)/,
match: /(\(0,\i\.jsx\)\(\i\.TabBar\.Item,\{id:\i\.\i)\.BLOCKED,className:([^\s]+?)\.item,children:\i\.\i\.string\(\i\.\i#{intl::BLOCKED}\)\}\)/,
replace: "$1.IMPLICIT,className:$2.item,children:\"Implicit\"}),$&"
},
},

View file

@ -15,23 +15,13 @@ import { Settings } from "@api/Settings";
import { disableStyle, enableStyle } from "@api/Styles";
import ErrorBoundary from "@components/ErrorBoundary";
import { Devs } from "@utils/constants";
import { getIntlMessage } from "@utils/discord";
import { proxyLazy } from "@utils/lazy";
import { Logger } from "@utils/Logger";
import { classes } from "@utils/misc";
import definePlugin, { OptionType } from "@utils/types";
import { findByCodeLazy, findByPropsLazy } from "@webpack";
import {
ChannelStore,
FluxDispatcher,
i18n,
Menu,
MessageStore,
Parser,
SelectedChannelStore,
Timestamp,
UserStore,
useStateFromStores,
} from "@webpack/common";
import { ChannelStore, FluxDispatcher, Menu, MessageStore, Parser, SelectedChannelStore, Timestamp, UserStore, useStateFromStores } from "@webpack/common";
import { Message } from "discord-types/general";
import overlayStyle from "./deleteStyleOverlay.css?managed";
@ -188,30 +178,23 @@ export default definePlugin({
(oldMsg, newMsg) => oldMsg?.editHistory === newMsg?.editHistory,
);
return (
Settings.plugins.MessageLogger.inlineEdits && (
<>
{message.editHistory?.map(edit => (
<div className="messagelogger-edited">
{parseEditContent(edit.content, message)}
<Timestamp
timestamp={edit.timestamp}
isEdited={true}
isInline={false}
>
<span className={styles.edited}>
{" "}
({i18n.Messages.MESSAGE_EDITED})
</span>
</Timestamp>
</div>
))}
</>
)
return Settings.plugins.MessageLogger.inlineEdits && (
<>
{message.editHistory?.map(edit => (
<div className="messagelogger-edited">
{parseEditContent(edit.content, message)}
<Timestamp
timestamp={edit.timestamp}
isEdited={true}
isInline={false}
>
<span className={styles.edited}>{" "}({getIntlMessage("MESSAGE_EDITED")})</span>
</Timestamp>
</div>
))}
</>
);
},
{ noop: true },
),
}, { noop: true }),
makeEdit(newMessage: any, oldMessage: any): any {
return {

View file

@ -19,6 +19,7 @@
import { definePluginSettings } from "@api/Settings";
import { Flex } from "@components/Flex";
import { Devs } from "@utils/constants";
import { getIntlMessage } from "@utils/discord";
import { Margins } from "@utils/margins";
import definePlugin, { OptionType } from "@utils/types";
import { findByCodeLazy, findLazy } from "@webpack";
@ -191,9 +192,9 @@ export default definePlugin({
replacement: [
// make the tag show the right text
{
match: /(switch\((\i)\){.+?)case (\i(?:\.\i)?)\.BOT:default:(\i)=.{0,40}(\i\.\i\.Messages)\.APP_TAG/,
replace: (_, origSwitch, variant, tags, displayedText, strings) =>
`${origSwitch}default:{${displayedText} = $self.getTagText(${tags}[${variant}], ${strings})}`
match: /(switch\((\i)\){.+?)case (\i(?:\.\i)?)\.BOT:default:(\i)=(.{0,40}#{intl::APP_TAG}\))/,
replace: (_, origSwitch, variant, tags, displayedText, originalText) =>
`${origSwitch}default:{${displayedText} = $self.getTagText(${tags}[${variant}],${originalText})}`
},
// show OP tags correctly
{
@ -295,21 +296,25 @@ export default definePlugin({
isOPTag: (tag: number) => tag === Tag.Types.ORIGINAL_POSTER || tags.some(t => tag === Tag.Types[`${t.name}-OP`]),
getTagText(passedTagName: string, strings: Record<string, string>) {
if (!passedTagName) return strings.APP_TAG;
const [tagName, variant] = passedTagName.split("-");
const tag = tags.find(({ name }) => tagName === name);
if (!tag) return strings.APP_TAG;
if (variant === "BOT" && tagName !== "WEBHOOK" && this.settings.store.dontShowForBots) return strings.APP_TAG;
getTagText(passedTagName: string, originalText: string) {
try {
const [tagName, variant] = passedTagName.split("-");
if (!passedTagName) return getIntlMessage("APP_TAG");
const tag = tags.find(({ name }) => tagName === name);
if (!tag) return getIntlMessage("APP_TAG");
if (variant === "BOT" && tagName !== "WEBHOOK" && this.settings.store.dontShowForBots) return getIntlMessage("APP_TAG");
const tagText = settings.store.tagSettings?.[tag.name]?.text || tag.displayName;
switch (variant) {
case "OP":
return `${strings.BOT_TAG_FORUM_ORIGINAL_POSTER}${tagText}`;
case "BOT":
return `${strings.APP_TAG}${tagText}`;
default:
return tagText;
const tagText = settings.store.tagSettings?.[tag.name]?.text || tag.displayName;
switch (variant) {
case "OP":
return `${getIntlMessage("BOT_TAG_FORUM_ORIGINAL_POSTER")}${tagText}`;
case "BOT":
return `${getIntlMessage("APP_TAG")}${tagText}`;
default:
return tagText;
}
} catch {
return originalText;
}
},

View file

@ -18,8 +18,9 @@
import ErrorBoundary from "@components/ErrorBoundary";
import { Devs } from "@utils/constants";
import { getIntlMessage } from "@utils/discord";
import definePlugin from "@utils/types";
import { Constants, GuildStore, i18n, RestAPI } from "@webpack/common";
import { Constants, GuildStore, RestAPI } from "@webpack/common";
function showDisableInvites(guildId: string) {
// @ts-ignore
@ -61,7 +62,7 @@ export default definePlugin({
renderInvitesLabel: ErrorBoundary.wrap(({ guildId, setChecked }) => {
return (
<div>
{i18n.Messages.GUILD_INVITE_DISABLE_ACTION_SHEET_DESCRIPTION}
{getIntlMessage("GUILD_INVITE_DISABLE_ACTION_SHEET_DESCRIPTION")}
{showDisableInvites(guildId) && <a role="button" onClick={() => {
setChecked(true);
disableInvites(guildId);

View file

@ -19,10 +19,10 @@
import ErrorBoundary from "@components/ErrorBoundary";
import { Flex } from "@components/Flex";
import { InfoIcon, OwnerCrownIcon } from "@components/Icons";
import { getUniqueUsername } from "@utils/discord";
import { getIntlMessage, getUniqueUsername } from "@utils/discord";
import { ModalCloseButton, ModalContent, ModalHeader, ModalProps, ModalRoot, ModalSize, openModal } from "@utils/modal";
import { findByCodeLazy } from "@webpack";
import { Clipboard, ContextMenuApi, FluxDispatcher, GuildMemberStore, GuildStore, i18n, Menu, PermissionsBits, ScrollerThin, Text, Tooltip, useEffect, UserStore, useState, useStateFromStores } from "@webpack/common";
import { Clipboard, ContextMenuApi, FluxDispatcher, GuildMemberStore, GuildStore, Menu, PermissionsBits, ScrollerThin, Text, Tooltip, useEffect, UserStore, useState, useStateFromStores } from "@webpack/common";
import { UnicodeEmoji } from "@webpack/types";
import type { Guild, Role, User } from "discord-types/general";
@ -216,7 +216,7 @@ function RoleContextMenu({ guild, roleId, onClose }: { guild: Guild; roleId: str
>
<Menu.MenuItem
id={cl("copy-role-id")}
label={i18n.Messages.COPY_ID_ROLE}
label={getIntlMessage("COPY_ID_ROLE")}
action={() => {
Clipboard.copy(roleId);
}}
@ -225,7 +225,7 @@ function RoleContextMenu({ guild, roleId, onClose }: { guild: Guild; roleId: str
{(settings.store as any).unsafeViewAsRole && (
<Menu.MenuItem
id={cl("view-as-role")}
label={i18n.Messages.VIEW_AS_ROLE}
label={getIntlMessage("VIEW_AS_ROLE")}
action={() => {
const role = GuildStore.getRole(guild.id, roleId);
if (!role) return;
@ -257,7 +257,7 @@ function UserContextMenu({ userId }: { userId: string; }) {
>
<Menu.MenuItem
id={cl("copy-user-id")}
label={i18n.Messages.COPY_ID_USER}
label={getIntlMessage("COPY_ID_USER")}
action={() => {
Clipboard.copy(userId);
}}

View file

@ -18,9 +18,10 @@
import ErrorBoundary from "@components/ErrorBoundary";
import { ExpandableHeader } from "@components/ExpandableHeader";
import { getIntlMessage } from "@utils/discord";
import { classes } from "@utils/misc";
import { filters, findBulk, proxyLazyWebpack } from "@webpack";
import { i18n, PermissionsBits, Text, Tooltip, useMemo, UserStore } from "@webpack/common";
import { PermissionsBits, Text, Tooltip, useMemo, UserStore } from "@webpack/common";
import type { Guild, GuildMember } from "discord-types/general";
import { PermissionsSortOrder, settings } from "..";
@ -105,7 +106,7 @@ function UserPermissionsComponent({ guild, guildMember, forceOpen = false }: { g
permissions: Object.values(PermissionsBits).reduce((prev, curr) => prev | curr, 0n)
});
const OWNER = i18n.Messages.GUILD_OWNER || "Server Owner";
const OWNER = getIntlMessage("GUILD_OWNER") || "Server Owner";
userPermissions.push({
permission: OWNER,
roleName: "Owner",

View file

@ -17,8 +17,9 @@
*/
import { classNameFactory } from "@api/Styles";
import { getIntlMessage } from "@utils/discord";
import { wordsToTitle } from "@utils/text";
import { GuildStore, i18n, Parser } from "@webpack/common";
import { GuildStore, Parser } from "@webpack/common";
import { Guild, GuildMember, Role } from "discord-types/general";
import type { ReactNode } from "react";
@ -44,7 +45,7 @@ const PermissionKeyMap = {
export function getPermissionString(permission: string) {
permission = PermissionKeyMap[permission] || permission;
return i18n.Messages[permission] ||
return getIntlMessage(permission) ||
// shouldn't get here but just in case
formatPermissionWithoutMatchingString(permission);
}
@ -58,7 +59,7 @@ export function getPermissionDescription(permission: string): ReactNode {
else if (permission !== "STREAM")
permission = PermissionKeyMap[permission] || permission;
const msg = i18n.Messages[`ROLE_PERMISSIONS_${permission}_DESCRIPTION`] as any;
const msg = getIntlMessage(`ROLE_PERMISSIONS_${permission}_DESCRIPTION`) as any;
if (msg?.hasMarkdown)
return Parser.parse(msg.message);

View file

@ -30,7 +30,7 @@ interface ColorPickerWithSwatchesProps {
renderCustomButton?: () => React.ReactNode;
}
const ColorPicker = findComponentByCodeLazy<ColorPickerProps>(".Messages.USER_SETTINGS_PROFILE_COLOR_SELECT_COLOR", ".BACKGROUND_PRIMARY)");
const ColorPicker = findComponentByCodeLazy<ColorPickerProps>("#{intl::USER_SETTINGS_PROFILE_COLOR_SELECT_COLOR}", ".BACKGROUND_PRIMARY)");
const ColorPickerWithSwatches = findExportedComponentLazy<ColorPickerWithSwatchesProps>("ColorPicker", "CustomColorPicker");
export const requireSettingsMenu = extractAndLoadChunksLazy(['name:"UserSettings"'], /createPromise:.{0,20}Promise\.all\((\[\i\.\i\("?.+?"?\).+?\])\).then\(\i\.bind\(\i,"?(.+?)"?\)\).{0,50}"UserSettings"/);

View file

@ -16,11 +16,12 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { getIntlMessage } from "@utils/discord";
import { findComponentByCodeLazy, findLazy } from "@webpack";
import { i18n, useToken } from "@webpack/common";
import { useToken } from "@webpack/common";
const ColorMap = findLazy(m => m.colors?.INTERACTIVE_MUTED?.css);
const VerifiedIconComponent = findComponentByCodeLazy(".CONNECTIONS_ROLE_OFFICIAL_ICON_TOOLTIP");
const VerifiedIconComponent = findComponentByCodeLazy("#{intl::CONNECTIONS_ROLE_OFFICIAL_ICON_TOOLTIP}");
export function VerifiedIcon() {
const color = useToken(ColorMap.colors.INTERACTIVE_MUTED).hex();
@ -31,7 +32,7 @@ export function VerifiedIcon() {
color={color}
forcedIconColor={forcedIconColor}
size={16}
tooltipText={i18n.Messages.CONNECTION_VERIFIED}
tooltipText={getIntlMessage("CONNECTION_VERIFIED")}
/>
);
}

View file

@ -19,7 +19,7 @@
import { Settings } from "@api/Settings";
import ErrorBoundary from "@components/ErrorBoundary";
import { formatDuration } from "@utils/text";
import { findByPropsLazy, findComponentByCodeLazy, findComponentLazy } from "@webpack";
import { findByPropsLazy, findComponentByCodeLazy } from "@webpack";
import { EmojiStore, FluxDispatcher, GuildMemberStore, GuildStore, Parser, PermissionsBits, PermissionStore, SnowflakeUtils, Text, Timestamp, Tooltip, useEffect, useState } from "@webpack/common";
import type { Channel } from "discord-types/general";
@ -80,14 +80,8 @@ const enum ChannelFlags {
const ChatScrollClasses = findByPropsLazy("auto", "managedReactiveScroller");
const ChatClasses = findByPropsLazy("chat", "content", "noChat", "chatContent");
const ChannelBeginHeader = findComponentByCodeLazy(".Messages.ROLE_REQUIRED_SINGLE_USER_MESSAGE");
const TagComponent = findComponentLazy(m => {
if (typeof m !== "function") return false;
const code = Function.prototype.toString.call(m);
// Get the component which doesn't include increasedActivity
return code.includes(".Messages.FORUM_TAG_A11Y_FILTER_BY_TAG") && !code.includes("increasedActivityPill");
});
const ChannelBeginHeader = findComponentByCodeLazy("#{intl::ROLE_REQUIRED_SINGLE_USER_MESSAGE}");
const TagComponent = findComponentByCodeLazy("#{intl::FORUM_TAG_A11Y_FILTER_BY_TAG}");
const EmojiParser = findByPropsLazy("convertSurrogateToName");
const EmojiUtils = findByPropsLazy("getURL", "getEmojiColors");

View file

@ -9,13 +9,16 @@ import "./styles.css";
import { definePluginSettings } from "@api/Settings";
import ErrorBoundary from "@components/ErrorBoundary";
import { Devs } from "@utils/constants";
import { getIntlMessage } from "@utils/discord";
import { canonicalizeMatch } from "@utils/patches";
import definePlugin, { OptionType } from "@utils/types";
import { findComponentLazy } from "@webpack";
import { ChannelStore, GuildMemberStore, i18n, Text, Tooltip } from "@webpack/common";
import { ChannelStore, GuildMemberStore, Text, Tooltip } from "@webpack/common";
import { Message } from "discord-types/general";
import { FunctionComponent, ReactNode } from "react";
const CountDown = findComponentLazy(m => m.prototype?.render?.toString().includes(".MAX_AGE_NEVER"));
const countDownFilter = canonicalizeMatch("#{intl::MAX_AGE_NEVER}");
const CountDown = findComponentLazy(m => m.prototype?.render?.toString().includes(countDownFilter));
const enum DisplayStyle {
Tooltip = "tooltip",
@ -48,9 +51,14 @@ function renderTimeout(message: Message, inline: boolean) {
/>
);
getIntlMessage("GUILD_ENABLE_COMMUNICATION_TIME_REMAINING", {
username: message.author.username,
countdown
});
return inline
? countdown()
: i18n.Messages.GUILD_ENABLE_COMMUNICATION_TIME_REMAINING.format({
: getIntlMessage("GUILD_ENABLE_COMMUNICATION_TIME_REMAINING", {
username: message.author.username,
countdown
});

View file

@ -21,9 +21,10 @@ import "./style.css";
import { definePluginSettings, Settings } from "@api/Settings";
import ErrorBoundary from "@components/ErrorBoundary";
import { Devs } from "@utils/constants";
import { getIntlMessage } from "@utils/discord";
import definePlugin, { OptionType } from "@utils/types";
import { findComponentByCodeLazy, findExportedComponentLazy, findStoreLazy } from "@webpack";
import { ChannelStore, GuildMemberStore, i18n, RelationshipStore, SelectedChannelStore, Tooltip, UserStore, useStateFromStores } from "@webpack/common";
import { ChannelStore, GuildMemberStore, RelationshipStore, SelectedChannelStore, Tooltip, UserStore, useStateFromStores } from "@webpack/common";
import { buildSeveralUsers } from "../typingTweaks";
@ -75,21 +76,21 @@ function TypingIndicator({ channelId }: { channelId: string; }) {
switch (typingUsersArray.length) {
case 0: break;
case 1: {
tooltipText = i18n.Messages.ONE_USER_TYPING.format({ a: getDisplayName(guildId, typingUsersArray[0]) });
tooltipText = getIntlMessage("ONE_USER_TYPING", { a: getDisplayName(guildId, typingUsersArray[0]) });
break;
}
case 2: {
tooltipText = i18n.Messages.TWO_USERS_TYPING.format({ a: getDisplayName(guildId, typingUsersArray[0]), b: getDisplayName(guildId, typingUsersArray[1]) });
tooltipText = getIntlMessage("TWO_USERS_TYPING", { a: getDisplayName(guildId, typingUsersArray[0]), b: getDisplayName(guildId, typingUsersArray[1]) });
break;
}
case 3: {
tooltipText = i18n.Messages.THREE_USERS_TYPING.format({ a: getDisplayName(guildId, typingUsersArray[0]), b: getDisplayName(guildId, typingUsersArray[1]), c: getDisplayName(guildId, typingUsersArray[2]) });
tooltipText = getIntlMessage("THREE_USERS_TYPING", { a: getDisplayName(guildId, typingUsersArray[0]), b: getDisplayName(guildId, typingUsersArray[1]), c: getDisplayName(guildId, typingUsersArray[2]) });
break;
}
default: {
tooltipText = Settings.plugins.TypingTweaks.enabled
? buildSeveralUsers({ a: getDisplayName(guildId, typingUsersArray[0]), b: getDisplayName(guildId, typingUsersArray[1]), count: typingUsersArray.length - 2 })
: i18n.Messages.SEVERAL_USERS_TYPING;
: getIntlMessage("SEVERAL_USERS_TYPING");
break;
}
}

View file

@ -112,8 +112,8 @@ export default definePlugin({
{
find: "getCooldownTextStyle",
replacement: {
match: /(?<=(\i)\.length\?\i.\i\.Messages.THREE_USERS_TYPING\.format\({\i:(\i),(?:\i:)?(\i),\i:\i}\):)\i\.\i\.Messages\.SEVERAL_USERS_TYPING/,
replace: (_, users, a, b) => `$self.buildSeveralUsers({ a: ${a}, b: ${b}, count: ${users}.length - 2 })`
match: /(,{a:(\i),b:(\i),c:\i}\):)\i\.\i\.string\(\i\.\i#{intl::SEVERAL_USERS_TYPING}\)(?<=(\i)\.length.+?)/,
replace: (_, rest, a, b, users) => `${rest}$self.buildSeveralUsers({ a: ${a}, b: ${b}, count: ${users}.length - 2 })`
},
predicate: () => settings.store.alternativeFormatting
}

View file

@ -18,9 +18,10 @@
import { getUserSettingLazy } from "@api/UserSettings";
import ErrorBoundary from "@components/ErrorBoundary";
import { getIntlMessage } from "@utils/discord";
import { classes } from "@utils/misc";
import { findByPropsLazy } from "@webpack";
import { i18n, Tooltip, UserStore } from "@webpack/common";
import { Tooltip, UserStore } from "@webpack/common";
import { Message } from "discord-types/general";
import { settings } from "./settings";
@ -44,7 +45,7 @@ function PronounsChatComponent({ message }: { message: Message; }) {
const pronouns = useFormattedPronouns(message.author.id);
return pronouns && (
<Tooltip text={i18n.Messages.USER_PROFILE_PRONOUNS}>
<Tooltip text={getIntlMessage("USER_PROFILE_PRONOUNS")}>
{tooltipProps => (
<span
{...tooltipProps}

View file

@ -14,7 +14,7 @@ import { Channel } from "discord-types/general";
const cl = classNameFactory("vc-uvs-");
const { selectVoiceChannel } = findByPropsLazy("selectVoiceChannel", "selectChannel");
const { useChannelName } = mapMangledModuleLazy(".Messages.GROUP_DM_ALONE", {
const { useChannelName } = mapMangledModuleLazy("#{intl::GROUP_DM_ALONE}", {
useChannelName: filters.byCode("()=>null==")
});
const getDMChannelIcon = findByCodeLazy(".getChannelIconURL({");

View file

@ -78,7 +78,7 @@ export default definePlugin({
{
find: "PrivateChannel.renderAvatar",
replacement: {
match: /\.Messages\.CLOSE_DM.+?}\)(?=])/,
match: /#{intl::CLOSE_DM}.+?}\)(?=])/,
replace: "$&,$self.VoiceChannelIndicator({userId:arguments[0]?.user?.id})"
},
predicate: () => settings.store.showVoiceChannelIndicator

View file

@ -39,7 +39,7 @@ export default definePlugin({
{
find: "#{intl::REPLY_QUOTE_MESSAGE_NOT_LOADED}",
replacement: {
match: /#{intl::REPLY_QUOTE_MESSAGE_NOT_LOADED}"\]\)/,
match: /#{intl::REPLY_QUOTE_MESSAGE_NOT_LOADED}\)/,
replace: "$&,onMouseEnter:()=>$self.fetchReply(arguments[0])"
}
},

View file

@ -23,11 +23,12 @@ import { CodeBlock } from "@components/CodeBlock";
import ErrorBoundary from "@components/ErrorBoundary";
import { Flex } from "@components/Flex";
import { Devs } from "@utils/constants";
import { getIntlMessage } from "@utils/discord";
import { Margins } from "@utils/margins";
import { copyWithToast } from "@utils/misc";
import { closeModal, ModalCloseButton, ModalContent, ModalFooter, ModalHeader, ModalRoot, ModalSize, openModal } from "@utils/modal";
import definePlugin, { OptionType } from "@utils/types";
import { Button, ChannelStore, Forms, i18n, Menu, Text } from "@webpack/common";
import { Button, ChannelStore, Forms, Menu, Text } from "@webpack/common";
import { Message } from "discord-types/general";
@ -122,7 +123,7 @@ function MakeContextCallback(name: "Guild" | "User" | "Channel"): NavContextMenu
return (children, props) => {
const value = props[name.toLowerCase()];
if (!value) return;
if (props.label === i18n.Messages.CHANNEL_ACTIONS_MENU_LABEL) return; // random shit like notification settings
if (props.label === getIntlMessage("CHANNEL_ACTIONS_MENU_LABEL")) return; // random shit like notification settings
const lastChild = children.at(-1);
if (lastChild?.key === "developer-actions") {

View file

@ -19,12 +19,39 @@
import "./discord.css";
import { MessageObject } from "@api/MessageEvents";
import { ChannelStore, ComponentDispatch, Constants, FluxDispatcher, GuildStore, InviteActions, MessageActions, PrivateChannelsStore, RestAPI, SelectedChannelStore, SelectedGuildStore, UserProfileActions, UserProfileStore, UserSettingsActionCreators, UserUtils } from "@webpack/common";
import { ChannelStore, ComponentDispatch, Constants, FluxDispatcher, GuildStore, i18n, InviteActions, MessageActions, PrivateChannelsStore, RestAPI, SelectedChannelStore, SelectedGuildStore, UserProfileActions, UserProfileStore, UserSettingsActionCreators, UserUtils } from "@webpack/common";
import { Channel, Guild, Message, User } from "discord-types/general";
import { Except } from "type-fest";
import { runtimeHashMessageKey } from "./intlHash";
import { Logger } from "./Logger";
import { MediaModalItem, MediaModalProps, openMediaModal } from "./modal";
const IntlManagerLogger = new Logger("IntlManager");
/**
* Get an internationalized message from a non hashed key
* @param key The plain message key
* @param values The values to interpolate, if it's a rich message
*/
export function getIntlMessage(key: string, values?: Record<PropertyKey, any>): any {
return getIntlMessageFromHash(runtimeHashMessageKey(key), values, key);
}
/**
* Get an internationalized message from a hashed key
* @param hashedKey The hashed message key
* @param values The values to interpolate, if it's a rich message
*/
export function getIntlMessageFromHash(hashedKey: string, values?: Record<PropertyKey, any>, originalKey?: string): any {
try {
return values == null ? i18n.intl.string(i18n.t[hashedKey]) : i18n.intl.format(i18n.t[hashedKey], values);
} catch (e) {
IntlManagerLogger.error(`Failed to get intl message for key: ${originalKey ?? hashedKey}`, e);
return originalKey ?? "";
}
}
/**
* Open the invite modal
* @param code The invite code

View file

@ -8,7 +8,6 @@
* @license MIT
*/
import { hash as h64 } from "@intrnl/xxhash64";
const BASE64_TABLE = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split("");

View file

@ -25,12 +25,12 @@ export function canonicalizeMatch<T extends RegExp | string>(match: T): T {
const hashed = runtimeHashMessageKey(key);
const isString = typeof match === "string";
const hasSpecialChars = /^[\d]/.test(hashed) || !/^[\w$]+$/.test(hashed);
const hasSpecialChars = !Number.isNaN(Number(hashed[0])) || hashed.includes("+") || hashed.includes("/");
if (hasSpecialChars) {
return isString
? `["${hashed}`
: String.raw`(?:\["${hashed})`.replaceAll("+", "\\+");
? `["${hashed}"]`
: String.raw`(?:\["${hashed}"\])`.replaceAll("+", "\\+");
}
return isString ? `.${hashed}` : String.raw`(?:\.${hashed})`;

View file

@ -57,7 +57,7 @@ export let FocusLock: t.FocusLock;
export let useToken: t.useToken;
export const MaskedLink = waitForComponent<t.MaskedLink>("MaskedLink", filters.componentByCode("MASKED_LINK)"));
export const Timestamp = waitForComponent<t.Timestamp>("Timestamp", filters.byCode(".Messages.MESSAGE_EDITED_TIMESTAMP_A11Y_LABEL.format"));
export const Timestamp = waitForComponent<t.Timestamp>("Timestamp", filters.byCode("#{intl::MESSAGE_EDITED_TIMESTAMP_A11Y_LABEL}"));
export const Flex = waitForComponent<t.Flex>("Flex", ["Justify", "Align", "Wrap"]);
export const { OAuth2AuthorizeModal } = findByPropsLazy("OAuth2AuthorizeModal");

File diff suppressed because one or more lines are too long

View file

@ -19,7 +19,6 @@
export * from "./classes";
export * from "./components";
export * from "./fluxEvents";
export * from "./i18nMessages";
export * from "./menu";
export * from "./passiveupdatestate";
export * from "./stores";

View file

@ -21,7 +21,6 @@ import type { ReactNode } from "react";
import { LiteralUnion } from "type-fest";
import type { FluxEvents } from "./fluxEvents";
import { i18nMessages } from "./i18nMessages";
export { FluxEvents };
@ -150,19 +149,6 @@ export interface LocaleInfo {
postgresLang: string;
}
export interface i18n {
getAvailableLocales(): Locale[];
getLanguages(): LocaleInfo[];
getDefaultLocale(): string;
getLocale(): string;
getLocaleInfo(): LocaleInfo;
setLocale(locale: string): void;
loadPromise: Promise<void>;
Messages: Record<i18nMessages, any>;
}
export interface Clipboard {
copy(text: string): void;
SUPPORTS_COPY: boolean;

View file

@ -16,6 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { runtimeHashMessageKey } from "@utils/intlHash";
import type { Channel } from "discord-types/general";
import { _resolveReady, filters, findByCodeLazy, findByPropsLazy, findLazy, mapMangledModuleLazy, waitFor } from "../webpack";
@ -59,7 +60,10 @@ export const { match, P }: Pick<typeof import("ts-pattern"), "match" | "P"> = ma
export const lodash: typeof import("lodash") = findByPropsLazy("debounce", "cloneDeep");
export const i18n: t.i18n = findLazy(m => m.Messages?.["en-US"]);
export const i18n = mapMangledModuleLazy('defaultLocale:"en-US"', {
intl: filters.byProps("string", "format"),
t: filters.byProps(runtimeHashMessageKey("DISCORD"))
});
export let SnowflakeUtils: t.SnowflakeUtils;
waitFor(["fromTimestamp", "extractTimestamp"], m => SnowflakeUtils = m);
@ -133,7 +137,7 @@ export const UserUtils = {
export const UploadManager = findByPropsLazy("clearAll", "addFile");
export const UploadHandler = {
promptToUpload: findByCodeLazy(".ATTACHMENT_TOO_MANY_ERROR_TITLE,") as (files: File[], channel: Channel, draftType: Number) => void
promptToUpload: findByCodeLazy("#{intl::ATTACHMENT_TOO_MANY_ERROR_TITLE}") as (files: File[], channel: Channel, draftType: Number) => void
};
export const ApplicationAssetUtils = findByPropsLazy("fetchAssetIds", "getAssetImage") as {