add PITranslator

begin localization "ru"
This commit is contained in:
2024-11-02 18:43:30 +03:00
parent df75efe881
commit 9a928f6feb
14 changed files with 305 additions and 407 deletions

View File

@@ -23,6 +23,7 @@
#include "piliterals.h"
#include "pimathbase.h"
#include "pistringlist.h"
#include "pitranslator.h"
#ifdef PIP_ICU
# define U_NOEXCEPT
# include "unicode/ucnv.h"
@@ -1732,43 +1733,32 @@ ldouble PIString::toLDouble() const {
//! piCout << s; // 47.6 GiB
//! \endcode
PIString & PIString::setReadableSize(llong bytes) {
static const PIString tr_c = "PIString"_a;
clear();
if (bytes < 1024) {
*this += (PIString::fromNumber(bytes) + " B"_a);
*this += (PIString::fromNumber(bytes) + " "_a + PITranslator::tr("B", tr_c));
return *this;
}
double fres = bytes / 1024.;
llong res = bytes / 1024;
fres -= res;
if (res < 1024) {
*this += (PIString::fromNumber(res) + "."_a + PIString::fromNumber(llong(fres * 10)).left(1) + " KiB"_a);
return *this;
}
fres = res / 1024.;
res /= 1024;
fres -= res;
if (res < 1024) {
*this += (PIString::fromNumber(res) + "."_a + PIString::fromNumber(llong(fres * 10)).left(1) + " MiB"_a);
return *this;
}
fres = res / 1024.;
res /= 1024;
fres -= res;
if (res < 1024) {
*this += (PIString::fromNumber(res) + "."_a + PIString::fromNumber(llong(fres * 10)).left(1) + " GiB"_a);
return *this;
}
fres = res / 1024.;
res /= 1024;
fres -= res;
if (res < 1024) {
*this += (PIString::fromNumber(res) + "."_a + PIString::fromNumber(llong(fres * 10)).left(1) + " TiB"_a);
return *this;
}
fres = res / 1024.;
res /= 1024;
fres -= res;
*this += (PIString::fromNumber(res) + "."_a + PIString::fromNumber(llong(fres * 10)).left(1) + " PiB"_a);
double fres = bytes;
llong res = bytes;
auto checkRange = [this, &fres, &res](const PIString & unit, bool last = false) {
fres = res / 1024.;
res /= 1024;
fres -= res;
if (res < 1024 || last) {
*this += (PIString::fromNumber(res) + "."_a + PIString::fromNumber(llong(fres * 10)).left(1) + " "_a + unit);
return true;
}
return false;
};
if (checkRange(PITranslator::tr("KiB", tr_c))) return *this;
if (checkRange(PITranslator::tr("MiB", tr_c))) return *this;
if (checkRange(PITranslator::tr("GiB", tr_c))) return *this;
if (checkRange(PITranslator::tr("TiB", tr_c))) return *this;
if (checkRange(PITranslator::tr("PiB", tr_c))) return *this;
if (checkRange(PITranslator::tr("EiB", tr_c))) return *this;
if (checkRange(PITranslator::tr("ZiB", tr_c))) return *this;
checkRange(PITranslator::tr("YiB", tr_c), true);
return *this;
}