--- a/src/eric7/Globals/__init__.py Sun Jul 02 17:40:17 2023 +0200 +++ b/src/eric7/Globals/__init__.py Tue Aug 01 09:59:45 2023 +0200 @@ -184,29 +184,57 @@ return QByteArray(txt) -def dataString(size): +def dataString(size, loc=None): """ Module function to generate a formatted size string. @param size size to be formatted @type int + @param loc locale to be used for localized size strings (defaults to None) + @type QLocale (optional) @return formatted data string @rtype str """ - if size < 1024: - return QCoreApplication.translate("Globals", "{0:4.2f} Bytes").format(size) - elif size < 1024 * 1024: - size /= 1024 - return QCoreApplication.translate("Globals", "{0:4.2f} KiB").format(size) - elif size < 1024 * 1024 * 1024: - size /= 1024 * 1024 - return QCoreApplication.translate("Globals", "{0:4.2f} MiB").format(size) - elif size < 1024 * 1024 * 1024 * 1024: - size /= 1024 * 1024 * 1024 - return QCoreApplication.translate("Globals", "{0:4.2f} GiB").format(size) + if loc is None: + if size < 1024: + return QCoreApplication.translate("Globals", "{0:4.2f} Bytes").format(size) + elif size < 1024 * 1024: + size /= 1024 + return QCoreApplication.translate("Globals", "{0:4.2f} KiB").format(size) + elif size < 1024 * 1024 * 1024: + size /= 1024 * 1024 + return QCoreApplication.translate("Globals", "{0:4.2f} MiB").format(size) + elif size < 1024 * 1024 * 1024 * 1024: + size /= 1024 * 1024 * 1024 + return QCoreApplication.translate("Globals", "{0:4.2f} GiB").format(size) + else: + size /= 1024 * 1024 * 1024 * 1024 + return QCoreApplication.translate("Globals", "{0:4.2f} TiB").format(size) else: - size /= 1024 * 1024 * 1024 * 1024 - return QCoreApplication.translate("Globals", "{0:4.2f} TiB").format(size) + if size < 1024: + return QCoreApplication.translate("Globals", "{0} Bytes").format( + loc.toString(size, "f", 2) + ) + elif size < 1024 * 1024: + size /= 1024 + return QCoreApplication.translate("Globals", "{0} KiB").format( + loc.toString(size, "f", 2) + ) + elif size < 1024 * 1024 * 1024: + size /= 1024 * 1024 + return QCoreApplication.translate("Globals", "{0} MiB").format( + loc.toString(size, "f", 2) + ) + elif size < 1024 * 1024 * 1024 * 1024: + size /= 1024 * 1024 * 1024 + return QCoreApplication.translate("Globals", "{0} GiB").format( + loc.toString(size, "f", 2) + ) + else: + size /= 1024 * 1024 * 1024 * 1024 + return QCoreApplication.translate("Globals", "{0} TiB").format( + loc.toString(size, "f", 2) + ) ###############################################################################