diff --git a/src/add-ons/mail_daemon/inbound_filters/notifier/filter.cpp b/src/add-ons/mail_daemon/inbound_filters/notifier/filter.cpp index d417ed7a7a..1ad15ebb53 100644 --- a/src/add-ons/mail_daemon/inbound_filters/notifier/filter.cpp +++ b/src/add-ons/mail_daemon/inbound_filters/notifier/filter.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -67,15 +68,12 @@ NotifyFilter::MailboxSynced(status_t status) system_beep("New E-mail"); if (fStrategy & alert) { - BString text, numString; - if (fNNewMessages != 1) - text << B_TRANSLATE("You have %num new messages for %name."); - else - text << B_TRANSLATE("You have %num new message for %name."); + BString text; + BMessageFormat().Format(text, B_TRANSLATE( + "You have {0, plural, one{# new message} other{# new messages}} " + "for %account."), fNNewMessages); - numString << fNNewMessages; - text.ReplaceFirst("%num", numString); - text.ReplaceFirst("%name", fMailProtocol.AccountSettings().Name()); + text.ReplaceFirst("%account", fMailProtocol.AccountSettings().Name()); BAlert *alert = new BAlert(B_TRANSLATE("New messages"), text.String(), B_TRANSLATE("OK"), NULL, NULL, B_WIDTH_AS_USUAL); @@ -99,14 +97,10 @@ NotifyFilter::MailboxSynced(status_t status) } if (fStrategy & log_window) { - BString message, numString; - if (fNNewMessages != 1) - message << B_TRANSLATE("%num new messages"); - else - message << B_TRANSLATE("%num new message"); - - numString << fNNewMessages; - message.ReplaceFirst("%num", numString); + BString message; + BMessageFormat().Format(message, B_TRANSLATE( + "{0, plural, one{# new message} other{# new messages}}"), + fNNewMessages); fMailProtocol.ShowMessage(message.String()); } diff --git a/src/apps/aboutsystem/AboutSystem.cpp b/src/apps/aboutsystem/AboutSystem.cpp index ea834d1d37..fd1a68b203 100644 --- a/src/apps/aboutsystem/AboutSystem.cpp +++ b/src/apps/aboutsystem/AboutSystem.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -442,13 +443,10 @@ AboutView::AboutView() B_ALIGN_VERTICAL_UNSET)); // CPU count, type and clock speed - char processorLabel[256]; - if (systemInfo.cpu_count > 1) { - snprintf(processorLabel, sizeof(processorLabel), - B_TRANSLATE("%ld Processors:"), systemInfo.cpu_count); - } else - strlcpy(processorLabel, B_TRANSLATE("Processor:"), - sizeof(processorLabel)); + BString processorLabel; + BMessageFormat().Format(processorLabel, B_TRANSLATE_COMMENT( + "{0, plural, one{Processors:} other{# Processors:}}", + "\"Processor:\" or \"2 Processors:\""), systemInfo.cpu_count); uint32 topologyNodeCount = 0; cpu_topology_node_info* topology = NULL; @@ -550,7 +548,7 @@ AboutView::AboutView() .Add(versionView) .Add(abiView) .AddStrut(offset) - .Add(_CreateLabel("cpulabel", processorLabel)) + .Add(_CreateLabel("cpulabel", processorLabel.String())) .Add(cpuView) .Add(frequencyView) .AddStrut(offset) diff --git a/src/apps/pairs/PairsWindow.cpp b/src/apps/pairs/PairsWindow.cpp index 639d883d51..8a198a277f 100644 --- a/src/apps/pairs/PairsWindow.cpp +++ b/src/apps/pairs/PairsWindow.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -294,17 +295,20 @@ PairsWindow::MessageReceived(BMessage* message) // game end and results if (fFinishPairs == pairsButtonList->CountItems() / 2) { - BString score; - score << fButtonClicks; BString strAbout = B_TRANSLATE("%app%\n" "\twritten by Ralf Schülke\n" "\tCopyright 2008-2010, Haiku Inc.\n" - "\n" - "You completed the game in %num% clicks.\n"); + "\n"); strAbout.ReplaceFirst("%app%", B_TRANSLATE_SYSTEM_NAME("Pairs")); - strAbout.ReplaceFirst("%num%", score); + + // Note: in english the singular form is never used, but other + // languages behave differently. + BMessageFormat().Format(strAbout, B_TRANSLATE( + "You completed the game in " + "{0, plural, one{# click} other{# clicks}}.\n"), + fButtonClicks); BAlert* alert = new BAlert("about", strAbout.String(), diff --git a/src/kits/tracker/CountView.cpp b/src/kits/tracker/CountView.cpp index 711ebde1dc..195ac4f65b 100644 --- a/src/kits/tracker/CountView.cpp +++ b/src/kits/tracker/CountView.cpp @@ -41,6 +41,7 @@ All rights reserved. #include #include #include +#include #include "AutoLock.h" #include "Bitmaps.h" @@ -230,13 +231,11 @@ BCountView::Draw(BRect updateRect) } else { if (fLastCount == 0) itemString << B_TRANSLATE("no items"); - else if (fLastCount == 1) - itemString << B_TRANSLATE("1 item"); else { - itemString.SetTo(B_TRANSLATE("%num items")); - char numString[256]; - snprintf(numString, sizeof(numString), "%" B_PRId32, fLastCount); - itemString.ReplaceFirst("%num", numString); + BMessageFormat().Format(itemString, B_TRANSLATE_COMMENT( + "{0, plural, one{# item} other{# items}}", + "Number of selected items: \"1 item\" or \"2 items\""), + fLastCount); } } diff --git a/src/kits/tracker/InfoWindow.cpp b/src/kits/tracker/InfoWindow.cpp index 37061ece39..0e311e5758 100644 --- a/src/kits/tracker/InfoWindow.cpp +++ b/src/kits/tracker/InfoWindow.cpp @@ -47,6 +47,7 @@ All rights reserved. #include #include #include +#include #include #include #include @@ -675,43 +676,22 @@ void BInfoWindow::GetSizeString(BString &result, off_t size, int32 fileCount) { char sizeBuffer[128]; + BMessageFormat messageFormat; + result << string_for_size((double)size, sizeBuffer, sizeof(sizeBuffer)); - // when we show the byte size, format it with a thousands delimiter - // TODO: use BCountry::FormatNumber if (size >= kKBSize) { - char numStr[128]; - snprintf(numStr, sizeof(numStr), "%" B_PRIdOFF, size); - BString bytes; - - uint32 length = strlen(numStr); - if (length >= 4) { - uint32 charsTillComma = length % 3; - if (charsTillComma == 0) - charsTillComma = 3; - - uint32 numberIndex = 0; - - while (numStr[numberIndex]) { - bytes += numStr[numberIndex++]; - if (--charsTillComma == 0 && numStr[numberIndex]) { - bytes += ','; - charsTillComma = 3; - } - } - } - - result << " " << B_TRANSLATE("(%bytes bytes)"); + result << " "; + messageFormat.Format(result, B_TRANSLATE( + "{0, plural, one{(# byte)} other{(# bytes)}}"), size); // "bytes" translation could come from string_for_size // which could be part of the localekit itself - result.ReplaceFirst("%bytes", bytes); } if (fileCount != 0) { - result << " " << B_TRANSLATE("for %num files"); - BString countString; - countString << fileCount; - result.ReplaceFirst("%num", countString); + result << " "; + messageFormat.Format(result, B_TRANSLATE( + "{0, plural, one{for # file} other{for # files}}"), fileCount); } } diff --git a/src/servers/mail/DeskbarView.cpp b/src/servers/mail/DeskbarView.cpp index eca435cfd0..520c5b9482 100644 --- a/src/servers/mail/DeskbarView.cpp +++ b/src/servers/mail/DeskbarView.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -525,7 +526,7 @@ DeskbarView::_BuildMenu() item = new BMenuItem(path.Leaf(), msg); menu->AddItem(item); - if(entry.InitCheck() != B_OK) + if (entry.InitCheck() != B_OK) item->SetEnabled(false); } if (count > 0) @@ -541,14 +542,10 @@ DeskbarView::_BuildMenu() // The New E-mail query if (fNewMessages > 0) { - BString string, numString; - if (fNewMessages != 1) - string << B_TRANSLATE("%num new messages"); - else - string << B_TRANSLATE("%num new message"); - - numString << fNewMessages; - string.ReplaceFirst("%num", numString); + BString string; + BMessageFormat().Format(string, B_TRANSLATE( + "{0, plural, one{# new message} other{# new messages}}"), + fNewMessages); _GetNewQueryRef(ref); @@ -559,8 +556,7 @@ DeskbarView::_BuildMenu() navMenu->SetNavDir(&ref); menu->AddItem(item); - } - else { + } else { menu->AddItem(item = new BMenuItem(B_TRANSLATE("No new messages"), NULL)); item->SetEnabled(false); diff --git a/src/servers/mail/MailDaemon.cpp b/src/servers/mail/MailDaemon.cpp index 05586c5a5b..f1e5dab4b6 100644 --- a/src/servers/mail/MailDaemon.cpp +++ b/src/servers/mail/MailDaemon.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -175,17 +176,12 @@ MailDaemonApp::ReadyToRun() fQueries.AddItem(query); } - BString string, numString; + BString string; if (fNewMessages > 0) { - if (fNewMessages != 1) - string << B_TRANSLATE("%num new messages."); - else - string << B_TRANSLATE("%num new message."); - - numString << fNewMessages; - string.ReplaceFirst("%num", numString); - } - else + BMessageFormat().Format(string, B_TRANSLATE( + "{0, plural, one{# new message} other{# new messages}}"), + fNewMessages); + } else string = B_TRANSLATE("No new messages"); fCentralBeep = false; @@ -349,15 +345,10 @@ MailDaemonApp::MessageReceived(BMessage* msg) case 'numg': { int32 numMessages = msg->FindInt32("num_messages"); - BString numString; + BMessageFormat().Format(fAlertString, B_TRANSLATE( + "{0, plural, one{# new message} other{# new messages}} " + "for %name\n"), numMessages); - if (numMessages > 1) - fAlertString << B_TRANSLATE("%num new messages for %name\n"); - else - fAlertString << B_TRANSLATE("%num new message for %name\n"); - - numString << numMessages; - fAlertString.ReplaceFirst("%num", numString); fAlertString.ReplaceFirst("%name", msg->FindString("name")); break; } @@ -375,18 +366,13 @@ MailDaemonApp::MessageReceived(BMessage* msg) break; } - BString string, numString; + BString string; if (fNewMessages > 0) { - if (fNewMessages != 1) - string << B_TRANSLATE("%num new messages."); - else - string << B_TRANSLATE("%num new message."); - - numString << fNewMessages; - string.ReplaceFirst("%num", numString); - } - else + BMessageFormat().Format(string, B_TRANSLATE( + "{0, plural, one{# new message.} other{# new messages.}}"), + fNewMessages); + } else string << B_TRANSLATE("No new messages."); fNotification->SetTitle(string.String());