qtqlocale

Is there any way for QLocale::formattedDataSize function to return the translation quantified units?


QLocale::formattedDataSize always return English quantified units.


Solution

  • The units are clearly translated, as seen from the source code of qlocale_data_p.h.

    This private header defines an array named byte_unit_data with the following content as characters:

    byteskB;MB;GB;TB;PB;EBKiB;MiB;GiB;TiB;PiB;EiBbytegrepebajtባይትኪባ;ሜጋባይት;ጊባ;ቴራባይት;PB;EBبايتكيلوبايت;ميغابايت;غيغابايت;تيرابايت;PB;EBբայթերկԲ;ՄԲ;ԳԲ;ՏԲ;PB;EBবাইটকিঃ বাঃ;মেঃ বাঃ;গিঃ বাঃ;টেঃ বাঃ;PB;EBbaytbyte-akoktedoùko;Mo;Go;To;Po;EoKio;Mio;Gio;Tio;Pio;Eioбайтовеဘိုက်байтыКБ;МБ;ГБ;ТБ;PB;EBបៃ字节千字节;兆字节;吉字节;太字节;PB;EB位元組bajtovibajtybaididbýtKB;MB;GB;TB;PB;EBtavutkt;Mt;Gt;Tt;Pt;EtKit;Mit;Git;Tit;Pit;Eitoctetsbaidhtბაიტიკბაიტი;მბაიტი;გბაიტი;ტბაიტი;PB;EBBytesબાઇટבייטबाइटbájtbætibeartaバイトಬೈಟ್‌ಗಳುಕಿ.ಬೈ.;ಮೆ.ಬೈ.;ಗಿ.ಬೈ.;ಟೆ.ಬೈ.;PB;EBбайткБ;MБ;ГБ;TБ;PБ;EБKiБ;MiБ;GiБ;TiБ;PiБ;EiБкБ;МБ;ГБ;ТБ;PB;EB바이트baitibaitaiбајтиbaitബൈറ്റ്കി.ബി.;മെ.ബൈ.;ജി.ബൈ.;ടിബി;PB;EBବାଇଟ୍بایتکیلوبایت;مگابایت;گیگابایت;ترابایت;PB;EBਬਾਇਟbyțiбајтовиبائيٽزڪلو بائيٽز;ميگا بائيٽز;گيگا بائيٽز;ٽيرا بائيٽز;PB;EBබයිට්කිබ {0};මෙබ {0};ගිබ {0};ටෙබ {0};PB;EBkilobaiti {0};MB {0};GB {0};terabaiti {0};PB;EBபைட்கள்బైట్‌లుకేబీ;ఎమ్‌బి;జీబీ;టీబీ;PB;EBไบต์paitikB ʻe {0};MB ʻe {0};GB ʻe {0};TB ʻe {0};PB ʻe {0};EB ʻe {0}KiB ʻe {0};MiB ʻe {

    ...

    So you have to use the correct locale (from the location in your user profile I assume it is Russian) and format QLocale::DataSizeTraditionalFormat like this:

    QLocale l(QLocale::Russian, QLocale::Russia);
    
    l.formattedDataSize(154, 2, QLocale::DataSizeTraditionalFormat);        // "154 байты"
    l.formattedDataSize(19324, 2, QLocale::DataSizeTraditionalFormat);      // "18,87 кБ"
    l.formattedDataSize(125839324, 2, QLocale::DataSizeTraditionalFormat);  // "120,01 МБ"