Skip to content

Commit

Permalink
fix: use correct trailing text component, fix i18n one last time
Browse files Browse the repository at this point in the history
  • Loading branch information
PalmDevs committed Sep 14, 2024
1 parent 96d7b17 commit 4b44dfc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
18 changes: 7 additions & 11 deletions src/core/i18n/index.ts
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -28,7 +28,7 @@ export const Strings = new Proxy(
) as Record<I18nKey, string>;

export function initFetchI18nStrings() {
const cb = ({ locale }: { locale: string }) => {
const cb = ({ locale }: { locale: string; }) => {
const languageMap = {
"es-ES": "es",
"es-419": "es_419",
Expand Down Expand Up @@ -63,10 +63,6 @@ export function initFetchI18nStrings() {
return () => FluxDispatcher.unsubscribe("I18N_LOAD_SUCCESS", cb);
}

type FormatStringRet<T> = T extends PrimitiveType ? string : string | T | (string | T)[];

export function formatString<T = void>(key: I18nKey, val: Record<string, T>): FormatStringRet<T> {
const str = Strings[key];
// @ts-ignore
return IntlMessageFormat.IntlMessageFormat(str).format(val);
}
export function formatString(key: I18nKey, val: Record<string, any>): string {
return new IntlMessageFormat(Strings[key]).format(val)
}
4 changes: 2 additions & 2 deletions src/core/ui/settings/pages/General/Version.tsx
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -14,7 +14,7 @@ export default function Version({ label, version, icon }: VersionProps) {
<TableRow
label={label}
icon={<TableRow.Icon source={findAssetId(icon)} />}
trailing={<TableRow.TrailingText>{version}</TableRow.TrailingText>}
trailing={<TableRowTrailingText text={version} />}
onPress={() => {
clipboard.setString(`${label} - ${version}`);
showToast.showCopyToClipboard();
Expand Down

0 comments on commit 4b44dfc

Please sign in to comment.