2 * Copyright 2010 Haiku Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
6 #include "StringForSize.h"
10 #include <MessageFormat.h>
11 #include <SystemCatalog.h>
13 using BPrivate::gSystemCatalog
;
16 #undef B_TRANSLATION_CONTEXT
17 #define B_TRANSLATION_CONTEXT "StringForSize"
24 string_for_size(double size
, char* string
, size_t stringSize
)
26 double kib
= size
/ 1024.0;
28 const char* trKey
= B_TRANSLATE_MARK(
29 "{0, plural, one{# byte} other{# bytes}}");
32 BMessageFormat
format(
33 gSystemCatalog
.GetString(trKey
, B_TRANSLATION_CONTEXT
));
34 format
.Format(tmp
, (int)size
);
36 strlcpy(string
, tmp
.String(), stringSize
);
39 double mib
= kib
/ 1024.0;
41 const char* trKey
= B_TRANSLATE_MARK("%3.2f KiB");
42 snprintf(string
, stringSize
, gSystemCatalog
.GetString(trKey
,
43 B_TRANSLATION_CONTEXT
), kib
);
46 double gib
= mib
/ 1024.0;
48 const char* trKey
= B_TRANSLATE_MARK("%3.2f MiB");
49 snprintf(string
, stringSize
, gSystemCatalog
.GetString(trKey
,
50 B_TRANSLATION_CONTEXT
), mib
);
53 double tib
= gib
/ 1024.0;
55 const char* trKey
= B_TRANSLATE_MARK("%3.2f GiB");
56 snprintf(string
, stringSize
, gSystemCatalog
.GetString(trKey
,
57 B_TRANSLATION_CONTEXT
), gib
);
60 const char* trKey
= B_TRANSLATE_MARK("%.2f TiB");
61 snprintf(string
, stringSize
, gSystemCatalog
.GetString(trKey
,
62 B_TRANSLATION_CONTEXT
), tib
);
67 } // namespace BPrivate