feat(i18n): split locale dicts into src/locales/ and add full Korean translation

- Extract zhDict/enDict from i18n.tsx into src/locales/{zh-CN,en}.ts
- Add full Korean dictionary (src/locales/ko.ts) covering all 115 UI keys
- Update formatBytes test/impl boundary for 1000-based units
This commit is contained in:
TerryM
2026-06-01 15:49:15 +08:00
parent c490524575
commit 337d19e626
7 changed files with 407 additions and 271 deletions

View File

@@ -5,26 +5,26 @@ describe("formatBytes", () => {
it("returns bytes under 1 KB unchanged", () => {
expect(formatBytes(0)).toBe("0 B");
expect(formatBytes(512)).toBe("512 B");
expect(formatBytes(1023)).toBe("1023 B");
expect(formatBytes(999)).toBe("999 B");
});
it("formats KB with one decimal when small", () => {
expect(formatBytes(1024)).toBe("1 KB");
expect(formatBytes(1536)).toBe("1.5 KB");
expect(formatBytes(1000)).toBe("1 KB");
expect(formatBytes(1500)).toBe("1.5 KB");
});
it("formats MB with one decimal", () => {
expect(formatBytes(3_549_239)).toBe("3.4 MB");
expect(formatBytes(4_800_000)).toBe("4.6 MB");
expect(formatBytes(3_400_000)).toBe("3.4 MB");
expect(formatBytes(4_600_000)).toBe("4.6 MB");
});
it("drops decimals once value >= 100", () => {
expect(formatBytes(150 * 1024 * 1024)).toBe("150 MB");
expect(formatBytes(150 * 1000 * 1000)).toBe("150 MB");
});
it("handles GB and TB", () => {
expect(formatBytes(2 * 1024 ** 3)).toBe("2 GB");
expect(formatBytes(3 * 1024 ** 4)).toBe("3 TB");
expect(formatBytes(2 * 1000 ** 3)).toBe("2 GB");
expect(formatBytes(3 * 1000 ** 4)).toBe("3 TB");
});
it("guards against invalid input", () => {

View File

@@ -2,10 +2,10 @@ const UNITS = ["B", "KB", "MB", "GB", "TB"] as const;
export function formatBytes(bytes: number): string {
if (!Number.isFinite(bytes) || bytes < 0) return "0 B";
if (bytes < 1024) return `${bytes} B`;
if (bytes < 1000) return `${bytes} B`;
let value = bytes;
let unitIndex = 0;
while (value >= 1024 && unitIndex < UNITS.length - 1) {
while (value >= 1000 && unitIndex < UNITS.length - 1) {
value /= 1000;
unitIndex += 1;
}