[view] improvement: displaying update sizes as localized numbers (update summary)

This commit is contained in:
Vinicius Moreira
2022-04-06 15:41:07 -03:00
parent 950d422094
commit 9daba19f61
4 changed files with 18 additions and 1 deletions

View File

@@ -1,4 +1,5 @@
import faulthandler
import locale
import os
import sys
import traceback
@@ -25,6 +26,12 @@ def main(tray: bool = False):
logger = logs.new_logger(__app_name__, bool(args.logs))
try:
locale.setlocale(locale.LC_NUMERIC, '')
except:
logger.error("Could not set locale 'LC_NUMBERIC' to '' to display localized numbers")
traceback.print_exc()
if args.offline:
logger.warning("offline mode activated")

View File

@@ -1,3 +1,4 @@
import locale
from typing import Tuple, Optional, Iterable
from bauh.api.abstract.view import SelectViewType, InputOption, SingleSelectComponent
@@ -34,5 +35,6 @@ def get_human_size_str(size, positive_sign: bool = False) -> Optional[str]:
if size_unit < 1024:
size_unit = size_unit if size > 0 else size_unit * -1
size_str = f'{int(size_unit)} {unit}' if unit == 'B' else f'{size_unit:.2f} {unit}'
localized_size = locale.format_string('%.2f', size_unit)
size_str = f'{int(size_unit)} {unit}' if unit == 'B' else f"{localized_size} {unit}"
return f'+{size_str}' if positive_sign and size_unit > 0 else size_str