mirror of
https://github.com/Equicord/Equicord.git
synced 2025-06-14 17:13:03 -04:00
try catch getIntlMessageFromHash
This commit is contained in:
parent
4cf5b58f9b
commit
e4aba774e0
4 changed files with 42 additions and 28 deletions
|
@ -275,12 +275,16 @@ export default definePlugin({
|
||||||
},
|
},
|
||||||
|
|
||||||
makeGuildsBarGuildListFilter(isBetterFolders: boolean) {
|
makeGuildsBarGuildListFilter(isBetterFolders: boolean) {
|
||||||
|
try {
|
||||||
return child => {
|
return child => {
|
||||||
if (isBetterFolders) {
|
if (isBetterFolders) {
|
||||||
return child?.props?.["aria-label"] === getIntlMessage("SERVERS");
|
return child?.props?.["aria-label"] === getIntlMessage("SERVERS");
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
} catch {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
makeGuildsBarTreeFilter(isBetterFolders: boolean) {
|
makeGuildsBarTreeFilter(isBetterFolders: boolean) {
|
||||||
|
|
|
@ -192,9 +192,9 @@ export default definePlugin({
|
||||||
replacement: [
|
replacement: [
|
||||||
// make the tag show the right text
|
// 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) =>
|
replace: (_, origSwitch, variant, tags, displayedText, originalText) =>
|
||||||
`${origSwitch}default:{${displayedText} = $self.getTagText(${tags}[${variant}])}`
|
`${origSwitch}default:{${displayedText} = $self.getTagText(${tags}[${variant}],${originalText})}`
|
||||||
},
|
},
|
||||||
// show OP tags correctly
|
// show OP tags correctly
|
||||||
{
|
{
|
||||||
|
@ -296,9 +296,10 @@ export default definePlugin({
|
||||||
|
|
||||||
isOPTag: (tag: number) => tag === Tag.Types.ORIGINAL_POSTER || tags.some(t => tag === Tag.Types[`${t.name}-OP`]),
|
isOPTag: (tag: number) => tag === Tag.Types.ORIGINAL_POSTER || tags.some(t => tag === Tag.Types[`${t.name}-OP`]),
|
||||||
|
|
||||||
getTagText(passedTagName: string) {
|
getTagText(passedTagName: string, originalText: string) {
|
||||||
if (!passedTagName) return getIntlMessage("APP_TAG");
|
try {
|
||||||
const [tagName, variant] = passedTagName.split("-");
|
const [tagName, variant] = passedTagName.split("-");
|
||||||
|
if (!passedTagName) return getIntlMessage("APP_TAG");
|
||||||
const tag = tags.find(({ name }) => tagName === name);
|
const tag = tags.find(({ name }) => tagName === name);
|
||||||
if (!tag) return getIntlMessage("APP_TAG");
|
if (!tag) return getIntlMessage("APP_TAG");
|
||||||
if (variant === "BOT" && tagName !== "WEBHOOK" && this.settings.store.dontShowForBots) return getIntlMessage("APP_TAG");
|
if (variant === "BOT" && tagName !== "WEBHOOK" && this.settings.store.dontShowForBots) return getIntlMessage("APP_TAG");
|
||||||
|
@ -312,6 +313,9 @@ export default definePlugin({
|
||||||
default:
|
default:
|
||||||
return tagText;
|
return tagText;
|
||||||
}
|
}
|
||||||
|
} catch {
|
||||||
|
return originalText;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
getTag({
|
getTag({
|
||||||
|
|
|
@ -73,8 +73,6 @@ function TypingIndicator({ channelId }: { channelId: string; }) {
|
||||||
const typingUsersArray = Object.keys(typingUsers).filter(id => id !== myId && !(RelationshipStore.isBlocked(id) && !settings.store.includeBlockedUsers));
|
const typingUsersArray = Object.keys(typingUsers).filter(id => id !== myId && !(RelationshipStore.isBlocked(id) && !settings.store.includeBlockedUsers));
|
||||||
let tooltipText: string;
|
let tooltipText: string;
|
||||||
|
|
||||||
// the new syntax is getIntlMessage("ONE_USER_TYPING", { a: getDisplayName(guildId, typingUsersArray[0]) });
|
|
||||||
|
|
||||||
switch (typingUsersArray.length) {
|
switch (typingUsersArray.length) {
|
||||||
case 0: break;
|
case 0: break;
|
||||||
case 1: {
|
case 1: {
|
||||||
|
|
|
@ -24,24 +24,32 @@ import { Channel, Guild, Message, User } from "discord-types/general";
|
||||||
import { Except } from "type-fest";
|
import { Except } from "type-fest";
|
||||||
|
|
||||||
import { runtimeHashMessageKey } from "./intlHash";
|
import { runtimeHashMessageKey } from "./intlHash";
|
||||||
|
import { Logger } from "./Logger";
|
||||||
import { MediaModalItem, MediaModalProps, openMediaModal } from "./modal";
|
import { MediaModalItem, MediaModalProps, openMediaModal } from "./modal";
|
||||||
|
|
||||||
|
const IntlManagerLogger = new Logger("IntlManager");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an internationalized message from a non hashed key
|
* Get an internationalized message from a non hashed key
|
||||||
* @param key The plain message key
|
* @param key The plain message key
|
||||||
* @param values The values to interpolate, if it's a rich message
|
* @param values The values to interpolate, if it's a rich message
|
||||||
*/
|
*/
|
||||||
export function getIntlMessage(key: string, values?: Record<PropertyKey, any>): any {
|
export function getIntlMessage(key: string, values?: Record<PropertyKey, any>): any {
|
||||||
return getIntlMessageFromHash(runtimeHashMessageKey(key), values);
|
return getIntlMessageFromHash(runtimeHashMessageKey(key), values, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an internationalized message from a hashed 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
|
* @param values The values to interpolate, if it's a rich message
|
||||||
*/
|
*/
|
||||||
export function getIntlMessageFromHash(key: string, values?: Record<PropertyKey, any>): any {
|
export function getIntlMessageFromHash(hashedKey: string, values?: Record<PropertyKey, any>, originalKey?: string): any {
|
||||||
return values == null ? i18n.intl.string(i18n.t[key]) : i18n.intl.format(i18n.t[key], values);
|
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 ?? "";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue