More uses of BMessageFormat
ZipOMatic, DiskUsage, MediaConverter, MediaPlayer, ShowImage, WebPositive, Screen preferences, Tracker, string_for_size. Thanks to KapiX for reporting those!
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
#include "ZipOMatic.h"
|
||||
|
||||
#include <Alert.h>
|
||||
#include <MessageFormat.h>
|
||||
#include <Roster.h>
|
||||
#include <TrackerAddOnAppLaunch.h>
|
||||
|
||||
@@ -153,13 +154,15 @@ ZipOMatic::QuitRequested(void)
|
||||
// The multi-zipper case differs from the single-zipper case
|
||||
// in that zippers are not paused while the BAlert is up.
|
||||
|
||||
BString question;
|
||||
question << B_TRANSLATE("You have %ld Zip-O-Matic running.\n\n");
|
||||
question << B_TRANSLATE("Do you want to stop them?");
|
||||
static BMessageFormat format(
|
||||
B_TRANSLATE("You have {0, plural, one{# Zip-O-Matic} "
|
||||
"other{# Zip-O-Matics}} running.\n\n"));
|
||||
|
||||
BString temp;
|
||||
temp << zippoCount;
|
||||
question.ReplaceFirst("%ld", temp.String());
|
||||
BString question;
|
||||
|
||||
format.Format(question, zippoCount);
|
||||
|
||||
question << B_TRANSLATE("Do you want to stop them?");
|
||||
|
||||
BAlert* alert = new BAlert(NULL, question.String(),
|
||||
B_TRANSLATE("Stop them"), B_TRANSLATE("Let them continue"), NULL,
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include <Catalog.h>
|
||||
#include <MessageFormat.h>
|
||||
#include <StringForSize.h>
|
||||
#include <StringView.h>
|
||||
#include <Bitmap.h>
|
||||
@@ -77,31 +78,36 @@ InfoWin::InfoWin(BPoint p, FileInfo *f, BWindow* parent)
|
||||
Item item;
|
||||
|
||||
// Size
|
||||
char name[B_PATH_NAME_LENGTH] = { 0 };
|
||||
string_for_size(f->size, name, sizeof(name));
|
||||
BString name;
|
||||
if (f->count > 0) {
|
||||
// This is a directory.
|
||||
char str[64];
|
||||
snprintf(str, sizeof(str), B_TRANSLATE(" in %d files"),
|
||||
f->count);
|
||||
strlcat(name, str, sizeof(name));
|
||||
}
|
||||
info.push_back(Item(B_TRANSLATE_MARK("Size"), name));
|
||||
// This is a directory, include file count information
|
||||
static BMessageFormat format(B_TRANSLATE(
|
||||
"%size% in {0, plural, one{# file} other{# files}"));
|
||||
|
||||
format.Format(name, f->count);
|
||||
} else
|
||||
name = "%size%";
|
||||
|
||||
char tmp[B_PATH_NAME_LENGTH] = { 0 };
|
||||
string_for_size(f->size, tmp, sizeof(tmp));
|
||||
name.ReplaceFirst("%size%", tmp);
|
||||
|
||||
info.push_back(Item(B_TRANSLATE_MARK("Size"), name.String()));
|
||||
|
||||
// Created & modified dates
|
||||
BEntry entry(&f->ref);
|
||||
time_t t;
|
||||
entry.GetCreationTime(&t);
|
||||
strftime(name, 64, B_TRANSLATE("%a, %d %b %Y, %r"), localtime(&t));
|
||||
info.push_back(Item(B_TRANSLATE("Created"), name));
|
||||
strftime(tmp, 64, B_TRANSLATE("%a, %d %b %Y, %r"), localtime(&t));
|
||||
info.push_back(Item(B_TRANSLATE("Created"), tmp));
|
||||
entry.GetModificationTime(&t);
|
||||
strftime(name, 64, B_TRANSLATE("%a, %d %b %Y, %r"), localtime(&t));
|
||||
info.push_back(Item(B_TRANSLATE("Modified"), name));
|
||||
strftime(tmp, 64, B_TRANSLATE("%a, %d %b %Y, %r"), localtime(&t));
|
||||
info.push_back(Item(B_TRANSLATE("Modified"), tmp));
|
||||
|
||||
// Kind
|
||||
BMimeType* type = f->Type();
|
||||
type->GetShortDescription(name);
|
||||
info.push_back(Item(B_TRANSLATE("Kind"), name));
|
||||
type->GetShortDescription(tmp);
|
||||
info.push_back(Item(B_TRANSLATE("Kind"), tmp));
|
||||
delete type;
|
||||
|
||||
// Path
|
||||
@@ -127,15 +133,15 @@ InfoWin::InfoWin(BPoint p, FileInfo *f, BWindow* parent)
|
||||
float rightWidth = 0.0;
|
||||
InfoList::iterator i = info.begin();
|
||||
while (i != info.end()) {
|
||||
float w = smallFont.StringWidth((*i).first.c_str()) +
|
||||
2.0 * kSmallHMargin;
|
||||
float w = smallFont.StringWidth((*i).first.c_str())
|
||||
+ 2.0 * kSmallHMargin;
|
||||
leftWidth = max_c(leftWidth, w);
|
||||
w = smallFont.StringWidth((*i).second.c_str()) + 2.0 * kSmallHMargin;
|
||||
rightWidth = max_c(rightWidth, w);
|
||||
i++;
|
||||
}
|
||||
|
||||
float winHeight = 32.0 + 4.0 * kSmallVMargin + 5.0 * (fontHeight
|
||||
float winHeight = 32.0 + 4.0 * kSmallVMargin + 5.0 * (fontHeight
|
||||
+ kSmallVMargin);
|
||||
float winWidth = leftWidth + rightWidth;
|
||||
ResizeTo(winWidth, winHeight);
|
||||
|
||||
@@ -46,7 +46,8 @@ StatusView::StatusView()
|
||||
B_SIZE_UNSET));
|
||||
|
||||
char testLabel[256];
|
||||
snprintf(testLabel, sizeof(testLabel), B_TRANSLATE("%d files"),
|
||||
snprintf(testLabel, sizeof(testLabel), B_TRANSLATE_COMMENT("%d files",
|
||||
"For UI layouting only, use the longest plural form for your language"),
|
||||
999999);
|
||||
|
||||
fCountView = new BStringView(NULL, kEmptyStr);
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include <Locale.h>
|
||||
#include <MediaFile.h>
|
||||
#include <MediaTrack.h>
|
||||
#include <MessageFormat.h>
|
||||
#include <Mime.h>
|
||||
#include <Path.h>
|
||||
#include <String.h>
|
||||
@@ -130,17 +131,10 @@ MediaConverterApp::RefsReceived(BMessage* msg)
|
||||
|
||||
if (errors) {
|
||||
BString alertText;
|
||||
if (errors > 1) {
|
||||
alertText = B_TRANSLATE(
|
||||
"%amountOfFiles files were not recognized"
|
||||
" as supported media files:");
|
||||
BString amount;
|
||||
amount << errors;
|
||||
alertText.ReplaceAll("%amountOfFiles", amount);
|
||||
} else {
|
||||
alertText = B_TRANSLATE(
|
||||
"The file was not recognized as a supported media file:");
|
||||
}
|
||||
static BMessageFormat format(B_TRANSLATE("{0, plural, "
|
||||
"one{The file was not recognized as a supported media file:} "
|
||||
"other{# files were not recognized as supported media files:}}"));
|
||||
format.Format(alertText, errors);
|
||||
|
||||
alertText << "\n" << errorFiles;
|
||||
BAlert* alert = new BAlert((errors > 1) ?
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
#include <Catalog.h>
|
||||
#include <MediaTrack.h>
|
||||
#include <MessageFormat.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#undef B_TRANSLATION_CONTEXT
|
||||
@@ -26,7 +27,7 @@ MediaFileInfo::LoadInfo(BMediaFile* file)
|
||||
_Reset();
|
||||
if (!file)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
|
||||
BMediaTrack* track;
|
||||
media_format format;
|
||||
memset(&format, 0, sizeof(format));
|
||||
@@ -52,6 +53,9 @@ MediaFileInfo::LoadInfo(BMediaFile* file)
|
||||
if (ret != B_OK)
|
||||
return ret;
|
||||
|
||||
static BMessageFormat frameFormat(B_TRANSLATE(
|
||||
"{0, plural, one{# frame} other{# frames}}"));
|
||||
|
||||
if (format.IsVideo()) {
|
||||
memset(&format, 0, sizeof(format));
|
||||
format.type = B_MEDIA_RAW_VIDEO;
|
||||
@@ -71,12 +75,14 @@ MediaFileInfo::LoadInfo(BMediaFile* file)
|
||||
videoFrames = track->CountFrames();
|
||||
|
||||
BString details;
|
||||
snprintf(details.LockBuffer(256), 256,
|
||||
B_TRANSLATE_COMMENT("%u x %u, %.2ffps / %Ld frames",
|
||||
"Width x Height, fps / frames"),
|
||||
format.Width(), format.Height(),
|
||||
rvf->field_rate / rvf->interlace, videoFrames);
|
||||
details.UnlockBuffer();
|
||||
details.SetToFormat(
|
||||
B_TRANSLATE_COMMENT("%u x %u, %.2ffps", "Width x Height, fps"),
|
||||
format.Width(), format.Height(),
|
||||
rvf->field_rate / rvf->interlace);
|
||||
|
||||
details << " / ";
|
||||
frameFormat.Format(details, videoFrames);
|
||||
|
||||
video.details << details;
|
||||
videoDone = true;
|
||||
|
||||
@@ -91,14 +97,17 @@ MediaFileInfo::LoadInfo(BMediaFile* file)
|
||||
|
||||
BString details;
|
||||
if (bytesPerSample == 1 || bytesPerSample == 2) {
|
||||
snprintf(details.LockBuffer(16), 16,
|
||||
B_TRANSLATE("%d bit "), bytesPerSample * 8);
|
||||
static BMessageFormat bitFormat(
|
||||
B_TRANSLATE("{0, plural, one{# bit} other{# bits}}"));
|
||||
bitFormat.Format(details, bytesPerSample * 8);
|
||||
details.SetToFormat(B_TRANSLATE("%d bit "), bytesPerSample * 8);
|
||||
} else {
|
||||
snprintf(details.LockBuffer(16), 16,
|
||||
B_TRANSLATE("%d byte "), bytesPerSample);
|
||||
static BMessageFormat bitFormat(
|
||||
B_TRANSLATE("{0, plural, one{# byte} other{# bytes}}"));
|
||||
bitFormat.Format(details, bytesPerSample);
|
||||
}
|
||||
details.UnlockBuffer();
|
||||
audio.details << details;
|
||||
audio.details << " ";
|
||||
|
||||
ret = track->GetCodecInfo(&codecInfo);
|
||||
if (ret != B_OK)
|
||||
@@ -109,19 +118,19 @@ MediaFileInfo::LoadInfo(BMediaFile* file)
|
||||
audioFrames = track->CountFrames();
|
||||
BString channels;
|
||||
if (raf->channel_count == 1) {
|
||||
snprintf(channels.LockBuffer(64), 64,
|
||||
B_TRANSLATE("%.1f kHz mono / %lld frames"),
|
||||
raf->frame_rate / 1000.f, audioFrames);
|
||||
channels.SetToFormat(B_TRANSLATE("%.1f kHz mono"),
|
||||
raf->frame_rate / 1000.f);
|
||||
} else if (raf->channel_count == 2) {
|
||||
snprintf(channels.LockBuffer(64), 64,
|
||||
B_TRANSLATE("%.1f kHz stereo / %lld frames"),
|
||||
raf->frame_rate / 1000.f, audioFrames);
|
||||
channels.SetToFormat(B_TRANSLATE("%.1f kHz stereo"),
|
||||
raf->frame_rate / 1000.f);
|
||||
} else {
|
||||
snprintf(channels.LockBuffer(64), 64,
|
||||
B_TRANSLATE("%.1f kHz %ld channel / %lld frames"),
|
||||
raf->frame_rate / 1000.f, raf->channel_count, audioFrames);
|
||||
channels.SetToFormat(B_TRANSLATE("%.1f kHz %ld channel"),
|
||||
raf->frame_rate / 1000.f, raf->channel_count);
|
||||
}
|
||||
channels.UnlockBuffer();
|
||||
|
||||
channels << " / ";
|
||||
frameFormat.Format(channels, audioFrames);
|
||||
|
||||
audio.details << channels;
|
||||
|
||||
audioDone = true;
|
||||
@@ -133,7 +142,7 @@ MediaFileInfo::LoadInfo(BMediaFile* file)
|
||||
|
||||
useconds = MAX(audioDuration, videoDuration);
|
||||
duration << (int32)(useconds / 1000000)
|
||||
<< B_TRANSLATE(" seconds");
|
||||
<< B_TRANSLATE(" seconds");
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include <Catalog.h>
|
||||
#include <Debug.h>
|
||||
#include <MediaDefs.h>
|
||||
#include <MessageFormat.h>
|
||||
#include <Mime.h>
|
||||
#include <NodeInfo.h>
|
||||
#include <String.h>
|
||||
@@ -385,16 +386,11 @@ printf("InfoWin::Update(0x%08" B_PRIx32 ")\n", which);
|
||||
bitsPerSample);
|
||||
s << bitString << " ";
|
||||
}
|
||||
if (channelCount == 1)
|
||||
s << B_TRANSLATE("Mono");
|
||||
else if (channelCount == 2)
|
||||
s << B_TRANSLATE("Stereo");
|
||||
else {
|
||||
char channelString[20];
|
||||
snprintf(channelString, sizeof(channelString),
|
||||
B_TRANSLATE("%d Channels"), channelCount);
|
||||
s << channelString;
|
||||
}
|
||||
|
||||
static BMessageFormat channelFormat(B_TRANSLATE(
|
||||
"{0, plural, =1{Mono} =2{Stereo} other{# Channels}}"));
|
||||
channelFormat.Format(s, channelCount);
|
||||
|
||||
s << ", ";
|
||||
if (sr > 0.0) {
|
||||
char rateString[20];
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include <Button.h>
|
||||
#include <Catalog.h>
|
||||
#include <Clipboard.h>
|
||||
#include <DurationFormat.h>
|
||||
#include <Entry.h>
|
||||
#include <File.h>
|
||||
#include <FilePanel.h>
|
||||
@@ -317,11 +318,10 @@ ShowImageWindow::_BuildViewMenu(BMenu* menu, bool popupMenu)
|
||||
|
||||
int32 kDelays[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 20};
|
||||
for (uint32 i = 0; i < sizeof(kDelays) / sizeof(kDelays[0]); i++) {
|
||||
BString text(B_TRANSLATE_COMMENT("%SECONDS seconds",
|
||||
"Don't translate %SECONDS"));
|
||||
char seconds[32];
|
||||
snprintf(seconds, sizeof(seconds), "%" B_PRIi32, kDelays[i]);
|
||||
text.ReplaceFirst("%SECONDS", seconds);
|
||||
BString text;
|
||||
BDurationFormat format;
|
||||
text.Truncate(0);
|
||||
format.Format(text, 0, kDelays[i] * 1000000LL);
|
||||
|
||||
_AddDelayItem(delayMenu, text.String(), kDelays[i] * 1000000LL);
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include <SpaceLayoutItem.h>
|
||||
#include <StatusBar.h>
|
||||
#include <StringView.h>
|
||||
#include <TimeUnitFormat.h>
|
||||
|
||||
#include "BrowserWindow.h"
|
||||
#include "WebDownload.h"
|
||||
@@ -796,38 +797,36 @@ DownloadProgressView::_UpdateStatusText()
|
||||
finishTime -= now;
|
||||
time = gmtime(&finishTime);
|
||||
|
||||
BTimeUnitFormat timeFormat;
|
||||
|
||||
BString buffer2;
|
||||
if (finishTime > secondsPerDay) {
|
||||
int64 days = finishTime / secondsPerDay;
|
||||
if (days == 1)
|
||||
buffer2 << B_TRANSLATE("Over 1 day left");
|
||||
else {
|
||||
buffer2 << B_TRANSLATE("Over %days days left");
|
||||
buffer2.ReplaceFirst("%days", BString() << days);
|
||||
}
|
||||
|
||||
BString time;
|
||||
timeFormat.Format(time, days, B_TIME_UNIT_DAY);
|
||||
|
||||
buffer2 << B_TRANSLATE("Over %days left");
|
||||
buffer2.ReplaceFirst("%days", time);
|
||||
} else if (finishTime > 60 * 60) {
|
||||
int64 hours = finishTime / (60 * 60);
|
||||
if (hours == 1)
|
||||
buffer2 << B_TRANSLATE("Over 1 hour left");
|
||||
else {
|
||||
buffer2 << B_TRANSLATE("Over %hours hours left");
|
||||
buffer2.ReplaceFirst("%hours", BString() << hours);
|
||||
}
|
||||
BString time;
|
||||
timeFormat.Format(time, hours, B_TIME_UNIT_HOUR);
|
||||
|
||||
buffer2 << B_TRANSLATE("Over %hours left");
|
||||
buffer2.ReplaceFirst("%hours", time);
|
||||
} else if (finishTime > 60) {
|
||||
int64 minutes = finishTime / 60;
|
||||
if (minutes == 1)
|
||||
buffer2 << B_TRANSLATE("Over 1 minute left");
|
||||
else {
|
||||
buffer2 << B_TRANSLATE("%minutes minutes");
|
||||
buffer2.ReplaceFirst("%minutes", BString() << minutes);
|
||||
}
|
||||
else
|
||||
timeFormat.Format(buffer2, minutes, B_TIME_UNIT_MINUTE);
|
||||
} else {
|
||||
if (finishTime == 1)
|
||||
buffer2 << B_TRANSLATE("1 second left");
|
||||
else {
|
||||
buffer2 << B_TRANSLATE("%seconds seconds left");
|
||||
buffer2.ReplaceFirst("%seconds", BString() << finishTime);
|
||||
}
|
||||
BString time;
|
||||
timeFormat.Format(time, finishTime, B_TIME_UNIT_SECOND);
|
||||
|
||||
buffer2 << B_TRANSLATE("%seconds left");
|
||||
buffer2.ReplaceFirst("%seconds", time);
|
||||
}
|
||||
|
||||
buffer = "(";
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <MessageFormat.h>
|
||||
#include <SystemCatalog.h>
|
||||
|
||||
using BPrivate::gSystemCatalog;
|
||||
@@ -24,9 +25,15 @@ string_for_size(double size, char* string, size_t stringSize)
|
||||
{
|
||||
double kib = size / 1024.0;
|
||||
if (kib < 1.0) {
|
||||
const char* trKey = B_TRANSLATE_MARK("%d bytes");
|
||||
snprintf(string, stringSize, gSystemCatalog.GetString(trKey,
|
||||
B_TRANSLATION_CONTEXT), (int)size);
|
||||
const char* trKey = B_TRANSLATE_MARK(
|
||||
"{0, plural, one{# byte} other{# bytes}");
|
||||
|
||||
BString tmp;
|
||||
BMessageFormat format(
|
||||
gSystemCatalog.GetString(trKey, B_TRANSLATION_CONTEXT));
|
||||
format.Format(tmp, (int)size);
|
||||
|
||||
strlcpy(string, tmp.String(), stringSize);
|
||||
return string;
|
||||
}
|
||||
double mib = kib / 1024.0;
|
||||
|
||||
@@ -58,6 +58,7 @@ respective holders. All rights reserved.
|
||||
#include <Entry.h>
|
||||
#include <FindDirectory.h>
|
||||
#include <Locale.h>
|
||||
#include <MessageFormat.h>
|
||||
#include <NodeInfo.h>
|
||||
#include <Path.h>
|
||||
#include <Roster.h>
|
||||
@@ -2051,10 +2052,13 @@ FileStatToString(StatStruct* stat, char* buffer, int32 length)
|
||||
tm timeData;
|
||||
localtime_r(&stat->st_mtime, &timeData);
|
||||
|
||||
BString size;
|
||||
static BMessageFormat format(
|
||||
B_TRANSLATE("{0, plural, one{# byte} other{# bytes}}"));
|
||||
format.Format(size, stat->st_size);
|
||||
uint32 pos = snprintf(buffer, length, "\n\t(%s ", size.String());
|
||||
|
||||
uint32 pos = sprintf(buffer,
|
||||
B_TRANSLATE("\n\t(%Ld bytes, "), stat->st_size);
|
||||
strftime(buffer + pos, length - pos,"%b %d %Y, %I:%M:%S %p)", &timeData);
|
||||
strftime(buffer + pos, length - pos, "%b %d %Y, %I:%M:%S %p)", &timeData);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -49,6 +49,7 @@ All rights reserved.
|
||||
#include <DateTimeFormat.h>
|
||||
#include <Debug.h>
|
||||
#include <Locale.h>
|
||||
#include <MessageFormat.h>
|
||||
#include <NodeInfo.h>
|
||||
#include <Path.h>
|
||||
#include <TextView.h>
|
||||
@@ -105,7 +106,9 @@ TruncFileSizeBase(BString* outString, int64 value, const View* view,
|
||||
*outString = "-";
|
||||
return view->StringWidth("-");
|
||||
} else if (value < kKBSize) {
|
||||
buffer.SetToFormat(B_TRANSLATE("%Ld bytes"), value);
|
||||
static BMessageFormat format(B_TRANSLATE(
|
||||
"{0, plural, one{# byte} other{# bytes}}"));
|
||||
format.Format(buffer, value);
|
||||
if (view->StringWidth(buffer.String()) > width)
|
||||
buffer.SetToFormat(B_TRANSLATE("%Ld B"), value);
|
||||
} else {
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include <Catalog.h>
|
||||
#include <StringView.h>
|
||||
#include <String.h>
|
||||
#include <TimeUnitFormat.h>
|
||||
|
||||
#include <IconUtils.h>
|
||||
#include <FindDirectory.h>
|
||||
@@ -134,8 +135,13 @@ void
|
||||
AlertView::UpdateCountdownView()
|
||||
{
|
||||
BString string;
|
||||
string = B_TRANSLATE("Settings will revert in %seconds seconds.");
|
||||
string.ReplaceFirst("%seconds", BString() << fSeconds);
|
||||
string = B_TRANSLATE("Settings will revert in %seconds.");
|
||||
|
||||
BTimeUnitFormat format;
|
||||
BString tmp;
|
||||
format.Format(tmp, fSeconds, B_TIME_UNIT_SECOND);
|
||||
|
||||
string.ReplaceFirst("%seconds", tmp);
|
||||
fCountdownView->SetText(string.String());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user