Skip to content

Commit

Permalink
Update some strings
Browse files Browse the repository at this point in the history
  • Loading branch information
pylixonly committed Mar 7, 2024
1 parent 218d09a commit cea9b1c
Show file tree
Hide file tree
Showing 13 changed files with 54 additions and 37 deletions.
24 changes: 18 additions & 6 deletions src/core/i18n/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"ARE_YOU_SURE_TO_CLEAR_DATA": "Are you sure you wish to clear the data of {name}?",
"ARE_YOU_SURE_TO_DELETE_PLUGIN": "Are you sure you wish to delete {name}? This will clear all of the plugin's data.",
"ARE_YOU_SURE_TO_DELETE_THEME": "Are you sure you wish to delete {name}?",
"ASSET_BROWSER": "Asset Browser",
"BRAND": "Brand",
"BUNNY": "Bunny",
"BUNNY_URL": "Bunny URL",
Expand All @@ -20,37 +21,46 @@
"COMMAND_EVAL_OPT_CODE": "The code to evaluate.",
"COMMAND_PLUGINS_DESC": "Send list of installed plugins.",
"COMMAND_PLUGINS_OPT_EPHEMERALLY": "Send plugins list ephemerally.",
"COMPONENT": "Component",
"CONFIRMATION_LINK_IS_A_TYPE": "This link is a **{urlType, select, plugin {Plugin} theme {Theme} other {Add-on}}**, would you like to install it?",
"CONNECT_TO_DEBUG_WEBSOCKET": "Connect to debug websocket",
"CONNECT_TO_REACT_DEVTOOLS": "Connect to React DevTools",
"COPIED_TO_CLIPBOARD": "Copied plugin URL to clipboard",
"COPY_URL": "Copy URL",
"DEBUG": "Debug",
"DEBUGGER_URL": "Debugger URL",
"DELETE": "Delete",
"DEVELOPER": "Developer",
"DEVELOPER_SETTINGS": "Developer Settings",
"DISABLE_THEME": "Disable Theme",
"DISABLE_UPDATES": "Disable updates",
"DISCORD_SERVER": "Discord Server",
"ENABLE_UPDATES": "Enable updates",
"ERROR_BOUNDARY_TOOLS_LABEL": "ErrorBoundary Tools",
"GENERAL": "General",
"GITHUB": "GitHub",
"HOLD_UP": "Hold Up",
"INFO": "Info",
"INSTALL": "Install",
"INSTALL_ADDON": "Install Add-on",
"INSTALL_PLUGIN": "Install Plugin",
"INSTALL_THEME": "Install Theme",
"INSTALL_TITLE": "Install {title}",
"LINKS": "Links",
"LOAD_FROM_CUSTOM_URL": "Load from custom url",
"LOAD_FROM_CUSTOM_URL_DEC": "Load Bunny from a custom endpoint.",
"LOAD_REACT_DEVTOOLS": "Load React DevTools",
"LOADER": "Loader",
"MACHINE_ID": "Machine ID",
"MANUFACTURER": "Manufacturer",
"MESSAGE": "Message",
"MODAL_THEME_REFETCHED": "Theme refetched",
"MODAL_THEME_REFETCHED_DESC": "A reload is required to see the changes. Do you want to reload now?",
"MODAL_UNPROXIED_PLUGIN_DESC": "The plugin you are trying to install has not been proxied/verified by staffs. Are you sure you want to continue?",
"MODAL_UNPROXIED_PLUGIN_HEADER": "Unproxied Plugin",
"MODEL": "Model",
"OPEN_IN_BROWSER": "Open in Browser",
"OPERATING_SYSTEM": "Operating System",
"OVERFLOW_PLUGIN_SETTINGS": "Plugin settings",
"PHONE_MODEL": "Model",
"PLATFORM": "Platform",
"PLUGINS": "Plugins",
"REFETCH": "Refetch",
Expand All @@ -61,20 +71,22 @@
"RELOAD_IN_SAFE_MODE": "Reload in Safe Mode",
"RELOAD_IN_SAFE_MODE_DESC": "This will reload Discord without loading addons",
"RETRY": "Retry",
"RETRY_RENDER": "Retry Render",
"SAFE_MODE": "Safe Mode",
"SAFE_MODE_NOTICE_PLUGINS": "You are in Safe Mode, so plugins cannot be loaded. Disable any misbehaving plugins, then return to Normal Mode from the General settings page.",
"SAFE_MODE_NOTICE_THEMES": "You are in Safe Mode, meaning themes have been temporarily disabled.",
"SAFE_MODE_NOTICE_THEMES_EXTEND": "If a theme appears to be causing the issue, you can press below to disable it persistently.",
"SAFE_MODE_NOTICE_THEMES": "You are in Safe Mode, meaning themes have been temporarily disabled.{enabled, select, true { If a theme appears to be causing the issue, you can press below to disable it persistently.}}",
"SEARCH": "Search",
"STACK_TRACE": "Stack Trace",
"SUCCESSFULLY_INSTALLED": "Successfully installed",
"THEME_REFETCH_FAILED": "Failed to refetch theme!",
"THEME_REFETCH_SUCCESSFUL": "Successfully refetched theme.",
"THEMES": "Themes",
"THEMES_RELOAD_FOR_CHANGES": "Reload the app to fully apply changes!",
"TOASTS_INSTALLED_PLUGIN": "Installed plugin",
"TOASTS_SUCCESSFULLY_INSTALLED": "Successfully installed",
"TOASTS_COPIED_TO_CLIPBOARD": "Copied plugin URL to clipboard",
"UH_OH": "Uh oh.",
"UNINSTALL": "Uninstall",
"UNINSTALL_TITLE": "Uninstall {title}",
"URL_PLACEHOLDER": "https://example.com",
"VERSION": "Version",
"VERSIONS": "Versions"
}
5 changes: 3 additions & 2 deletions src/core/i18n/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { findByName } from "@lib/metro/filters";
import { PrimitiveType } from "intl-messageformat";

import langDefault from "./default.json";

Expand All @@ -12,9 +13,9 @@ export const Strings = new Proxy({}, {
}
}) as Record<I18nKey, string>;

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

export function formatString<T = void>(key: I18nKey, val: Record<string, T>): FRet<T> {
export function formatString<T = void>(key: I18nKey, val: Record<string, T>): FormatStringRet<T> {
const str = Strings[key];
// @ts-ignore
return new IntlMessageFormat(str).format(val);
Expand Down
4 changes: 2 additions & 2 deletions src/core/plugins/quickInstall/url.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function typeFromUrl(url: string) {
function installWithToast(type: "plugin" | "theme", url: string) {
(type === "plugin" ? installPlugin : installTheme)(url)
.then(() => {
showToast(Strings.TOASTS_SUCCESSFULLY_INSTALLED, getAssetIDByName("Check"));
showToast(Strings.SUCCESSFULLY_INSTALLED, getAssetIDByName("Check"));
})
.catch((e: Error) => {
showToast(e.message, getAssetIDByName("Small"));
Expand All @@ -49,7 +49,7 @@ export default () => {
if (!urlType) return;

options.push({
label: formatString("INSTALL_TITLE", { urlType }),
label: Strings.INSTALL_ADDON,
onPress: () => installWithToast(urlType, url),
});
})
Expand Down
11 changes: 6 additions & 5 deletions src/core/ui/components/AddonPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { formatString, Strings } from "@core/i18n";
import { Strings } from "@core/i18n";
import { CardWrapper } from "@core/ui/components/Card";
import { getAssetIDByName } from "@lib/api/assets";
import { useProxy } from "@lib/api/storage";
Expand All @@ -14,6 +14,7 @@ import { FlatList, View } from "react-native";

interface AddonPageProps<T> {
title: string;
floatingButtonText: string;
fetchFunction: (url: string) => Promise<void>;
items: Record<string, T & { id: string; }>;
safeModeMessage: string;
Expand All @@ -38,7 +39,7 @@ function getItemsByQuery<T extends { id?: string; }>(items: T[], query: string):
const reanimated = findByProps("useSharedValue");
const { FloatingActionButton } = findByProps("FloatingActionButton");

export default function AddonPage<T>({ title, fetchFunction, items, safeModeMessage, safeModeExtras, card: CardComponent }: AddonPageProps<T>) {
export default function AddonPage<T>({ title, floatingButtonText, fetchFunction, items, safeModeMessage, safeModeExtras, card: CardComponent }: AddonPageProps<T>) {
useProxy(settings);
useProxy(items);

Expand Down Expand Up @@ -73,16 +74,16 @@ export default function AddonPage<T>({ title, fetchFunction, items, safeModeMess
renderItem={({ item, index }) => <CardComponent item={item} index={index} />}
/>
<FloatingActionButton
text={formatString("INSTALL_TITLE", { title })}
text={floatingButtonText}
icon={getAssetIDByName("DownloadIcon")}
state={{ collapseText }}
onPress={() => {
// from ./InstallButton.tsx
clipboard.getString().then(content =>
showInputAlert({
title: formatString("INSTALL_TITLE", { title }),
title: floatingButtonText,
initialValue: content.match(HTTP_REGEX_MULTI)?.[0] ?? "",
placeholder: "https://example.com/",
placeholder: Strings.URL_PLACEHOLDER,
onConfirm: (input: string) => fetchFunction(input),
confirmText: Strings.INSTALL,
cancelText: Strings.CANCEL,
Expand Down
2 changes: 1 addition & 1 deletion src/core/ui/components/InstallButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default function InstallButton({ alertTitle, installFunction: fetchFuncti
showInputAlert({
title: alertTitle,
initialValue: content.match(HTTP_REGEX_MULTI)?.[0] ?? "",
placeholder: "https://example.com/",
placeholder: Strings.URL_PLACEHOLDER,
onConfirm: (input: string) => fetchFunction(input),
confirmText: Strings.INSTALL,
cancelText: Strings.CANCEL,
Expand Down
1 change: 0 additions & 1 deletion src/core/ui/settings/pages/AssetBrowser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export default function AssetBrowser() {
<Search
style={{ margin: 10 }}
onChangeText={(v: string) => setSearch(v)}
placeholder="Search"
/>
<FlatList
data={Object.values(all).filter(a => a.name.includes(search) || a.id.toString() === search)}
Expand Down
18 changes: 9 additions & 9 deletions src/core/ui/settings/pages/Developer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ export default function Developer() {
<ScrollView style={{ flex: 1 }} contentContainerStyle={{ paddingBottom: 38 }}>
<Stack style={{ paddingVertical: 24, paddingHorizontal: 12 }} spacing={24}>
<TextInput
label="Debugger URL"
label={Strings.DEBUGGER_URL}
placeholder="127.0.0.1:9090"
size="md"
leadingIcon={() => <FormText style={styles.leadingText}>ws://</FormText>}
defaultValue={settings.debuggerUrl}
onChange={(v: string) => settings.debuggerUrl = v}
/>
<TableRowGroup title="Debug">
<TableRowGroup title={Strings.DEBUG}>
<TableRow
label={Strings.CONNECT_TO_DEBUG_WEBSOCKET}
icon={<TableRow.Icon source={getAssetIDByName("copy")} />}
Expand All @@ -64,8 +64,8 @@ export default function Developer() {
{isLoaderConfigSupported() && <>
<TableRowGroup title="Loader config">
<TableSwitchRow
label="Load from custom url"
subLabel={"Load Bunny from a custom endpoint."}
label={Strings.LOAD_FROM_CUSTOM_URL}
subLabel={Strings.LOAD_FROM_CUSTOM_URL_DEC}
icon={<TableRow.Icon source={getAssetIDByName("copy")} />}
value={loaderConfig.customLoadUrl.enabled}
onValueChange={(v: boolean) => {
Expand All @@ -80,8 +80,8 @@ export default function Developer() {
label={Strings.BUNNY_URL}
/>} />}
{isReactDevToolsPreloaded() && <TableSwitchRow
label="Load React DevTools"
subLabel={`Version: ${getReactDevToolsVersion()}`}
label={Strings.LOAD_REACT_DEVTOOLS}
subLabel={`${Strings.VERSION}: ${getReactDevToolsVersion()}`}
icon={<TableRow.Icon source={getAssetIDByName("ic_badge_staff")} />}
value={loaderConfig.loadReactDevTools}
onValueChange={(v: boolean) => {
Expand All @@ -93,17 +93,17 @@ export default function Developer() {
<TableRowGroup title="Other">
<TableRow
arrow
label="Asset Browser"
label={Strings.ASSET_BROWSER}
icon={<TableRow.Icon source={getAssetIDByName("ic_image")} />}
trailing={TableRow.Arrow}
onPress={() => navigation.push("VendettaCustomPage", {
title: "Asset Browser",
title: Strings.ASSET_BROWSER,
render: AssetBrowser,
})}
/>
<TableRow
arrow
label="ErrorBoundary Tools"
label={Strings.ERROR_BOUNDARY_TOOLS_LABEL}
icon={<TableRow.Icon source={getAssetIDByName("ic_warning_24px")} />}
onPress={() => showSimpleActionSheet({
key: "ErrorBoundaryTools",
Expand Down
2 changes: 1 addition & 1 deletion src/core/ui/settings/pages/General.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export default function General() {
icon: "ic_settings_boost_24px"
},
{
label: Strings.PHONE_MODEL,
label: Strings.MODEL,
version: debugInfo.device.model,
icon: "ic_phonelink_24px"
},
Expand Down
1 change: 1 addition & 0 deletions src/core/ui/settings/pages/Plugins.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default function Plugins() {
return (
<AddonPage<BunnyPlugin>
title={Strings.PLUGINS}
floatingButtonText={Strings.INSTALL_PLUGIN}
fetchFunction={installPlugin}
items={plugins}
safeModeMessage={Strings.SAFE_MODE_NOTICE_PLUGINS}
Expand Down
5 changes: 3 additions & 2 deletions src/core/ui/settings/pages/Themes.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Strings } from "@core/i18n";
import { formatString, Strings } from "@core/i18n";
import AddonPage from "@core/ui/components/AddonPage";
import ThemeCard from "@core/ui/components/ThemeCard";
import { useProxy } from "@lib/api/storage";
Expand All @@ -13,9 +13,10 @@ export default function Themes() {
return (
<AddonPage<Theme>
title={Strings.THEMES}
floatingButtonText={Strings.INSTALL_THEME}
fetchFunction={installTheme}
items={themes}
safeModeMessage={`${Strings.SAFE_MODE_NOTICE_THEMES}${settings.safeMode?.currentThemeId ? ` ${Strings.SAFE_MODE_NOTICE_THEMES_EXTEND}` : ""}`}
safeModeMessage={formatString("SAFE_MODE_NOTICE_THEMES", { enabled: Boolean(settings.safeMode?.currentThemeId) })}
safeModeExtras={settings.safeMode?.currentThemeId ? <Button
text={Strings.DISABLE_THEME}
color={ButtonColors.BRAND}
Expand Down
13 changes: 7 additions & 6 deletions src/lib/ui/safeMode.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Strings } from "@core/i18n";
import { DeviceManager } from "@lib/api/native/modules";
import { after } from "@lib/api/patcher";
import { _toggleSafeMode } from "@lib/debug";
Expand Down Expand Up @@ -61,9 +62,9 @@ interface Button {
}

const tabs: Tab[] = [
{ id: "message", title: "Message" },
{ id: "stack", title: "Stack Trace" },
{ id: "componentStack", title: "Component", trimWhitespace: true },
{ id: "message", title: Strings.MESSAGE },
{ id: "stack", title: Strings.STACK_TRACE },
{ id: "componentStack", title: Strings.COMPONENT, trimWhitespace: true },
];

export default () => after("render", ErrorBoundary.prototype, function (this: any, _, ret) {
Expand All @@ -76,9 +77,9 @@ export default () => after("render", ErrorBoundary.prototype, function (this: an

// This is in the patch and not outside of it so that we can use `this`, e.g. for setting state
const buttons: Button[] = [
{ text: "Restart Discord", onPress: this.handleReload },
...!settings.safeMode?.enabled ? [{ text: "Restart in Safe Mode", onPress: _toggleSafeMode }] : [],
{ text: "Retry Render", color: ButtonColors.RED, onPress: () => this.setState({ info: null, error: null }) },
{ text: Strings.RELOAD_DISCORD, onPress: this.handleReload },
...!settings.safeMode?.enabled ? [{ text: Strings.RELOAD_IN_SAFE_MODE, onPress: _toggleSafeMode }] : [],
{ text: Strings.RETRY_RENDER, color: ButtonColors.RED, onPress: () => this.setState({ info: null, error: null }) },
];

return (
Expand Down
3 changes: 2 additions & 1 deletion src/lib/ui/settings/patches/shared.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { NavigationNative } from "@lib/metro/common";
import { findByProps } from "@lib/metro/filters";
import { ErrorBoundary } from "@lib/ui/components";
import { RowConfig } from "@lib/ui/settings";

const tabsNavigationRef = findByProps("getRootNavigationRef");
Expand All @@ -12,7 +13,7 @@ export const CustomPageRenderer = React.memo(() => {

React.useEffect(() => void navigation.setOptions({ ...args }), []);

return <PageComponent />;
return <ErrorBoundary><PageComponent /></ErrorBoundary>;
});

export function wrapOnPress(
Expand Down
2 changes: 1 addition & 1 deletion src/lib/ui/toasts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const showToast = (content: string, asset?: number) => toasts.open({
icon: asset,
});

showToast.showCopyToClipboard = (message = Strings.TOASTS_COPIED_TO_CLIPBOARD) => {
showToast.showCopyToClipboard = (message = Strings.COPIED_TO_CLIPBOARD) => {
// On Android, only show toast for 12 and lower
if (Platform.OS !== "android" || Platform.Version <= 32) {
showToast(message, getAssetIDByName("toast_copy_link"));
Expand Down

0 comments on commit cea9b1c

Please sign in to comment.