Skip to content

Commit ab92f39

Browse files
authored
fix(TerminalProgress): make the progress bar respect locale-specific decimal separator (apple#936)
- The `ProgressBar#adjustFormattedSize` function currently expects a decimal dot when adding the additional ".0" to the size. This, however, breaks when a region with a non-dot decimal separator is used.
1 parent 420be74 commit ab92f39

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

Sources/TerminalProgress/ProgressBar.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,12 +261,13 @@ extension ProgressBar {
261261
private func adjustFormattedSize(_ size: String) -> String {
262262
// Ensure we always have one digit after the decimal point to prevent flickering.
263263
let zero = Int64(0).formattedSize()
264-
guard !size.contains("."), let first = size.first, first.isNumber || !size.contains(zero) else {
264+
let decimalSep = Locale.current.decimalSeparator ?? "."
265+
guard !size.contains(decimalSep), let first = size.first, first.isNumber || !size.contains(zero) else {
265266
return size
266267
}
267268
var size = size
268269
for unit in ["MB", "GB", "TB"] {
269-
size = size.replacingOccurrences(of: " \(unit)", with: ".0 \(unit)")
270+
size = size.replacingOccurrences(of: " \(unit)", with: "\(decimalSep)0 \(unit)")
270271
}
271272
return size
272273
}

0 commit comments

Comments
 (0)