From 7c178559191a9154f2a95a12ae34ba13ccce95fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dancs=C3=B3=20R=C3=B3bert?= Date: Fri, 4 Jan 2013 19:05:33 +0100 Subject: [PATCH] Added localization support for Playground app. Signed-off-by: Humdinger --- src/tests/servers/app/playground/Jamfile | 9 ++- .../servers/app/playground/ObjectView.cpp | 9 ++- .../servers/app/playground/ObjectWindow.cpp | 61 ++++++++++--------- src/tests/servers/app/playground/main.cpp | 7 ++- 4 files changed, 54 insertions(+), 32 deletions(-) diff --git a/src/tests/servers/app/playground/Jamfile b/src/tests/servers/app/playground/Jamfile index 343845d4f95..327085ddec7 100644 --- a/src/tests/servers/app/playground/Jamfile +++ b/src/tests/servers/app/playground/Jamfile @@ -11,7 +11,7 @@ Application Playground : ObjectView.cpp ObjectWindow.cpp States.cpp - : be $(TARGET_LIBSUPC++) + : be $(TARGET_LIBSUPC++) $(HAIKU_LOCALE_LIBS) : Playground.rdef ; @@ -20,3 +20,10 @@ if ( $(TARGET_PLATFORM) = libbe_test ) { : tests!apps ; } +DoCatalogs Playground : + application/x-vnd.Haiku-Playground + : + main.cpp + ObjectView.cpp + ObjectWindow.cpp +; diff --git a/src/tests/servers/app/playground/ObjectView.cpp b/src/tests/servers/app/playground/ObjectView.cpp index 497304ff5e1..932cfc1777d 100644 --- a/src/tests/servers/app/playground/ObjectView.cpp +++ b/src/tests/servers/app/playground/ObjectView.cpp @@ -11,6 +11,11 @@ #include #include #include +// Locale Kit +#include + +#undef B_TRANSLATION_CONTEXT +#define B_TRANSLATION_CONTEXT "Playground" #include "States.h" @@ -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); @@ -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(); diff --git a/src/tests/servers/app/playground/ObjectWindow.cpp b/src/tests/servers/app/playground/ObjectWindow.cpp index 3b9129ba2dc..ca9e90ee4ad 100644 --- a/src/tests/servers/app/playground/ObjectWindow.cpp +++ b/src/tests/servers/app/playground/ObjectWindow.cpp @@ -26,6 +26,11 @@ #include #include #include +// Locale Kit +#include + +#undef B_TRANSLATION_CONTEXT +#define B_TRANSLATION_CONTEXT "Playground" #include "ObjectView.h" #include "States.h" @@ -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); @@ -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(); @@ -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 @@ -197,7 +202,7 @@ 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); @@ -205,72 +210,72 @@ ObjectWindow::ObjectWindow(BRect frame, const char* name) 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(""); + BPopUpMenu* popupMenu = new BPopUpMenu(B_TRANSLATE("")); 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); @@ -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); @@ -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)); @@ -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(); diff --git a/src/tests/servers/app/playground/main.cpp b/src/tests/servers/app/playground/main.cpp index 56121230c57..db3c20287d0 100644 --- a/src/tests/servers/app/playground/main.cpp +++ b/src/tests/servers/app/playground/main.cpp @@ -3,6 +3,11 @@ #include #include +// Locale Kit +#include + +#undef B_TRANSLATION_CONTEXT +#define B_TRANSLATION_CONTEXT "Playground" #include "ObjectWindow.h" @@ -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();