diff --git a/src/add-ons/tracker/zipomatic/ZipOMatic.cpp b/src/add-ons/tracker/zipomatic/ZipOMatic.cpp index 254c311208..44ad6b50fa 100644 --- a/src/add-ons/tracker/zipomatic/ZipOMatic.cpp +++ b/src/add-ons/tracker/zipomatic/ZipOMatic.cpp @@ -10,6 +10,7 @@ #include "ZipOMatic.h" #include +#include #include #include @@ -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, diff --git a/src/apps/diskusage/InfoWindow.cpp b/src/apps/diskusage/InfoWindow.cpp index c44460201a..5508dab2f7 100644 --- a/src/apps/diskusage/InfoWindow.cpp +++ b/src/apps/diskusage/InfoWindow.cpp @@ -17,6 +17,7 @@ #include #include +#include #include #include #include @@ -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); diff --git a/src/apps/diskusage/StatusView.cpp b/src/apps/diskusage/StatusView.cpp index 0aa817f7f7..e1aa911df6 100644 --- a/src/apps/diskusage/StatusView.cpp +++ b/src/apps/diskusage/StatusView.cpp @@ -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); diff --git a/src/apps/mediaconverter/MediaConverterApp.cpp b/src/apps/mediaconverter/MediaConverterApp.cpp index fc07713fad..bb6d55223c 100644 --- a/src/apps/mediaconverter/MediaConverterApp.cpp +++ b/src/apps/mediaconverter/MediaConverterApp.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -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) ? diff --git a/src/apps/mediaconverter/MediaFileInfo.cpp b/src/apps/mediaconverter/MediaFileInfo.cpp index 0dd1b5e1dc..d5aa4f2ab8 100644 --- a/src/apps/mediaconverter/MediaFileInfo.cpp +++ b/src/apps/mediaconverter/MediaFileInfo.cpp @@ -9,6 +9,7 @@ #include #include +#include #include #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; } diff --git a/src/apps/mediaplayer/InfoWin.cpp b/src/apps/mediaplayer/InfoWin.cpp index 62919de9e6..a06668841c 100644 --- a/src/apps/mediaplayer/InfoWin.cpp +++ b/src/apps/mediaplayer/InfoWin.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -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]; diff --git a/src/apps/showimage/ShowImageWindow.cpp b/src/apps/showimage/ShowImageWindow.cpp index 077194360e..4b1fe4605f 100644 --- a/src/apps/showimage/ShowImageWindow.cpp +++ b/src/apps/showimage/ShowImageWindow.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -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); } diff --git a/src/apps/webpositive/DownloadProgressView.cpp b/src/apps/webpositive/DownloadProgressView.cpp index 1ab36907a1..abb29323b8 100644 --- a/src/apps/webpositive/DownloadProgressView.cpp +++ b/src/apps/webpositive/DownloadProgressView.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #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 = "("; diff --git a/src/kits/shared/StringForSize.cpp b/src/kits/shared/StringForSize.cpp index f7f5d26881..2672a8e450 100644 --- a/src/kits/shared/StringForSize.cpp +++ b/src/kits/shared/StringForSize.cpp @@ -7,6 +7,7 @@ #include +#include #include 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; diff --git a/src/kits/tracker/FSUtils.cpp b/src/kits/tracker/FSUtils.cpp index 01af1d871e..d21083281f 100644 --- a/src/kits/tracker/FSUtils.cpp +++ b/src/kits/tracker/FSUtils.cpp @@ -58,6 +58,7 @@ respective holders. All rights reserved. #include #include #include +#include #include #include #include @@ -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); } diff --git a/src/kits/tracker/WidgetAttributeText.cpp b/src/kits/tracker/WidgetAttributeText.cpp index 7e4a7c2f4f..6e24632921 100644 --- a/src/kits/tracker/WidgetAttributeText.cpp +++ b/src/kits/tracker/WidgetAttributeText.cpp @@ -49,6 +49,7 @@ All rights reserved. #include #include #include +#include #include #include #include @@ -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 { diff --git a/src/preferences/screen/AlertView.cpp b/src/preferences/screen/AlertView.cpp index a6567d4b8f..7d50749b85 100644 --- a/src/preferences/screen/AlertView.cpp +++ b/src/preferences/screen/AlertView.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -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()); }