More uses of BMessageFormat.

This commit is contained in:
Adrien Destugues
2014-10-08 13:17:17 +02:00
parent baf0ed6a7b
commit be93029899
2 changed files with 10 additions and 9 deletions
+5 -4
View File
@@ -17,6 +17,7 @@
#include <Catalog.h> #include <Catalog.h>
#include <Box.h> #include <Box.h>
#include <Button.h> #include <Button.h>
#include <MessageFormat.h>
#include <Node.h> #include <Node.h>
#include <String.h> #include <String.h>
#include <StringForSize.h> #include <StringForSize.h>
@@ -83,7 +84,7 @@ StatusView::StatusView()
.Add(fCountView) .Add(fCountView)
.Add(divider2) .Add(divider2)
.Add(fSizeView) .Add(fSizeView)
.End() .End()
.End() .End()
.AddStrut(kSmallHMargin) .AddStrut(kSmallHMargin)
.Add(fRefreshBtn) .Add(fRefreshBtn)
@@ -150,9 +151,9 @@ StatusView::ShowInfo(const FileInfo* info)
fSizeView->SetText(label); fSizeView->SetText(label);
if (info->count > 0) { if (info->count > 0) {
char label[256]; BString label;
snprintf(label, sizeof(label), (info->count == 1) ? BMessageFormat().Format(label, B_TRANSLATE("{0, plural, one{# file}, "
B_TRANSLATE("%d file") : B_TRANSLATE("%d files"), info->count); "other{# files}}"), info->count);
fCountView->SetText(label); fCountView->SetText(label);
} else { } else {
fCountView->SetText(kEmptyStr); fCountView->SetText(kEmptyStr);
+5 -5
View File
@@ -21,6 +21,7 @@
#include <Locale.h> #include <Locale.h>
#include <MenuItem.h> #include <MenuItem.h>
#include <MenuField.h> #include <MenuField.h>
#include <MessageFormat.h>
#include <Path.h> #include <Path.h>
#include <PopUpMenu.h> #include <PopUpMenu.h>
#include <Screen.h> #include <Screen.h>
@@ -828,17 +829,16 @@ TInfoView::Draw(BRect updateRect)
MovePenTo(10, fFontHeight + 5); MovePenTo(10, fFontHeight + 5);
BString dimensionsInfo( BString dimensionsInfo;
B_TRANSLATE("%width x %height @ %pixelSize pixels/pixel")); BMessageFormat().Format(dimensionsInfo,
B_TRANSLATE("%width x %height @ {0, plural, one{# pixel/pixel} "
"other{# pixels/pixel}}"), pixelSize);
BString rep; BString rep;
rep << hPixelCount; rep << hPixelCount;
dimensionsInfo.ReplaceAll("%width", rep); dimensionsInfo.ReplaceAll("%width", rep);
rep = ""; rep = "";
rep << vPixelCount; rep << vPixelCount;
dimensionsInfo.ReplaceAll("%height", rep); dimensionsInfo.ReplaceAll("%height", rep);
rep = "";
rep << pixelSize;
dimensionsInfo.ReplaceAll("%pixelSize", rep);
invalRect.Set(10, 5, 10 + StringWidth(fInfoStr), fFontHeight+7); invalRect.Set(10, 5, 10 + StringWidth(fInfoStr), fFontHeight+7);
SetHighColor(ViewColor()); SetHighColor(ViewColor());
FillRect(invalRect); FillRect(invalRect);