From 4c642bfcc3414e4e3e04a98b679ef95aabda4164 Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Sun, 3 Nov 2024 14:24:43 -0300 Subject: [PATCH 01/12] Fix broken finds --- src/plugins/clientTheme/index.tsx | 2 +- src/plugins/fakeProfileThemes/index.tsx | 4 ++-- .../pinDms/components/CreateCategoryModal.tsx | 2 +- src/plugins/showConnections/VerifiedIcon.tsx | 2 +- .../components/HiddenChannelLockScreen.tsx | 12 +++--------- src/plugins/showTimeoutDuration/index.tsx | 4 +++- src/plugins/userVoiceShow/components.tsx | 2 +- src/webpack/common/components.ts | 2 +- src/webpack/common/utils.ts | 2 +- 9 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/plugins/clientTheme/index.tsx b/src/plugins/clientTheme/index.tsx index 59f3d5fe..7e648427 100644 --- a/src/plugins/clientTheme/index.tsx +++ b/src/plugins/clientTheme/index.tsx @@ -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", diff --git a/src/plugins/fakeProfileThemes/index.tsx b/src/plugins/fakeProfileThemes/index.tsx index edc0e740..495d2ddc 100644 --- a/src/plugins/fakeProfileThemes/index.tsx +++ b/src/plugins/fakeProfileThemes/index.tsx @@ -108,10 +108,10 @@ interface ProfileModalProps { isTryItOutFlow: boolean; } -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 ProfileModal = findComponentByCodeLazy("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", diff --git a/src/plugins/pinDms/components/CreateCategoryModal.tsx b/src/plugins/pinDms/components/CreateCategoryModal.tsx index 2f1d4d1d..7c4cf0d0 100644 --- a/src/plugins/pinDms/components/CreateCategoryModal.tsx +++ b/src/plugins/pinDms/components/CreateCategoryModal.tsx @@ -30,7 +30,7 @@ interface ColorPickerWithSwatchesProps { renderCustomButton?: () => React.ReactNode; } -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 ColorPickerWithSwatches = findExportedComponentLazy("ColorPicker", "CustomColorPicker"); export const requireSettingsMenu = extractAndLoadChunksLazy(['name:"UserSettings"'], /createPromise:.{0,20}Promise\.all\((\[\i\.\i\("?.+?"?\).+?\])\).then\(\i\.bind\(\i,"?(.+?)"?\)\).{0,50}"UserSettings"/); diff --git a/src/plugins/showConnections/VerifiedIcon.tsx b/src/plugins/showConnections/VerifiedIcon.tsx index ffdf21e6..d4d3f094 100644 --- a/src/plugins/showConnections/VerifiedIcon.tsx +++ b/src/plugins/showConnections/VerifiedIcon.tsx @@ -20,7 +20,7 @@ import { findComponentByCodeLazy, findLazy } from "@webpack"; import { i18n, 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(); diff --git a/src/plugins/showHiddenChannels/components/HiddenChannelLockScreen.tsx b/src/plugins/showHiddenChannels/components/HiddenChannelLockScreen.tsx index bdb9fee8..51c984b0 100644 --- a/src/plugins/showHiddenChannels/components/HiddenChannelLockScreen.tsx +++ b/src/plugins/showHiddenChannels/components/HiddenChannelLockScreen.tsx @@ -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"); diff --git a/src/plugins/showTimeoutDuration/index.tsx b/src/plugins/showTimeoutDuration/index.tsx index c0f5e918..6f00f4c7 100644 --- a/src/plugins/showTimeoutDuration/index.tsx +++ b/src/plugins/showTimeoutDuration/index.tsx @@ -9,13 +9,15 @@ import "./styles.css"; import { definePluginSettings } from "@api/Settings"; import ErrorBoundary from "@components/ErrorBoundary"; import { Devs } from "@utils/constants"; +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 { 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", diff --git a/src/plugins/userVoiceShow/components.tsx b/src/plugins/userVoiceShow/components.tsx index 7a6f4dd2..e8924f82 100644 --- a/src/plugins/userVoiceShow/components.tsx +++ b/src/plugins/userVoiceShow/components.tsx @@ -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({"); diff --git a/src/webpack/common/components.ts b/src/webpack/common/components.ts index 0bcb82d1..11526c0f 100644 --- a/src/webpack/common/components.ts +++ b/src/webpack/common/components.ts @@ -56,7 +56,7 @@ export let FocusLock: t.FocusLock; export let useToken: t.useToken; export const MaskedLink = waitForComponent("MaskedLink", filters.componentByCode("MASKED_LINK)")); -export const Timestamp = waitForComponent("Timestamp", filters.byCode(".Messages.MESSAGE_EDITED_TIMESTAMP_A11Y_LABEL.format")); +export const Timestamp = waitForComponent("Timestamp", filters.byCode("#{intl::MESSAGE_EDITED_TIMESTAMP_A11Y_LABEL}")); export const Flex = waitForComponent("Flex", ["Justify", "Align", "Wrap"]); export const { OAuth2AuthorizeModal } = findByPropsLazy("OAuth2AuthorizeModal"); diff --git a/src/webpack/common/utils.ts b/src/webpack/common/utils.ts index 2d0026b5..2bce1db7 100644 --- a/src/webpack/common/utils.ts +++ b/src/webpack/common/utils.ts @@ -131,7 +131,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 { From 907bc25eef573565b135aae7e52cb2f95049926c Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Sun, 3 Nov 2024 14:26:39 -0300 Subject: [PATCH 02/12] Temp fix for settings --- src/plugins/_core/settings.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/plugins/_core/settings.tsx b/src/plugins/_core/settings.tsx index 939cf83a..e9eaa71b 100644 --- a/src/plugins/_core/settings.tsx +++ b/src/plugins/_core/settings.tsx @@ -26,7 +26,7 @@ import UpdaterTab from "@components/VencordSettings/UpdaterTab"; import VencordTab from "@components/VencordSettings/VencordTab"; import { Devs } from "@utils/constants"; import definePlugin, { OptionType } from "@utils/types"; -import { i18n, React } from "@webpack/common"; +import { React } from "@webpack/common"; import gitHash from "~git-hash"; @@ -148,13 +148,13 @@ export default definePlugin({ if (!header) return; - const names = { + /* const names = { top: i18n.Messages.USER_SETTINGS, aboveNitro: i18n.Messages.BILLING_SETTINGS, belowNitro: i18n.Messages.APP_SETTINGS, aboveActivity: i18n.Messages.ACTIVITY_SETTINGS }; - return header === names[settingsLocation]; + return header === names[settingsLocation]; */ }, patchedSettings: new WeakSet(), From a1487b50bebaa27cc4bfa125c0c81d0cb3a2f04d Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Sun, 3 Nov 2024 15:00:08 -0300 Subject: [PATCH 03/12] Fix settings properly --- src/plugins/_core/settings.tsx | 13 +++++++------ src/utils/discord.tsx | 21 ++++++++++++++++++++- src/webpack/common/types/i18nMessages.ts | 24 ------------------------ src/webpack/common/types/index.d.ts | 1 - src/webpack/common/types/utils.d.ts | 14 -------------- src/webpack/common/utils.ts | 6 +++++- 6 files changed, 32 insertions(+), 47 deletions(-) delete mode 100644 src/webpack/common/types/i18nMessages.ts diff --git a/src/plugins/_core/settings.tsx b/src/plugins/_core/settings.tsx index e9eaa71b..cde3e9e6 100644 --- a/src/plugins/_core/settings.tsx +++ b/src/plugins/_core/settings.tsx @@ -25,6 +25,7 @@ import ThemesTab from "@components/VencordSettings/ThemesTab"; 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 { React } from "@webpack/common"; @@ -148,13 +149,13 @@ export default definePlugin({ if (!header) return; - /* const names = { - top: i18n.Messages.USER_SETTINGS, - aboveNitro: i18n.Messages.BILLING_SETTINGS, - belowNitro: i18n.Messages.APP_SETTINGS, - aboveActivity: i18n.Messages.ACTIVITY_SETTINGS + const names = { + top: getIntlMessage("USER_SETTINGS"), + aboveNitro: getIntlMessage("BILLING_SETTINGS"), + belowNitro: getIntlMessage("APP_SETTINGS"), + aboveActivity: getIntlMessage("ACTIVITY_SETTINGS") }; - return header === names[settingsLocation]; */ + return header === names[settingsLocation]; }, patchedSettings: new WeakSet(), diff --git a/src/utils/discord.tsx b/src/utils/discord.tsx index fed5a5d8..c79bbc39 100644 --- a/src/utils/discord.tsx +++ b/src/utils/discord.tsx @@ -19,12 +19,31 @@ 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 { MediaModalItem, MediaModalProps, openMediaModal } from "./modal"; +/** + * 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): string { + return getIntlMessageFromHash(runtimeHashMessageKey(key), values); +} + +/** + * Get an internationalized message from a hashed key + * @param key The hashed message key + * @param values The values to interpolate, if it's a rich message + */ +export function getIntlMessageFromHash(key: string, values?: Record): string { + return values == null ? i18n.intl.string(i18n.t[key]) : i18n.intl.format(i18n.t[key], values); +} + /** * Open the invite modal * @param code The invite code diff --git a/src/webpack/common/types/i18nMessages.ts b/src/webpack/common/types/i18nMessages.ts deleted file mode 100644 index fdf677fc..00000000 --- a/src/webpack/common/types/i18nMessages.ts +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Vencord, a modification for Discord's desktop app - * Copyright (c) 2023 Vendicated and contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . -*/ - -import { LiteralUnion } from "type-fest"; - -export type i18nMessages = LiteralUnion< - "TITLE_BAR_CLOSE_WINDOW" | "TITLE_BAR_MAXIMIZE_WINDOW" | "TITLE_BAR_MINIMIZE_WINDOW" | "en-US" | "en-GB" | "zh-CN" | "zh-TW" | "cs" | "da" | "nl" | "fr" | "de" | "el" | "hu" | "it" | "ja" | "ko" | "pl" | "pt-BR" | "ru" | "es-ES" | "sv-SE" | "tr" | "bg" | "uk" | "fi" | "no" | "hr" | "ro" | "lt" | "th" | "vi" | "hi" | "KEYBIND_DESCRIPTION_MODAL_NAVIGATE_SERVERS" | "KEYBIND_DESCRIPTION_MODAL_NAVIGATE_CHANNELS" | "KEYBIND_DESCRIPTION_MODAL_NAVIGATE_BACK_FORWARD" | "KEYBIND_DESCRIPTION_MODAL_UNREAD_CHANNELS" | "KEYBIND_DESCRIPTION_MODAL_UNREAD_MENTION_CHANNELS" | "KEYBIND_DESCRIPTION_MODAL_NAVIGATE_TO_CALL" | "KEYBIND_DESCRIPTION_MODAL_TOGGLE_PREVIOUS_GUILD" | "KEYBIND_DESCRIPTION_MODAL_QUICKSWITCHER" | "KEYBIND_DESCRIPTION_MODAL_CREATE_GUILD" | "DND_OPERATION_LABEL_START" | "DND_OPERATION_LABEL_MOVE" | "DND_OPERATION_LABEL_DROP" | "DND_OPERATION_LABEL_CANCEL" | "KEYBIND_DESCRIPTION_MODAL_MARK_SERVER_READ" | "KEYBIND_DESCRIPTION_MODAL_MARK_CHANNEL_READ" | "KEYBIND_DESCRIPTION_MODAL_CREATE_DM_GROUP" | "KEYBIND_DESCRIPTION_MODAL_TOGGLE_PINS" | "KEYBIND_DESCRIPTION_MODAL_TOGGLE_INBOX" | "KEYBIND_DESCRIPTION_MODAL_MARK_TOP_INBOX_CHANNEL_READ" | "KEYBIND_DESCRIPTION_MODAL_TOGGLE_USERS" | "KEYBIND_DESCRIPTION_MODAL_SEARCH_EMOJIS" | "KEYBIND_DESCRIPTION_MODAL_SEARCH_GIFS" | "KEYBIND_DESCRIPTION_MODAL_SEARCH_STICKERS" | "KEYBIND_DESCRIPTION_MODAL_SCROLL_CHAT" | "KEYBIND_DESCRIPTION_MODAL_JUMP_TO_FIRST_UNREAD" | "KEYBIND_DESCRIPTION_MODAL_FOCUS_TEXT_AREA" | "KEYBIND_DESCRIPTION_MODAL_UPLOAD_FILE" | "KEYBIND_DESCRIPTION_MODAL_TOGGLE_MUTE" | "KEYBIND_DESCRIPTION_MODAL_TOGGLE_DEAFEN" | "KEYBIND_DESCRIPTION_MODAL_CALL_ACCEPT" | "KEYBIND_DESCRIPTION_MODAL_CALL_DECLINE" | "KEYBIND_DESCRIPTION_MODAL_CALL_START" | "KEYBIND_DESCRIPTION_MODAL_TOGGLE_HELP" | "KEYBIND_DESCRIPTION_MODAL_SEARCH" | "KEYBIND_DESCRIPTION_MODAL_EASTER_EGG" | "EDIT_MESSAGE" | "DELETE_MESSAGE" | "PIN_MESSAGE" | "ADD_REACTION" | "MESSAGE_ACTION_REPLY" | "COPY_TEXT" | "MARK_UNREAD" | "GUILDS_BAR_A11Y_LABEL" | "SERVERS" | "NEW" | "ADD_A_SERVER" | "GUILD_DISCOVERY_TOOLTIP" | "ACCOUNT_A11Y_LABEL" | "GUILD_SIDEBAR_A11Y_LABEL" | "UNKNOWN_USER" | "LOADING" | "LOADING_DID_YOU_KNOW" | "CONNECTING_PROBLEMS_CTA" | "TWEET_US" | "SERVER_STATUS" | "NOTIFICATION_CENTER_INCOMING_FRIEND_REQUEST" | "COMMAND_SHRUG_MESSAGE_DESCRIPTION" | "DIRECT_MESSAGES" | "GUILD_TOOLTIP_A11Y_LABEL" | "FAVORITES_GUILD_NAME" | "MEMBER_VERIFICATION_FOLDER_NAME" | "DND_DROP_ABOVE" | "DND_DROP_COMBINE" | "GUILD_FOLDER_TOOLTIP_A11Y_LABEL" | "DND_END_OF_LIST" | "GUILD_SIDEBAR_ACTIONS_BUTTON" | "PREMIUM_GUILD_TIER_3" | "PREMIUM_GUILD_SUBSCRIPTION_SUBSCRIBER_COUNT_TOOLTIP" | "CHANNELS" | "NEW_UNREADS" | "NEW_MENTIONS" | "UNMUTE" | "MUTE" | "DEAFEN" | "SET_STATUS" | "LABEL_WITH_ONLINE_STATUS" | "STATUS_ONLINE" | "USER_SETTINGS" | "CHANNEL_HEADER_BAR_A11Y_LABEL" | "TEXT_CHANNEL" | "UPLOAD_TO" | "UPLOAD_AREA_HELP" | "THREADS" | "NOTIFICATION_SETTINGS" | "PINNED_MESSAGES" | "MEMBER_LIST_SHOWN" | "SEARCH" | "SEARCH_CLEAR" | "INBOX" | "HELP" | "TEXTAREA_PLACEHOLDER" | "TEXTAREA_TEXT_CHANNEL_A11Y_LABEL" | "CHANNEL_A11Y_LABEL" | "CHANNEL_CHAT_HEADING" | "CHANNEL_MESSAGES_A11Y_LABEL" | "CHANNEL_MESSAGES_A11Y_DESCRIPTION" | "CHAT_ATTACH_UPLOAD_A_FILE" | "CHAT_ATTACH_UPLOAD_TEXT_AS_FILE" | "CREATE_THREAD" | "CHAT_ATTACH_USE_SLASH_COMMAND" | "CHAT_ATTACH_UPLOAD_OR_INVITE" | "PREMIUM_GIFT_BUTTON_TOOLTIP" | "PREMIUM_GIFT_BUTTON_LABEL" | "GIF_BUTTON_LABEL" | "STICKER_BUTTON_LABEL" | "SELECT_EMOJI" | "CHARACTER_COUNT_CLOSE_TO_LIMIT" | "MEMBERS_LIST_LANDMARK_LABEL" | "MEMBERS" | "PREMIUM_GUILD_SUBSCRIPTIONS_GOAL" | "PREMIUM_GUILD_TIER_3_SHORT" | "PREMIUM_GUILD_SUBSCRIPTIONS_PROGRESS_BAR_BLURB" | "PREMIUM_GUILD_SUBSCRIPTIONS_PROGRESS_BAR_COMPLETED_BLURB" | "PREMIUM_GUILD_SUBSCRIPTIONS_NUDGE_TOOLTIP_COMPLETE" | "PREMIUM_GUILD_SUBSCRIPTIONS_PROGRESS_BAR_TADA_ICON_ALT_TEXT" | "GUILD_EVENTS" | "GUILD_SIDEBAR_DEFAULT_CHANNEL_A11Y_LABEL" | "CHANNEL_TOOLTIP_TEXT_LIMITED" | "CREATE_INSTANT_INVITE" | "EDIT_CHANNEL" | "CHANNEL_TOOLTIP_TEXT" | "CATEGORY_A11Y_LABEL" | "CREATE_CHANNEL" | "CHANNEL_TOOLTIP_RULES" | "GUILD_SIDEBAR_ANNOUNCEMENT_CHANNEL_A11Y_LABEL" | "CHANNEL_TOOLTIP_ANNOUNCEMENTS" | "GUILD_SIDEBAR_STAGE_CHANNEL_A11Y_LABEL" | "OPEN_CHAT" | "CHANNEL_TOOLTIP_STAGE_LIMITED" | "CHANNEL_TOOLTIP_TEXT_ACTIVE_THREADS" | "THREAD_GROUP_A11Y_LABEL" | "GUILD_SIDEBAR_THREAD_A11Y_LABEL" | "GUILD_SIDEBAR_VOICE_CHANNEL_A11Y_LABEL" | "GUILD_SIDEBAR_CHANNEL_A11Y_LABEL_UNREAD" | "GUILD_SIDEBAR_VOICE_CHANNEL_A11Y_LABEL_USERS" | "CHANNEL_TOOLTIP_VOICE" | "STATUS_UNKNOWN" | "MESSAGE_A11Y_ROLE_DESCRIPTION" | "ROLE_ICON_ALT_TEXT" | "CHANNEL_MESSAGE_REPLY_A11Y_LABEL" | "IMAGE" | "MESSAGE_EDITED" | "MESSAGE_EDITED_TIMESTAMP_A11Y_LABEL" | "EMOJI_TOOLTIP_CLICK_CTA" | "REMOVE_MESSAGE_ATTACHMENT" | "VERIFIED_BOT_TOOLTIP" | "SUPPRESS_ALL_EMBEDS" | "CHANNEL_MEMBERS_A11Y_LABEL" | "GUILD_OWNER" | "PREMIUM_GUILD_SUBSCRIPTION_TOOLTIP" | "STATUS_ONLINE_MOBILE" | "STATUS_IDLE" | "STREAMING" | "LISTENING_TO" | "WATCHING" | "COMPETING" | "PLAYING_GAME" | "STATUS_DND" | "CHAT_ATTACH_INVITE_TO_LISTEN" | "ACTIVITY_PANEL_GO_LIVE_STREAM_GAME" | "SEARCH_ANSWER_HAS_LINK" | "SEARCH_ANSWER_HAS_EMBED" | "SEARCH_ANSWER_HAS_ATTACHMENT" | "SEARCH_ANSWER_HAS_VIDEO" | "SEARCH_ANSWER_HAS_IMAGE" | "SEARCH_ANSWER_HAS_SOUND" | "SEARCH_ANSWER_HAS_STICKER" | "SEARCH_FILTER_FROM" | "SEARCH_FILTER_MENTIONS" | "SEARCH_FILTER_HAS" | "SEARCH_FILTER_FILE_TYPE" | "SEARCH_FILTER_FILE_NAME" | "SEARCH_FILTER_BEFORE" | "SEARCH_FILTER_ON" | "SEARCH_FILTER_DURING" | "SEARCH_FILTER_AFTER" | "SEARCH_FILTER_IN" | "SEARCH_FILTER_PINNED" | "MESSAGE_UTILITIES_A11Y_LABEL" | "EDIT" | "MORE" | "SEARCH_SHORTCUT_TODAY" | "SEARCH_SHORTCUT_YESTERDAY" | "SEARCH_SHORTCUT_WEEK" | "SEARCH_SHORTCUT_MONTH" | "SEARCH_SHORTCUT_YEAR" | "SEARCH_GROUP_HEADER_SEARCH_OPTIONS" | "SEARCH_GROUP_HEADER_HISTORY" | "LEARN_MORE" | "SEARCH_ANSWER_FROM" | "SEARCH_ANSWER_MENTIONS" | "SEARCH_ANSWER_HAS" | "SEARCH_ANSWER_DATE" | "SEARCH_ANSWER_IN" | "SEARCH_ANSWER_BOOLEAN" | "SEARCH_CLEAR_HISTORY" | "SEARCH_FROM_SUGGESTIONS" | "MEMBER_LIST_HIDDEN" | "SEARCH_RESULTS_SECTION_LABEL" | "SEARCH_NEWEST_SHORT" | "SEARCH_OLDEST_SHORT" | "SEARCH_MOST_RELEVANT_SHORT" | "SEARCHING" | "TOTAL_RESULTS" | "JUMP" | "REPLY_QUOTE_MESSAGE_NOT_LOADED" | "COPY_MESSAGE_LINK" | "COPY_ID" | "MESSAGE_ACTIONS_MENU_LABEL" | "ACTIVE_THREADS_POPOUT_HEADER" | "ACTIVE_THREADS_POPOUT_LINK" | "THREAD_BROWSER_TIMESTAMP_MINUTES" | "THREAD_BROWSER_TIMESTAMP_HOURS" | "THREAD_BROWSER_TIMESTAMP_DAYS" | "THREAD_BROWSER_TIMESTAMP_MORE_THAN_MONTH" | "OPEN_CHANNEL_TOPIC" | "VIDEO" | "REPLY_QUOTE_NO_TEXT_CONTENT" | "PLAY" | "NEW_MEMBER_BADGE_TOOLTIP_TEXT" | "USER_SETTINGS_MY_ACCOUNT" | "USER_SETTINGS_PROFILES" | "PRIVACY_AND_SAFETY" | "AUTHORIZED_APPS" | "AUTH_SESSIONS" | "CONNECTIONS" | "CLIPS" | "FRIEND_REQUESTS" | "BILLING_SETTINGS" | "PREMIUM" | "PREMIUM_GUILD_SUBSCRIPTION_TITLE" | "SUBSCRIPTIONS_TITLE" | "GIFT_INVENTORY" | "BILLING" | "APP_SETTINGS" | "APPEARANCE" | "ACCESSIBILITY" | "VOICE_AND_VIDEO" | "POGGERMODE" | "TEXT_AND_IMAGES" | "NOTIFICATIONS" | "KEYBINDS" | "LANGUAGE" | "USER_SETTINGS_WINDOWS_SETTINGS" | "USER_SETTINGS_LINUX_SETTINGS" | "STREAMER_MODE" | "SETTINGS_ADVANCED" | "ACTIVITY_SETTINGS" | "ACTIVITY_PRIVACY" | "REGISTERED_GAMES" | "OVERLAY" | "WHATS_NEW" | "USER_SETTINGS_HYPESQUAD" | "LOGOUT" | "BETA" | "USER_SETTINGS_ACCOUNT_PASSWORD_AND_AUTHENTICATION" | "CHANGE_PASSWORD" | "USER_SETTINGS_EDIT_USER_PROFILE" | "ACTIONS" | "HYPESQUAD_ONLINE_BADGE_TOOLTIP" | "HYPESQUAD_HOUSE_1" | "ACTIVE_DEVELOPER_BADGE_TOOLTIP" | "PROFILE_USER_BADGES" | "USER_SETTINGS_LABEL_USERNAME" | "USER_SETTINGS_ACCOUNT_EDIT_USERNAME_A11Y_LABEL" | "USER_SETTINGS_ACCOUNT_EDIT_EMAIL_A11Y_LABEL" | "USER_SETTINGS_ACCOUNT_REVEAL_EMAIL_A11Y_LABEL" | "USER_SETTINGS_ACCOUNT_HIDE_EMAIL_A11Y_LABEL" | "USER_SETTINGS_LABEL_EMAIL" | "REVEAL" | "USER_SETTINGS_ACCOUNT_REVEAL_PHONE_A11Y_LABEL" | "USER_SETTINGS_ACCOUNT_HIDE_PHONE_A11Y_LABEL" | "USER_SETTINGS_LABEL_PHONE_NUMBER" | "USER_SETTINGS_ACCOUNT_REMOVE_PHONE_A11Y_LABEL" | "REMOVE" | "USER_SETTINGS_ACCOUNT_EDIT_PHONE_A11Y_LABEL" | "TWO_FA_VIEW_BACKUP_CODES" | "TWO_FA_ENABLED" | "TWO_FA_DESCRIPTION" | "TWO_FA_DISABLED_FOR_SERVER_SUBSCRIPTION_MOD" | "MFA_SMS_AUTH_CURRENT_PHONE" | "MFA_SMS_PHONE_NUMBER_REVEAL" | "MFA_SMS_ENABLE" | "CHANGE_PHONE_NUMBER" | "MFA_SMS_AUTH" | "MFA_SMS_AUTH_SALES_PITCH" | "TWO_FA_REMOVE" | "USER_SETTINGS_ACCOUNT_REMOVAL_SECTION" | "USER_SETTINGS_ACCOUNT_REMOVAL_DESCRIPTION" | "DISABLE_ACCOUNT" | "DELETE_ACCOUNT" | "CLOSE" | "PREMIUM_BADGE_TOOLTIP" | "SELECT" | "REPLYING_TO" | "SUPER_REACTION_NITRO_TOOLTIP" | "YOURE_VIEWING_OLDER_MESSAGES" | "JUMP_TO_PRESENT" | "REACT_WITH_COUNT_A11Y_LABEL" | "SEARCH_NO_RESULTS" | "GUILD_SIDEBAR_CHANNEL_A11Y_LABEL_LIMIT" | "COPY_LINK" | "DELETE" | "GUILD_SIDEBAR_DEFAULT_CHANNEL_A11Y_LABEL_WITH_MENTIONS" | "NEW_MESSAGES" | "NEW_MESSAGES_PILL" | "JUMP_TO_LAST_UNREAD_MESSAGE" | "MARK_AS_READ", - string ->; diff --git a/src/webpack/common/types/index.d.ts b/src/webpack/common/types/index.d.ts index a536cdcf..77148dd0 100644 --- a/src/webpack/common/types/index.d.ts +++ b/src/webpack/common/types/index.d.ts @@ -19,7 +19,6 @@ export * from "./classes"; export * from "./components"; export * from "./fluxEvents"; -export * from "./i18nMessages"; export * from "./menu"; export * from "./stores"; export * from "./utils"; diff --git a/src/webpack/common/types/utils.d.ts b/src/webpack/common/types/utils.d.ts index c0a93004..00e3f4a0 100644 --- a/src/webpack/common/types/utils.d.ts +++ b/src/webpack/common/types/utils.d.ts @@ -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 }; @@ -148,19 +147,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; - - Messages: Record; -} - export interface Clipboard { copy(text: string): void; SUPPORTS_COPY: boolean; diff --git a/src/webpack/common/utils.ts b/src/webpack/common/utils.ts index 2bce1db7..3f44d106 100644 --- a/src/webpack/common/utils.ts +++ b/src/webpack/common/utils.ts @@ -16,6 +16,7 @@ * along with this program. If not, see . */ +import { runtimeHashMessageKey } from "@utils/intlHash"; import type { Channel } from "discord-types/general"; // eslint-disable-next-line path-alias/no-relative @@ -56,7 +57,10 @@ export const { match, P }: Pick = 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); From 80ae0603577599b99dc80c7683854e2e872bf142 Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Sun, 3 Nov 2024 15:07:46 -0300 Subject: [PATCH 04/12] Fix i18n usage --- src/components/Icons.tsx | 5 ++--- src/debug/loadLazyChunks.ts | 4 +--- src/plugins/betterFolders/index.tsx | 5 +++-- src/plugins/betterSettings/PluginsSubmenu.tsx | 5 +++-- src/plugins/betterSettings/index.tsx | 5 +++-- .../decor/ui/components/DecorationGridCreate.tsx | 5 +++-- .../decor/ui/components/DecorationGridNone.tsx | 5 +++-- src/plugins/fullSearchContext/index.tsx | 7 ++++--- src/plugins/messageLogger/index.tsx | 5 +++-- src/plugins/pauseInvitesForever/index.tsx | 5 +++-- .../components/RolesAndUsersPermissions.tsx | 10 +++++----- .../components/UserPermissions.tsx | 5 +++-- src/plugins/permissionsViewer/utils.ts | 7 ++++--- src/plugins/showConnections/VerifiedIcon.tsx | 5 +++-- src/plugins/showTimeoutDuration/index.tsx | 10 ++++++++-- src/plugins/typingIndicator/index.tsx | 13 ++++++++----- .../userMessagesPronouns/PronounsChatComponent.tsx | 5 +++-- src/plugins/userVoiceShow/index.tsx | 2 +- src/plugins/viewRaw/index.tsx | 5 +++-- src/utils/discord.tsx | 4 ++-- 20 files changed, 68 insertions(+), 49 deletions(-) diff --git a/src/components/Icons.tsx b/src/components/Icons.tsx index fa142a18..d0d2ecbe 100644 --- a/src/components/Icons.tsx +++ b/src/components/Icons.tsx @@ -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 ( (); - // 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])) : []; diff --git a/src/plugins/betterFolders/index.tsx b/src/plugins/betterFolders/index.tsx index 3af5af66..3d04419d 100644 --- a/src/plugins/betterFolders/index.tsx +++ b/src/plugins/betterFolders/index.tsx @@ -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"; @@ -276,7 +277,7 @@ export default definePlugin({ makeGuildsBarGuildListFilter(isBetterFolders: boolean) { return child => { if (isBetterFolders) { - return child?.props?.["aria-label"] === i18n.Messages.SERVERS; + return child?.props?.["aria-label"] === getIntlMessage("SERVERS"); } return true; }; diff --git a/src/plugins/betterSettings/PluginsSubmenu.tsx b/src/plugins/betterSettings/PluginsSubmenu.tsx index b22f82a6..ad7ded30 100644 --- a/src/plugins/betterSettings/PluginsSubmenu.tsx +++ b/src/plugins/betterSettings/PluginsSubmenu.tsx @@ -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")} /> )} /> diff --git a/src/plugins/betterSettings/index.tsx b/src/plugins/betterSettings/index.tsx index 15618faf..2cee8569 100644 --- a/src/plugins/betterSettings/index.tsx +++ b/src/plugins/betterSettings/index.tsx @@ -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"; @@ -159,7 +160,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); } diff --git a/src/plugins/decor/ui/components/DecorationGridCreate.tsx b/src/plugins/decor/ui/components/DecorationGridCreate.tsx index 7699b23d..09572041 100644 --- a/src/plugins/decor/ui/components/DecorationGridCreate.tsx +++ b/src/plugins/decor/ui/components/DecorationGridCreate.tsx @@ -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")} ; } diff --git a/src/plugins/decor/ui/components/DecorationGridNone.tsx b/src/plugins/decor/ui/components/DecorationGridNone.tsx index b6114c67..81ebde0b 100644 --- a/src/plugins/decor/ui/components/DecorationGridNone.tsx +++ b/src/plugins/decor/ui/components/DecorationGridNone.tsx @@ -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")} ; } diff --git a/src/plugins/fullSearchContext/index.tsx b/src/plugins/fullSearchContext/index.tsx index 193e69f1..3f9e8210 100644 --- a/src/plugins/fullSearchContext/index.tsx +++ b/src/plugins/fullSearchContext/index.tsx @@ -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") }) ); }; diff --git a/src/plugins/messageLogger/index.tsx b/src/plugins/messageLogger/index.tsx index 080be776..3ee9f3fa 100644 --- a/src/plugins/messageLogger/index.tsx +++ b/src/plugins/messageLogger/index.tsx @@ -24,12 +24,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"; @@ -178,7 +179,7 @@ export default definePlugin({ isEdited={true} isInline={false} > - {" "}({i18n.Messages.MESSAGE_EDITED}) + {" "}({getIntlMessage("MESSAGE_EDITED")}) ))} diff --git a/src/plugins/pauseInvitesForever/index.tsx b/src/plugins/pauseInvitesForever/index.tsx index ff292a6d..23b188bc 100644 --- a/src/plugins/pauseInvitesForever/index.tsx +++ b/src/plugins/pauseInvitesForever/index.tsx @@ -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 (
- {i18n.Messages.GUILD_INVITE_DISABLE_ACTION_SHEET_DESCRIPTION} + {getIntlMessage("GUILD_INVITE_DISABLE_ACTION_SHEET_DESCRIPTION")} {showDisableInvites(guildId) && { setChecked(true); disableInvites(guildId); diff --git a/src/plugins/permissionsViewer/components/RolesAndUsersPermissions.tsx b/src/plugins/permissionsViewer/components/RolesAndUsersPermissions.tsx index 82925d61..32dcaf8d 100644 --- a/src/plugins/permissionsViewer/components/RolesAndUsersPermissions.tsx +++ b/src/plugins/permissionsViewer/components/RolesAndUsersPermissions.tsx @@ -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 > { Clipboard.copy(roleId); }} @@ -225,7 +225,7 @@ function RoleContextMenu({ guild, roleId, onClose }: { guild: Guild; roleId: str {(settings.store as any).unsafeViewAsRole && ( { const role = GuildStore.getRole(guild.id, roleId); if (!role) return; @@ -257,7 +257,7 @@ function UserContextMenu({ userId }: { userId: string; }) { > { Clipboard.copy(userId); }} diff --git a/src/plugins/permissionsViewer/components/UserPermissions.tsx b/src/plugins/permissionsViewer/components/UserPermissions.tsx index 7c0858f1..720445da 100644 --- a/src/plugins/permissionsViewer/components/UserPermissions.tsx +++ b/src/plugins/permissionsViewer/components/UserPermissions.tsx @@ -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", diff --git a/src/plugins/permissionsViewer/utils.ts b/src/plugins/permissionsViewer/utils.ts index ac753797..b2015840 100644 --- a/src/plugins/permissionsViewer/utils.ts +++ b/src/plugins/permissionsViewer/utils.ts @@ -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); diff --git a/src/plugins/showConnections/VerifiedIcon.tsx b/src/plugins/showConnections/VerifiedIcon.tsx index d4d3f094..d748f326 100644 --- a/src/plugins/showConnections/VerifiedIcon.tsx +++ b/src/plugins/showConnections/VerifiedIcon.tsx @@ -16,8 +16,9 @@ * along with this program. If not, see . */ +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("#{intl::CONNECTIONS_ROLE_OFFICIAL_ICON_TOOLTIP}"); @@ -31,7 +32,7 @@ export function VerifiedIcon() { color={color} forcedIconColor={forcedIconColor} size={16} - tooltipText={i18n.Messages.CONNECTION_VERIFIED} + tooltipText={getIntlMessage("CONNECTION_VERIFIED")} /> ); } diff --git a/src/plugins/showTimeoutDuration/index.tsx b/src/plugins/showTimeoutDuration/index.tsx index 6f00f4c7..fa2ef431 100644 --- a/src/plugins/showTimeoutDuration/index.tsx +++ b/src/plugins/showTimeoutDuration/index.tsx @@ -9,10 +9,11 @@ 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"; @@ -50,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 }); diff --git a/src/plugins/typingIndicator/index.tsx b/src/plugins/typingIndicator/index.tsx index 6df3f4b8..b58d1db7 100644 --- a/src/plugins/typingIndicator/index.tsx +++ b/src/plugins/typingIndicator/index.tsx @@ -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"; @@ -72,24 +73,26 @@ function TypingIndicator({ channelId }: { channelId: string; }) { const typingUsersArray = Object.keys(typingUsers).filter(id => id !== myId && !(RelationshipStore.isBlocked(id) && !settings.store.includeBlockedUsers)); let tooltipText: string; + // the new syntax is getIntlMessage("ONE_USER_TYPING", { a: getDisplayName(guildId, typingUsersArray[0]) }); + 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; } } diff --git a/src/plugins/userMessagesPronouns/PronounsChatComponent.tsx b/src/plugins/userMessagesPronouns/PronounsChatComponent.tsx index c2d7be2e..c2a54f14 100644 --- a/src/plugins/userMessagesPronouns/PronounsChatComponent.tsx +++ b/src/plugins/userMessagesPronouns/PronounsChatComponent.tsx @@ -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 && ( - + {tooltipProps => ( settings.store.showVoiceChannelIndicator diff --git a/src/plugins/viewRaw/index.tsx b/src/plugins/viewRaw/index.tsx index 83c560df..0134ea3e 100644 --- a/src/plugins/viewRaw/index.tsx +++ b/src/plugins/viewRaw/index.tsx @@ -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") { diff --git a/src/utils/discord.tsx b/src/utils/discord.tsx index c79bbc39..ccdb2fb9 100644 --- a/src/utils/discord.tsx +++ b/src/utils/discord.tsx @@ -31,7 +31,7 @@ import { MediaModalItem, MediaModalProps, openMediaModal } from "./modal"; * @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): string { +export function getIntlMessage(key: string, values?: Record): any { return getIntlMessageFromHash(runtimeHashMessageKey(key), values); } @@ -40,7 +40,7 @@ export function getIntlMessage(key: string, values?: Record): * @param key The hashed message key * @param values The values to interpolate, if it's a rich message */ -export function getIntlMessageFromHash(key: string, values?: Record): string { +export function getIntlMessageFromHash(key: string, values?: Record): any { return values == null ? i18n.intl.string(i18n.t[key]) : i18n.intl.format(i18n.t[key], values); } From a514122489367007ae481fd54b409d1e3b0968fe Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Sun, 3 Nov 2024 15:28:28 -0300 Subject: [PATCH 05/12] Fix rest of patches --- src/plugins/consoleShortcuts/index.ts | 2 ++ src/plugins/implicitRelationships/index.ts | 2 +- src/plugins/moreUserTags/index.tsx | 19 ++++++++++--------- src/plugins/typingTweaks/index.tsx | 4 ++-- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/plugins/consoleShortcuts/index.ts b/src/plugins/consoleShortcuts/index.ts index 2fdf8735..f10335e3 100644 --- a/src/plugins/consoleShortcuts/index.ts +++ b/src/plugins/consoleShortcuts/index.ts @@ -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 diff --git a/src/plugins/implicitRelationships/index.ts b/src/plugins/implicitRelationships/index.ts index 868e1355..8960bc13 100644 --- a/src/plugins/implicitRelationships/index.ts +++ b/src/plugins/implicitRelationships/index.ts @@ -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\"}),$&" }, }, diff --git a/src/plugins/moreUserTags/index.tsx b/src/plugins/moreUserTags/index.tsx index c6695d31..043c6063 100644 --- a/src/plugins/moreUserTags/index.tsx +++ b/src/plugins/moreUserTags/index.tsx @@ -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) => + `${origSwitch}default:{${displayedText} = $self.getTagText(${tags}[${variant}])}` }, // show OP tags correctly { @@ -295,19 +296,19 @@ 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) { - if (!passedTagName) return strings.APP_TAG; + getTagText(passedTagName: string) { + if (!passedTagName) return getIntlMessage("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; + 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}`; + return `${getIntlMessage("BOT_TAG_FORUM_ORIGINAL_POSTER")} • ${tagText}`; case "BOT": - return `${strings.APP_TAG} • ${tagText}`; + return `${getIntlMessage("APP_TAG")} • ${tagText}`; default: return tagText; } diff --git a/src/plugins/typingTweaks/index.tsx b/src/plugins/typingTweaks/index.tsx index d3f4a140..4fb3c775 100644 --- a/src/plugins/typingTweaks/index.tsx +++ b/src/plugins/typingTweaks/index.tsx @@ -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 } From e038c100422b102dfa396b4abf3220838804ce69 Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Sun, 3 Nov 2024 15:31:47 -0300 Subject: [PATCH 06/12] remove trailing newline --- src/utils/intlHash.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/utils/intlHash.ts b/src/utils/intlHash.ts index 069f8f80..e6b77d09 100644 --- a/src/utils/intlHash.ts +++ b/src/utils/intlHash.ts @@ -8,7 +8,6 @@ * @license MIT */ - import { hash as h64 } from "@intrnl/xxhash64"; const BASE64_TABLE = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split(""); From 17926c9aaccd45391a2b350bd939712c630054f6 Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Sun, 3 Nov 2024 15:33:27 -0300 Subject: [PATCH 07/12] annoying error --- src/plugins/implicitRelationships/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/implicitRelationships/index.ts b/src/plugins/implicitRelationships/index.ts index 8960bc13..1f7dbe70 100644 --- a/src/plugins/implicitRelationships/index.ts +++ b/src/plugins/implicitRelationships/index.ts @@ -117,7 +117,7 @@ export default definePlugin({ wrapSort(comparator: Function, row: any) { return row.type === 5 - ? -UserAffinitiesStore.getUserAffinity(row.user.id)?.affinity ?? 0 + ? -(UserAffinitiesStore.getUserAffinity(row.user.id)?.affinity ?? 0) : comparator(row); }, From 321ec844a5bde8b8e1e42e461e0ed18de6cf2f8d Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Sun, 3 Nov 2024 15:38:30 -0300 Subject: [PATCH 08/12] it is hiding from me --- src/plugins/betterRoleDot/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/betterRoleDot/index.ts b/src/plugins/betterRoleDot/index.ts index a8cadd8b..3a8a1456 100644 --- a/src/plugins/betterRoleDot/index.ts +++ b/src/plugins/betterRoleDot/index.ts @@ -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, From 4cf5b58f9bee080ab4b3d2eacf5520f22d3257cc Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Sun, 3 Nov 2024 16:04:30 -0300 Subject: [PATCH 09/12] re-add try catch --- src/plugins/_core/settings.tsx | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/plugins/_core/settings.tsx b/src/plugins/_core/settings.tsx index 3069c69b..a94e8cfa 100644 --- a/src/plugins/_core/settings.tsx +++ b/src/plugins/_core/settings.tsx @@ -149,13 +149,18 @@ export default definePlugin({ if (!header) return; - const names = { - top: getIntlMessage("USER_SETTINGS"), - aboveNitro: getIntlMessage("BILLING_SETTINGS"), - belowNitro: getIntlMessage("APP_SETTINGS"), - aboveActivity: getIntlMessage("ACTIVITY_SETTINGS") - }; - return header === names[settingsLocation]; + try { + const names = { + top: getIntlMessage("USER_SETTINGS"), + aboveNitro: getIntlMessage("BILLING_SETTINGS"), + belowNitro: getIntlMessage("APP_SETTINGS"), + aboveActivity: getIntlMessage("ACTIVITY_SETTINGS") + }; + + return header === names[settingsLocation]; + } catch { + return firstChild === "PREMIUM"; + } }, patchedSettings: new WeakSet(), From e4aba774e0f930c595fd3da484a1f59bc60f50c4 Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Sun, 3 Nov 2024 16:18:33 -0300 Subject: [PATCH 10/12] try catch getIntlMessageFromHash --- src/plugins/betterFolders/index.tsx | 14 ++++++---- src/plugins/moreUserTags/index.tsx | 38 +++++++++++++++------------ src/plugins/typingIndicator/index.tsx | 2 -- src/utils/discord.tsx | 16 ++++++++--- 4 files changed, 42 insertions(+), 28 deletions(-) diff --git a/src/plugins/betterFolders/index.tsx b/src/plugins/betterFolders/index.tsx index 3d04419d..50dee4f5 100644 --- a/src/plugins/betterFolders/index.tsx +++ b/src/plugins/betterFolders/index.tsx @@ -275,12 +275,16 @@ export default definePlugin({ }, makeGuildsBarGuildListFilter(isBetterFolders: boolean) { - return child => { - if (isBetterFolders) { - return child?.props?.["aria-label"] === getIntlMessage("SERVERS"); - } + try { + return child => { + if (isBetterFolders) { + return child?.props?.["aria-label"] === getIntlMessage("SERVERS"); + } + return true; + }; + } catch { return true; - }; + } }, makeGuildsBarTreeFilter(isBetterFolders: boolean) { diff --git a/src/plugins/moreUserTags/index.tsx b/src/plugins/moreUserTags/index.tsx index 043c6063..db071e72 100644 --- a/src/plugins/moreUserTags/index.tsx +++ b/src/plugins/moreUserTags/index.tsx @@ -192,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}#{intl::APP_TAG}"\]\)/, - replace: (_, origSwitch, variant, tags, displayedText) => - `${origSwitch}default:{${displayedText} = $self.getTagText(${tags}[${variant}])}` + 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 { @@ -296,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) { - if (!passedTagName) return getIntlMessage("APP_TAG"); - const [tagName, variant] = passedTagName.split("-"); - 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"); + 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 `${getIntlMessage("BOT_TAG_FORUM_ORIGINAL_POSTER")} • ${tagText}`; - case "BOT": - return `${getIntlMessage("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; } }, diff --git a/src/plugins/typingIndicator/index.tsx b/src/plugins/typingIndicator/index.tsx index b58d1db7..e23cf49d 100644 --- a/src/plugins/typingIndicator/index.tsx +++ b/src/plugins/typingIndicator/index.tsx @@ -73,8 +73,6 @@ function TypingIndicator({ channelId }: { channelId: string; }) { const typingUsersArray = Object.keys(typingUsers).filter(id => id !== myId && !(RelationshipStore.isBlocked(id) && !settings.store.includeBlockedUsers)); let tooltipText: string; - // the new syntax is getIntlMessage("ONE_USER_TYPING", { a: getDisplayName(guildId, typingUsersArray[0]) }); - switch (typingUsersArray.length) { case 0: break; case 1: { diff --git a/src/utils/discord.tsx b/src/utils/discord.tsx index ccdb2fb9..91fd791b 100644 --- a/src/utils/discord.tsx +++ b/src/utils/discord.tsx @@ -24,24 +24,32 @@ 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): any { - return getIntlMessageFromHash(runtimeHashMessageKey(key), values); + return getIntlMessageFromHash(runtimeHashMessageKey(key), values, key); } /** * Get an internationalized message from a hashed key - * @param key The hashed message key + * @param hashedKey The hashed message key * @param values The values to interpolate, if it's a rich message */ -export function getIntlMessageFromHash(key: string, values?: Record): any { - return values == null ? i18n.intl.string(i18n.t[key]) : i18n.intl.format(i18n.t[key], values); +export function getIntlMessageFromHash(hashedKey: string, values?: Record, 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 ?? ""; + } } /** From 39de683b6eabbc9217ea2b7b77e44d5b952d7f60 Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Sun, 3 Nov 2024 16:23:30 -0300 Subject: [PATCH 11/12] better intl transforming --- src/plugins/_api/serverList.ts | 4 ++-- src/plugins/_core/supportHelper.tsx | 2 +- src/plugins/decor/index.tsx | 2 +- src/plugins/fakeProfileThemes/index.tsx | 2 +- src/plugins/implicitRelationships/index.ts | 2 +- src/plugins/moreUserTags/index.tsx | 2 +- src/plugins/validReply/index.ts | 2 +- src/utils/patches.ts | 6 +++--- 8 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/plugins/_api/serverList.ts b/src/plugins/_api/serverList.ts index 15a1389f..dfd40de7 100644 --- a/src/plugins/_api/serverList.ts +++ b/src/plugins/_api/serverList.ts @@ -32,9 +32,9 @@ export default definePlugin({ } }, { - find: '#{intl::SERVERS}"]),children', + find: "#{intl::SERVERS}),children", replacement: { - match: /(?<=#{intl::SERVERS}"\]\),children:)\i\.map\(\i\)/, + match: /(?<=#{intl::SERVERS}\),children:)\i\.map\(\i\)/, replace: "Vencord.Api.ServerList.renderAll(Vencord.Api.ServerList.ServerListRenderPosition.In).concat($&)" } } diff --git a/src/plugins/_core/supportHelper.tsx b/src/plugins/_core/supportHelper.tsx index 6be41d31..1b9ce162 100644 --- a/src/plugins/_core/supportHelper.tsx +++ b/src/plugins/_core/supportHelper.tsx @@ -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 })," } }], diff --git a/src/plugins/decor/index.tsx b/src/plugins/decor/index.tsx index 47207922..69a7a1a5 100644 --- a/src/plugins/decor/index.tsx +++ b/src/plugins/decor/index.tsx @@ -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()," } }, diff --git a/src/plugins/fakeProfileThemes/index.tsx b/src/plugins/fakeProfileThemes/index.tsx index 495d2ddc..bfd1cb99 100644 --- a/src/plugins/fakeProfileThemes/index.tsx +++ b/src/plugins/fakeProfileThemes/index.tsx @@ -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})" } } diff --git a/src/plugins/implicitRelationships/index.ts b/src/plugins/implicitRelationships/index.ts index 1f7dbe70..1cde814e 100644 --- a/src/plugins/implicitRelationships/index.ts +++ b/src/plugins/implicitRelationships/index.ts @@ -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\.string\(\i\.\i#{intl::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\"}),$&" }, }, diff --git a/src/plugins/moreUserTags/index.tsx b/src/plugins/moreUserTags/index.tsx index db071e72..6c9102d8 100644 --- a/src/plugins/moreUserTags/index.tsx +++ b/src/plugins/moreUserTags/index.tsx @@ -192,7 +192,7 @@ export default definePlugin({ replacement: [ // make the tag show the right text { - match: /(switch\((\i)\){.+?)case (\i(?:\.\i)?)\.BOT:default:(\i)=(.{0,40}#{intl::APP_TAG}"\]\))/, + 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})}` }, diff --git a/src/plugins/validReply/index.ts b/src/plugins/validReply/index.ts index 4b62f790..989513d0 100644 --- a/src/plugins/validReply/index.ts +++ b/src/plugins/validReply/index.ts @@ -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])" } }, diff --git a/src/utils/patches.ts b/src/utils/patches.ts index 17c541b6..e903b226 100644 --- a/src/utils/patches.ts +++ b/src/utils/patches.ts @@ -25,12 +25,12 @@ export function canonicalizeMatch(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("+"); if (hasSpecialChars) { return isString - ? `["${hashed}` - : String.raw`(?:\["${hashed})`.replaceAll("+", "\\+"); + ? `["${hashed}"]` + : String.raw`(?:\["${hashed}"\])`.replaceAll("+", "\\+"); } return isString ? `.${hashed}` : String.raw`(?:\.${hashed})`; From b2dc81d144592f5f2a572ff7eb299dd8efb4dc11 Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Sun, 3 Nov 2024 16:25:59 -0300 Subject: [PATCH 12/12] fix --- src/utils/patches.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/patches.ts b/src/utils/patches.ts index e903b226..3812acd9 100644 --- a/src/utils/patches.ts +++ b/src/utils/patches.ts @@ -25,7 +25,7 @@ export function canonicalizeMatch(match: T): T { const hashed = runtimeHashMessageKey(key); const isString = typeof match === "string"; - const hasSpecialChars = !Number.isNaN(Number(hashed[0])) || hashed.includes("+"); + const hasSpecialChars = !Number.isNaN(Number(hashed[0])) || hashed.includes("+") || hashed.includes("/"); if (hasSpecialChars) { return isString