Start making use of BMessageFormat.
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
#include <Beep.h>
|
||||
#include <Catalog.h>
|
||||
#include <Message.h>
|
||||
#include <MessageFormat.h>
|
||||
#include <Path.h>
|
||||
#include <String.h>
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include <Font.h>
|
||||
#include <fs_attr.h>
|
||||
#include <LayoutBuilder.h>
|
||||
#include <MessageFormat.h>
|
||||
#include <MessageRunner.h>
|
||||
#include <Messenger.h>
|
||||
#include <OS.h>
|
||||
@@ -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)
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include <Menu.h>
|
||||
#include <MenuBar.h>
|
||||
#include <MenuItem.h>
|
||||
#include <MessageFormat.h>
|
||||
#include <MessageRunner.h>
|
||||
#include <String.h>
|
||||
#include <TextView.h>
|
||||
@@ -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(),
|
||||
|
||||
@@ -41,6 +41,7 @@ All rights reserved.
|
||||
#include <Catalog.h>
|
||||
#include <ControlLook.h>
|
||||
#include <Locale.h>
|
||||
#include <MessageFormat.h>
|
||||
|
||||
#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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -47,6 +47,7 @@ All rights reserved.
|
||||
#include <Font.h>
|
||||
#include <Locale.h>
|
||||
#include <MenuField.h>
|
||||
#include <MessageFormat.h>
|
||||
#include <Mime.h>
|
||||
#include <NodeInfo.h>
|
||||
#include <NodeMonitor.h>
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include <kernel/fs_info.h>
|
||||
#include <kernel/fs_index.h>
|
||||
#include <MenuItem.h>
|
||||
#include <MessageFormat.h>
|
||||
#include <Messenger.h>
|
||||
#include <NodeInfo.h>
|
||||
#include <NodeMonitor.h>
|
||||
@@ -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);
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include <FindDirectory.h>
|
||||
#include <fs_index.h>
|
||||
#include <IconUtils.h>
|
||||
#include <MessageFormat.h>
|
||||
#include <NodeMonitor.h>
|
||||
#include <Notification.h>
|
||||
#include <Path.h>
|
||||
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user