From 4b44dfccee8c4e4a0bab5a2e9767d5b4e2acabf3 Mon Sep 17 00:00:00 2001 From: PalmDevs Date: Sat, 14 Sep 2024 18:21:21 +0700 Subject: [PATCH] fix: use correct trailing text component, fix i18n one last time --- package.json | 1 + src/core/i18n/index.ts | 18 +++++++----------- src/core/ui/settings/pages/General/Version.tsx | 4 ++-- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index 1dda454d..ac609c91 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "chalk": "^5.3.0", "esbuild": "^0.20.2", "esbuild-plugin-globals": "^0.2.0", + "react-intl": "^6.6.8", "typescript": "^5.6.2", "yargs-parser": "^21.1.1" }, diff --git a/src/core/i18n/index.ts b/src/core/i18n/index.ts index 883e598a..d92d5f26 100644 --- a/src/core/i18n/index.ts +++ b/src/core/i18n/index.ts @@ -1,11 +1,11 @@ import { logger } from "@core/logger"; import { FluxDispatcher } from "@metro/common"; -import { findByPropsLazy } from "@metro/wrappers"; -import type { PrimitiveType } from "intl-messageformat"; import langDefault from "./default.json"; +import { findByProps } from "@metro"; -const IntlMessageFormat = findByPropsLazy("IntlMessageFormat") as typeof import("intl-messageformat"); +// Pylix wanted to use Discord's built-in modules, but it just does not work :/ +import IntlMessageFormat from "intl-messageformat"; type I18nKey = keyof typeof langDefault; @@ -28,7 +28,7 @@ export const Strings = new Proxy( ) as Record; export function initFetchI18nStrings() { - const cb = ({ locale }: { locale: string }) => { + const cb = ({ locale }: { locale: string; }) => { const languageMap = { "es-ES": "es", "es-419": "es_419", @@ -63,10 +63,6 @@ export function initFetchI18nStrings() { return () => FluxDispatcher.unsubscribe("I18N_LOAD_SUCCESS", cb); } -type FormatStringRet = T extends PrimitiveType ? string : string | T | (string | T)[]; - -export function formatString(key: I18nKey, val: Record): FormatStringRet { - const str = Strings[key]; - // @ts-ignore - return IntlMessageFormat.IntlMessageFormat(str).format(val); -} +export function formatString(key: I18nKey, val: Record): string { + return new IntlMessageFormat(Strings[key]).format(val) +} \ No newline at end of file diff --git a/src/core/ui/settings/pages/General/Version.tsx b/src/core/ui/settings/pages/General/Version.tsx index 9eebdd72..13b72598 100644 --- a/src/core/ui/settings/pages/General/Version.tsx +++ b/src/core/ui/settings/pages/General/Version.tsx @@ -1,6 +1,6 @@ import { findAssetId } from "@lib/api/assets"; import { clipboard } from "@metro/common"; -import { TableRow } from "@metro/common/components"; +import { TableRow, TableRowTrailingText } from "@metro/common/components"; import { showToast } from "@ui/toasts"; interface VersionProps { @@ -14,7 +14,7 @@ export default function Version({ label, version, icon }: VersionProps) { } - trailing={{version}} + trailing={} onPress={() => { clipboard.setString(`${label} - ${version}`); showToast.showCopyToClipboard();