From 2044cbb21cdf13e5602d1d9d4bbf71d6a28aaadd Mon Sep 17 00:00:00 2001 From: Philipinho <16838612+Philipinho@users.noreply.github.com> Date: Thu, 16 Jan 2025 15:29:09 +0000 Subject: [PATCH] fix translation * fix filesize formatting --- .../attachment/upload-attachment-action.tsx | 2 +- .../editor/components/code-block/mermaid-view.tsx | 3 ++- .../editor/components/image/upload-image-action.tsx | 2 +- .../editor/components/video/upload-video-action.tsx | 2 +- .../src/features/space/types/space-role-data.ts | 2 +- apps/client/src/lib/time.ts | 2 +- apps/client/src/lib/utils.ts | 13 ++++++------- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/apps/client/src/features/editor/components/attachment/upload-attachment-action.tsx b/apps/client/src/features/editor/components/attachment/upload-attachment-action.tsx index 5b208dfc..f1fd2eb6 100644 --- a/apps/client/src/features/editor/components/attachment/upload-attachment-action.tsx +++ b/apps/client/src/features/editor/components/attachment/upload-attachment-action.tsx @@ -3,7 +3,7 @@ import { uploadFile } from "@/features/page/services/page-service.ts"; import { notifications } from "@mantine/notifications"; import { getFileUploadSizeLimit } from "@/lib/config.ts"; import { formatBytes } from "@/lib"; -import i18n from "i18next"; +import i18n from "@/i18n.ts"; export const uploadAttachmentAction = handleAttachmentUpload({ onUpload: async (file: File, pageId: string): Promise => { diff --git a/apps/client/src/features/editor/components/code-block/mermaid-view.tsx b/apps/client/src/features/editor/components/code-block/mermaid-view.tsx index 3c3c5386..5f2cf845 100644 --- a/apps/client/src/features/editor/components/code-block/mermaid-view.tsx +++ b/apps/client/src/features/editor/components/code-block/mermaid-view.tsx @@ -3,7 +3,7 @@ import { useEffect, useState } from "react"; import mermaid from "mermaid"; import { v4 as uuidv4 } from "uuid"; import classes from "./code-block.module.css"; -import { t } from "i18next"; +import { useTranslation } from "react-i18next"; mermaid.initialize({ startOnLoad: false, @@ -15,6 +15,7 @@ interface MermaidViewProps { } export default function MermaidView({ props }: MermaidViewProps) { + const { t } = useTranslation(); const { node } = props; const [preview, setPreview] = useState(""); diff --git a/apps/client/src/features/editor/components/image/upload-image-action.tsx b/apps/client/src/features/editor/components/image/upload-image-action.tsx index 191c1ecc..31556285 100644 --- a/apps/client/src/features/editor/components/image/upload-image-action.tsx +++ b/apps/client/src/features/editor/components/image/upload-image-action.tsx @@ -3,7 +3,7 @@ import { uploadFile } from "@/features/page/services/page-service.ts"; import { notifications } from "@mantine/notifications"; import { getFileUploadSizeLimit } from "@/lib/config.ts"; import { formatBytes } from "@/lib"; -import i18n from "i18next"; +import i18n from "@/i18n.ts"; export const uploadImageAction = handleImageUpload({ onUpload: async (file: File, pageId: string): Promise => { diff --git a/apps/client/src/features/editor/components/video/upload-video-action.tsx b/apps/client/src/features/editor/components/video/upload-video-action.tsx index da969974..fa1011ff 100644 --- a/apps/client/src/features/editor/components/video/upload-video-action.tsx +++ b/apps/client/src/features/editor/components/video/upload-video-action.tsx @@ -3,7 +3,7 @@ import { uploadFile } from "@/features/page/services/page-service.ts"; import { notifications } from "@mantine/notifications"; import { getFileUploadSizeLimit } from "@/lib/config.ts"; import { formatBytes } from "@/lib"; -import i18n from "i18next"; +import i18n from "@/i18n.ts"; export const uploadVideoAction = handleVideoUpload({ onUpload: async (file: File, pageId: string): Promise => { diff --git a/apps/client/src/features/space/types/space-role-data.ts b/apps/client/src/features/space/types/space-role-data.ts index 1a646203..cabcc413 100644 --- a/apps/client/src/features/space/types/space-role-data.ts +++ b/apps/client/src/features/space/types/space-role-data.ts @@ -1,5 +1,5 @@ import { IRoleData, SpaceRole } from "@/lib/types.ts"; -import i18n from "i18next"; +import i18n from "@/i18n.ts"; export const spaceRoleData: IRoleData[] = [ { diff --git a/apps/client/src/lib/time.ts b/apps/client/src/lib/time.ts index 67ee69f3..0e320c1f 100644 --- a/apps/client/src/lib/time.ts +++ b/apps/client/src/lib/time.ts @@ -1,6 +1,6 @@ import { formatDistanceStrict } from "date-fns"; import { format, isToday, isYesterday } from "date-fns"; -import i18n from "i18next"; +import i18n from "@/i18n.ts"; export function timeAgo(date: Date) { return formatDistanceStrict(new Date(date), new Date(), { addSuffix: true }); diff --git a/apps/client/src/lib/utils.ts b/apps/client/src/lib/utils.ts index 62391adc..4ea1ef8d 100644 --- a/apps/client/src/lib/utils.ts +++ b/apps/client/src/lib/utils.ts @@ -28,14 +28,10 @@ export const computeSpaceSlug = (name: string) => { } }; -export const formatBytes = ( - bytes: number, - decimalPlaces: number = 2, -): string => { +export const formatBytes = (bytes: number): string => { if (bytes === 0) return "0.0 KB"; const unitSize = 1024; - const precision = decimalPlaces < 0 ? 0 : decimalPlaces; const units = ["KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"]; const kilobytes = bytes / unitSize; @@ -44,6 +40,9 @@ export const formatBytes = ( const adjustedUnitIndex = Math.max(unitIndex, 0); const adjustedSize = kilobytes / Math.pow(unitSize, adjustedUnitIndex); + // Use one decimal for KB and no decimals for MB or higher + const precision = adjustedUnitIndex === 0 ? 1 : 0; + return `${adjustedSize.toFixed(precision)} ${units[adjustedUnitIndex]}`; }; @@ -66,9 +65,9 @@ function decodeBase64(base64: string): string { } export function decodeBase64ToSvgString(base64Data: string): string { - const base64Prefix = 'data:image/svg+xml;base64,'; + const base64Prefix = "data:image/svg+xml;base64,"; if (base64Data.startsWith(base64Prefix)) { - base64Data = base64Data.replace(base64Prefix, ''); + base64Data = base64Data.replace(base64Prefix, ""); } return decodeBase64(base64Data);