Skip to content

Commit

Permalink
Added localization support for Playground app.
Browse files Browse the repository at this point in the history
Signed-off-by: Humdinger <humdingerb@gmail.com>
  • Loading branch information
Dancsó Róbert authored and Humdinger committed Jan 7, 2013
1 parent 0423443 commit 7c17855
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 32 deletions.
9 changes: 8 additions & 1 deletion src/tests/servers/app/playground/Jamfile
Expand Up @@ -11,7 +11,7 @@ Application Playground :
ObjectView.cpp
ObjectWindow.cpp
States.cpp
: be $(TARGET_LIBSUPC++)
: be $(TARGET_LIBSUPC++) $(HAIKU_LOCALE_LIBS)
: Playground.rdef
;

Expand All @@ -20,3 +20,10 @@ if ( $(TARGET_PLATFORM) = libbe_test ) {
: tests!apps ;
}

DoCatalogs Playground :
application/x-vnd.Haiku-Playground
:
main.cpp
ObjectView.cpp
ObjectWindow.cpp
;
9 changes: 7 additions & 2 deletions src/tests/servers/app/playground/ObjectView.cpp
Expand Up @@ -11,6 +11,11 @@
#include <Shape.h>
#include <String.h>
#include <Window.h>
// Locale Kit
#include <Catalog.h>

#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "Playground"

#include "States.h"

Expand Down Expand Up @@ -157,7 +162,7 @@ ObjectView::Draw(BRect updateRect)
SetDrawingMode(B_OP_OVER);
SetHighColor(255, 0, 0, 128);

const char* message = "Click and drag to draw an object";
const char* message = B_TRANSLATE("Click and drag to draw an object");
float width = StringWidth(message);

BPoint p((r.Width() - width) / 2.0, r.Height() / 2.0);
Expand Down Expand Up @@ -341,7 +346,7 @@ if (dragMessage) {
helper->FillRect(r);

helper->SetHighColor(0, 0, 0, 255);
const char* text = "Test";
const char* text = B_TRANSLATE("Test");
float pos = (r.Width() - helper->StringWidth(text)) / 2;
helper->DrawString(text, BPoint(pos, 25));
helper->Sync();
Expand Down
61 changes: 33 additions & 28 deletions src/tests/servers/app/playground/ObjectWindow.cpp
Expand Up @@ -26,6 +26,11 @@
#include <TabView.h>
#include <TextControl.h>
#include <TextView.h>
// Locale Kit
#include <Catalog.h>

#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "Playground"

#include "ObjectView.h"
#include "States.h"
Expand Down Expand Up @@ -126,12 +131,12 @@ ObjectWindow::ObjectWindow(BRect frame, const char* name)
BMenuBar* menuBar = new BMenuBar(b, "menu bar");
AddChild(menuBar);

BMenu* menu = new BMenu("File");
BMenu* menu = new BMenu(B_TRANSLATE("File"));
menuBar->AddItem(menu);

menu->AddItem(new BMenu("Submenu"));
menu->AddItem(new BMenu(B_TRANSLATE("Submenu")));

BMenuItem* menuItem = new BMenuItem("Quit", new BMessage(B_QUIT_REQUESTED),
BMenuItem* menuItem = new BMenuItem(B_TRANSLATE("Quit"), new BMessage(B_QUIT_REQUESTED),
'Q');
menu->AddItem(menuItem);

Expand Down Expand Up @@ -170,7 +175,7 @@ ObjectWindow::ObjectWindow(BRect frame, const char* name)
BBox* controlGroup = new BBox(b, "controls box",
B_FOLLOW_LEFT | B_FOLLOW_TOP_BOTTOM, B_WILL_DRAW, B_FANCY_BORDER);

controlGroup->SetLabel("Controls");
controlGroup->SetLabel(B_TRANSLATE("Controls"));
bg->AddChild(controlGroup);

b = controlGroup->Bounds();
Expand All @@ -180,14 +185,14 @@ ObjectWindow::ObjectWindow(BRect frame, const char* name)
b.right = b.left + b.Width() / 2.0 - 5.0;

// new button
fNewB = new BButton(b, "new button", "New Object",
fNewB = new BButton(b, "new button", B_TRANSLATE("New Object"),
new BMessage(MSG_NEW_OBJECT));
controlGroup->AddChild(fNewB);
SetDefaultButton(fNewB);

// clear button
b.OffsetBy(0, fNewB->Bounds().Height() + 5.0);
fClearB = new BButton(b, "clear button", "Clear", new BMessage(MSG_CLEAR));
fClearB = new BButton(b, "clear button", B_TRANSLATE("Clear"), new BMessage(MSG_CLEAR));
controlGroup->AddChild(fClearB);

// object type radio buttons
Expand All @@ -197,80 +202,80 @@ ObjectWindow::ObjectWindow(BRect frame, const char* name)
b.OffsetBy(0, fClearB->Bounds().Height() + 5.0);
message = new BMessage(MSG_SET_OBJECT_TYPE);
message->AddInt32("type", OBJECT_LINE);
radioButton = new BRadioButton(b, "radio 1", "Line", message);
radioButton = new BRadioButton(b, "radio 1", B_TRANSLATE("Line"), message);
controlGroup->AddChild(radioButton);

radioButton->SetValue(B_CONTROL_ON);

b.OffsetBy(0, radioButton->Bounds().Height() + 5.0);
message = new BMessage(MSG_SET_OBJECT_TYPE);
message->AddInt32("type", OBJECT_RECT);
radioButton = new BRadioButton(b, "radio 2", "Rect", message);
radioButton = new BRadioButton(b, "radio 2", B_TRANSLATE("Rect"), message);
controlGroup->AddChild(radioButton);

b.OffsetBy(0, radioButton->Bounds().Height() + 5.0);
message = new BMessage(MSG_SET_OBJECT_TYPE);
message->AddInt32("type", OBJECT_ROUND_RECT);
radioButton = new BRadioButton(b, "radio 3", "Round Rect", message);
radioButton = new BRadioButton(b, "radio 3", B_TRANSLATE("Round Rect"), message);
controlGroup->AddChild(radioButton);

b.OffsetBy(0, radioButton->Bounds().Height() + 5.0);
message = new BMessage(MSG_SET_OBJECT_TYPE);
message->AddInt32("type", OBJECT_ELLIPSE);
radioButton = new BRadioButton(b, "radio 4", "Ellipse", message);
radioButton = new BRadioButton(b, "radio 4", B_TRANSLATE("Ellipse"), message);
controlGroup->AddChild(radioButton);

// drawing mode
BPopUpMenu* popupMenu = new BPopUpMenu("<pick>");
BPopUpMenu* popupMenu = new BPopUpMenu(B_TRANSLATE("<pick>"));

message = new BMessage(MSG_SET_DRAWING_MODE);
message->AddInt32("mode", B_OP_COPY);
popupMenu->AddItem(new BMenuItem("Copy", message));
popupMenu->AddItem(new BMenuItem(B_TRANSLATE("Copy"), message));

message = new BMessage(MSG_SET_DRAWING_MODE);
message->AddInt32("mode", B_OP_OVER);
popupMenu->AddItem(new BMenuItem("Over", message));
popupMenu->AddItem(new BMenuItem(B_TRANSLATE("Over"), message));

message = new BMessage(MSG_SET_DRAWING_MODE);
message->AddInt32("mode", B_OP_INVERT);
popupMenu->AddItem(new BMenuItem("Invert", message));
popupMenu->AddItem(new BMenuItem(B_TRANSLATE("Invert"), message));

message = new BMessage(MSG_SET_DRAWING_MODE);
message->AddInt32("mode", B_OP_BLEND);
popupMenu->AddItem(new BMenuItem("Blend", message));
popupMenu->AddItem(new BMenuItem(B_TRANSLATE("Blend"), message));

message = new BMessage(MSG_SET_DRAWING_MODE);
message->AddInt32("mode", B_OP_SELECT);
popupMenu->AddItem(new BMenuItem("Select", message));
popupMenu->AddItem(new BMenuItem(B_TRANSLATE("Select"), message));

message = new BMessage(MSG_SET_DRAWING_MODE);
message->AddInt32("mode", B_OP_ERASE);
popupMenu->AddItem(new BMenuItem("Erase", message));
popupMenu->AddItem(new BMenuItem(B_TRANSLATE("Erase"), message));

message = new BMessage(MSG_SET_DRAWING_MODE);
message->AddInt32("mode", B_OP_ADD);
popupMenu->AddItem(new BMenuItem("Add", message));
popupMenu->AddItem(new BMenuItem(B_TRANSLATE("Add"), message));

message = new BMessage(MSG_SET_DRAWING_MODE);
message->AddInt32("mode", B_OP_SUBTRACT);
popupMenu->AddItem(new BMenuItem("Subtract", message));
popupMenu->AddItem(new BMenuItem(B_TRANSLATE("Subtract"), message));

message = new BMessage(MSG_SET_DRAWING_MODE);
message->AddInt32("mode", B_OP_MIN);
popupMenu->AddItem(new BMenuItem("Min", message));
popupMenu->AddItem(new BMenuItem(B_TRANSLATE("Min"), message));

message = new BMessage(MSG_SET_DRAWING_MODE);
message->AddInt32("mode", B_OP_MAX);
popupMenu->AddItem(new BMenuItem("Max", message));
popupMenu->AddItem(new BMenuItem(B_TRANSLATE("Max"), message));

message = new BMessage(MSG_SET_DRAWING_MODE);
message->AddInt32("mode", B_OP_ALPHA);
BMenuItem* item = new BMenuItem("Alpha", message);
BMenuItem* item = new BMenuItem(B_TRANSLATE("Alpha"), message);
item->SetMarked(true);
popupMenu->AddItem(item);

b.OffsetBy(0, radioButton->Bounds().Height() + 10.0);
fDrawingModeMF = new BMenuField(b, "drawing mode field", "Mode:",
fDrawingModeMF = new BMenuField(b, "drawing mode field", B_TRANSLATE("Mode:"),
popupMenu);

controlGroup->AddChild(fDrawingModeMF);
Expand All @@ -286,7 +291,7 @@ ObjectWindow::ObjectWindow(BRect frame, const char* name)

// alpha text control
b.OffsetBy(0, fColorControl-> Bounds().Height() + 5.0);
fAlphaTC = new BTextControl(b, "alpha text control", "Alpha:", "",
fAlphaTC = new BTextControl(b, "alpha text control", B_TRANSLATE("Alpha:"), "",
new BMessage(MSG_SET_COLOR));
controlGroup->AddChild(fAlphaTC);

Expand All @@ -300,14 +305,14 @@ ObjectWindow::ObjectWindow(BRect frame, const char* name)

// fill check box
b.OffsetBy(0, fAlphaTC->Bounds().Height() + 5.0);
fFillCB = new BCheckBox(b, "fill check box", "Fill",
fFillCB = new BCheckBox(b, "fill check box", B_TRANSLATE("Fill"),
new BMessage(MSG_SET_FILL_OR_STROKE));
controlGroup->AddChild(fFillCB);

// pen size text control
b.OffsetBy(0, radioButton->Bounds().Height() + 5.0);
b.bottom = b.top + 10.0;//35;
fPenSizeS = new BSlider(b, "width slider", "Width:", NULL, 1, 100,
fPenSizeS = new BSlider(b, "width slider", B_TRANSLATE("Width:"), NULL, 1, 100,
B_TRIANGLE_THUMB);
fPenSizeS->SetLimitLabels("1", "100");
fPenSizeS->SetModificationMessage(new BMessage(MSG_SET_PEN_SIZE));
Expand Down Expand Up @@ -417,8 +422,8 @@ ObjectWindow::MessageReceived(BMessage* message)
break;
case MSG_CLEAR: {
BAlert *alert = new BAlert("Playground",
"Do you really want to clear all drawing objects?",
"No", "Yes");
B_TRANSLATE("Do you really want to clear all drawing objects?"),
B_TRANSLATE("No"), B_TRANSLATE("Yes"));
if (alert->Go() == 1) {
fObjectView->MakeEmpty();
fObjectLV->MakeEmpty();
Expand Down
7 changes: 6 additions & 1 deletion src/tests/servers/app/playground/main.cpp
Expand Up @@ -3,6 +3,11 @@

#include <Application.h>
#include <Message.h>
// Locale Kit
#include <Catalog.h>

#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "Playground"

#include "ObjectWindow.h"

Expand All @@ -13,7 +18,7 @@ main(int argc, char** argv)
BApplication* app = new BApplication("application/x-vnd.Haiku-Playground");

BRect frame(50.0, 50.0, 600.0, 400.0);
BWindow* window = new ObjectWindow(frame, "Playground");
BWindow* window = new ObjectWindow(frame, B_TRANSLATE_SYSTEM_NAME("Playground"));

window->Show();

Expand Down

0 comments on commit 7c17855

Please sign in to comment.