12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- ########################################################################
- # Searx-Qt - Lightweight desktop application for Searx.
- # Copyright (C) 2020-2022 CYBERDEViL
- #
- # This file is part of Searx-Qt.
- #
- # Searx-Qt is free software: you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation, either version 3 of the License, or
- # (at your option) any later version.
- #
- # Searx-Qt is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program. If not, see <https://www.gnu.org/licenses/>.
- #
- ########################################################################
- from searxqt.translations import _
- def boolToStr(state):
- return _("Yes") if state else _("No")
- def listToStr(list_):
- return ", ".join(list_)
- def formatFileSize(fileSize):
- """
- @param fileSize: File size in bytes to format to string.
- @type fileSize: uint
- """
- sizeStr = ""
- KiB = 1024
- MiB = KiB ** 2
- GiB = KiB ** 3
- TiB = KiB ** 4
- if fileSize > TiB: # TiB
- sizeStr = f"{fileSize / TiB:.2f} TB"
- elif fileSize > GiB: # GiB
- sizeStr = f"{fileSize / GiB:.2f} GB"
- elif fileSize > MiB: # MiB
- sizeStr = f"{fileSize / MiB:.2f} MB"
- elif fileSize > KiB: # KiB
- sizeStr = f"{fileSize / KiB:.2f} KB"
- else:
- sizeStr = f"{fileSize} Bytes"
- return sizeStr
- def formatFileCount(fileCount):
- """
- @param fileCount: File count to format to string.
- @type fileCount: uint
- """
- if fileCount == 1:
- return "1 " + _("file")
- return f"{fileCount} {_('files')}"
|