Skip to content

Commit 0324047

Browse files
committed
i18n: counts follow the OS region instead of always en-US
`formatNumber` and the loading-overlay count now group thousands by the active locale (via the `lib/intl` chokepoint), so a German-region user sees `1.234` where the hardcoded en-US path showed `1,234`. This is the native-correct behavior and aligns counts with the dates that already localize. An en-US-region runtime is unchanged (parity net stays green). - `formatNumber` delegates to `formatInteger` (memoized locale formatter); the `'en-US'` literal is gone. - `LoadingIcon.svelte` routes through the same helper instead of a bare `toLocaleString()` (it previously used the runtime default, inconsistent with the rest of the app).
1 parent 638bac9 commit 0324047

3 files changed

Lines changed: 23 additions & 9 deletions

File tree

apps/desktop/src/lib/file-explorer/selection/selection-info-utils.test.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Tests for selection-info-utils.ts
33
*/
4-
import { describe, it, expect } from 'vitest'
4+
import { afterEach, describe, it, expect } from 'vitest'
55
import {
66
formatSizeTriads,
77
formatSizeForDisplay,
@@ -17,6 +17,7 @@ import {
1717
calculatePercentage,
1818
} from './selection-info-utils'
1919
import { formatDateForDisplay } from '$lib/settings/format-utils'
20+
import { _setLocaleForTests } from '$lib/intl/locale'
2021
import type { FileEntry } from '../types'
2122

2223
// Helper to create a basic file entry
@@ -459,26 +460,39 @@ describe('formatSizeForDisplay', () => {
459460
// ============================================================================
460461

461462
describe('formatNumber', () => {
463+
afterEach(() => {
464+
_setLocaleForTests(null)
465+
})
466+
462467
it('formats small numbers without separators', () => {
463468
expect(formatNumber(0)).toBe('0')
464469
expect(formatNumber(1)).toBe('1')
465470
expect(formatNumber(999)).toBe('999')
466471
})
467472

468-
it('formats thousands with comma separator', () => {
473+
it('formats thousands with comma separator (en-US)', () => {
474+
_setLocaleForTests('en-US')
469475
expect(formatNumber(1000)).toBe('1,000')
470476
expect(formatNumber(1234)).toBe('1,234')
471477
expect(formatNumber(9999)).toBe('9,999')
472478
})
473479

474-
it('formats millions with multiple comma separators', () => {
480+
it('formats millions with multiple comma separators (en-US)', () => {
481+
_setLocaleForTests('en-US')
475482
expect(formatNumber(1000000)).toBe('1,000,000')
476483
expect(formatNumber(1234567)).toBe('1,234,567')
477484
})
478485

479-
it('formats large numbers correctly', () => {
486+
it('formats large numbers correctly (en-US)', () => {
487+
_setLocaleForTests('en-US')
480488
expect(formatNumber(1234567890)).toBe('1,234,567,890')
481489
})
490+
491+
it('follows the active locale: de-DE groups with a period', () => {
492+
_setLocaleForTests('de-DE')
493+
expect(formatNumber(1000)).toBe('1.000')
494+
expect(formatNumber(1234567)).toBe('1.234.567')
495+
})
482496
})
483497

484498
describe('calculatePercentage', () => {

apps/desktop/src/lib/file-explorer/selection/selection-info-utils.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
type DateSegment,
1313
type FormattedDate,
1414
} from '$lib/settings/format-utils'
15+
import { formatInteger } from '$lib/intl/number-format'
1516

1617
// Size tier colors for digit triads (indexed: 0=bytes, 1=kB, 2=MB, 3=GB, 4=TB+)
1718
export const sizeTierClasses = ['size-bytes', 'size-kb', 'size-mb', 'size-gb', 'size-tb']
@@ -206,9 +207,9 @@ export function isPermissionDenied(entry: FileEntry | null): boolean {
206207
// Selection summary utilities
207208
// ============================================================================
208209

209-
/** Formats a number with thousands separators using en-US locale */
210+
/** Formats a count with the active locale's thousands grouping (en-US `1,234`, de-DE `1.234`). */
210211
export function formatNumber(n: number): string {
211-
return n.toLocaleString('en-US')
212+
return formatInteger(n)
212213
}
213214

214215
/** Calculates percentage, rounded to nearest integer */

apps/desktop/src/lib/ui/LoadingIcon.svelte

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<script lang="ts">
22
import ShortcutChip from '$lib/ui/ShortcutChip.svelte'
33
import Spinner from '$lib/ui/Spinner.svelte'
4+
import { formatInteger } from '$lib/intl/number-format'
45
56
interface Props {
67
openingFolder?: boolean
@@ -11,9 +12,7 @@
1112
1213
const { openingFolder = false, loadedCount, finalizingCount, showCancelHint = false }: Props = $props()
1314
14-
function formatNumber(n: number): string {
15-
return n.toLocaleString()
16-
}
15+
const formatNumber = formatInteger
1716
</script>
1817

1918
<div class="loading-container">

0 commit comments

Comments
 (0)