[haiku-commits] r40874 - haiku/trunk/src/apps/sudoku

  • From: axeld@xxxxxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Tue, 8 Mar 2011 18:40:58 +0100 (CET)

Author: axeld
Date: 2011-03-08 18:40:58 +0100 (Tue, 08 Mar 2011)
New Revision: 40874
Changeset: http://dev.haiku-os.org/changeset/40874

Modified:
   haiku/trunk/src/apps/sudoku/Jamfile
   haiku/trunk/src/apps/sudoku/ProgressWindow.cpp
   haiku/trunk/src/apps/sudoku/Sudoku.cpp
   haiku/trunk/src/apps/sudoku/SudokuGenerator.cpp
   haiku/trunk/src/apps/sudoku/SudokuWindow.cpp
Log:
* Applied patch by Karvjorm that localizes Sudoku - thanks!
* I removed translating the debug output, though. Style fixes come in the next
  commit with the hope for improvement in future patches.


Modified: haiku/trunk/src/apps/sudoku/Jamfile
===================================================================
--- haiku/trunk/src/apps/sudoku/Jamfile 2011-03-08 16:51:29 UTC (rev 40873)
+++ haiku/trunk/src/apps/sudoku/Jamfile 2011-03-08 17:40:58 UTC (rev 40874)
@@ -12,6 +12,20 @@
        SudokuView.cpp
        SudokuWindow.cpp
 
-       : be tracker $(TARGET_LIBSTDC++)
+       : be tracker $(HAIKU_LOCALE_LIBS) $(TARGET_LIBSTDC++)
        : Sudoku.rdef
        ;
+
+DoCatalogs Sudoku :
+    x-vnd.Haiku-Sudoku
+    :
+       ProgressWindow.cpp
+       Sudoku.cpp
+       SudokuGenerator.cpp
+       SudokuWindow.cpp
+;
+
+AddCatalogEntryAttribute Sudoku
+       :
+       x-vnd.Haiku-Sudoku:SudokuWindow:Sudoku
+;

Modified: haiku/trunk/src/apps/sudoku/ProgressWindow.cpp
===================================================================
--- haiku/trunk/src/apps/sudoku/ProgressWindow.cpp      2011-03-08 16:51:29 UTC 
(rev 40873)
+++ haiku/trunk/src/apps/sudoku/ProgressWindow.cpp      2011-03-08 17:40:58 UTC 
(rev 40874)
@@ -8,6 +8,7 @@
 
 #include <Autolock.h>
 #include <Button.h>
+#include <Catalog.h>
 #include <MessageRunner.h>
 #include <Screen.h>
 #include <StatusBar.h>
@@ -15,12 +16,15 @@
 #include <stdio.h>
 
 
+#undef B_TRANSLATE_CONTEXT
+#define B_TRANSLATE_CONTEXT "ProgressWindow"
+
 static const uint32 kMsgShow = 'show';
 
 
 ProgressWindow::ProgressWindow(BWindow* referenceWindow,
                BMessage* abortMessage)
-       : BWindow(BRect(0, 0, 250, 100), "Progress monitor",
+       : BWindow(BRect(0, 0, 250, 100), B_TRANSLATE("Progress monitor"),
                B_MODAL_WINDOW_LOOK, B_FLOATING_APP_WINDOW_FEEL,
                B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS),
        fRunner(NULL)
@@ -41,7 +45,7 @@
 
        if (abortMessage != NULL && referenceWindow) {
                rect.top += height + 8;
-               BButton* button = new BButton(rect, "abort", "Abort",
+               BButton* button = new BButton(rect, "abort", 
B_TRANSLATE("Abort"),
                        abortMessage);
                button->ResizeToPreferred();
                button->MoveBy((rect.Width() - button->Bounds().Width()) / 2, 
0);

Modified: haiku/trunk/src/apps/sudoku/Sudoku.cpp
===================================================================
--- haiku/trunk/src/apps/sudoku/Sudoku.cpp      2011-03-08 16:51:29 UTC (rev 
40873)
+++ haiku/trunk/src/apps/sudoku/Sudoku.cpp      2011-03-08 17:40:58 UTC (rev 
40874)
@@ -12,8 +12,11 @@
 
 #include <Alert.h>
 #include <Application.h>
+#include <Catalog.h>
 #include <TextView.h>
 
+#undef B_TRANSLATE_CONTEXT
+#define B_TRANSLATE_CONTEXT "Sudoku"
 
 const char* kSignature = "application/x-vnd.Haiku-Sudoku";
 
@@ -61,9 +64,9 @@
 void
 Sudoku::DisplayAbout()
 {
-       BAlert *alert = new BAlert("about", "Sudoku\n"
+       BAlert *alert = new BAlert(B_TRANSLATE("About"), B_TRANSLATE("Sudoku\n"
                "\twritten by Axel Dörfler\n"
-               "\tCopyright 2007, Haiku Inc.\n", "OK");
+               "\tCopyright 2007, Haiku Inc.\n"), B_TRANSLATE("OK"));
        BTextView *view = alert->TextView();
        BFont font;
 
@@ -72,8 +75,9 @@
        view->GetFont(&font);
        font.SetSize(18);
        font.SetFace(B_BOLD_FACE);
-       view->SetFontAndColor(0, 6, &font);
-
+       view->SetFontAndColor(0, strlen(B_TRANSLATE("Sudoku")), &font);
+       
+       alert->SetShortcut(0, B_ESCAPE);
        alert->Go();
 }
 

Modified: haiku/trunk/src/apps/sudoku/SudokuGenerator.cpp
===================================================================
--- haiku/trunk/src/apps/sudoku/SudokuGenerator.cpp     2011-03-08 16:51:29 UTC 
(rev 40873)
+++ haiku/trunk/src/apps/sudoku/SudokuGenerator.cpp     2011-03-08 17:40:58 UTC 
(rev 40874)
@@ -10,10 +10,15 @@
 #include "SudokuField.h"
 #include "SudokuSolver.h"
 
+#include <Catalog.h>
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
+#undef B_TRANSLATE_CONTEXT
+#define B_TRANSLATE_CONTEXT "SudokuGenerator"
+
 SudokuGenerator::SudokuGenerator()
 {
 }
@@ -54,7 +59,7 @@
 
        SudokuField field(target->BlockSize());
        uint32 inputCount = field.Size() * field.Size() / 3;
-       _Progress(progress, "Creating solvable field", 5.f);
+       _Progress(progress, B_TRANSLATE("Creating solvable field"), 5.f);
 
        while (!*quit) {
                field.Reset();
@@ -107,7 +112,7 @@
        bool tried[field.Size() * field.Size()];
        int32 tries = field.Size() * field.Size() * 3 / 4;
        memset(tried, 0, sizeof(tried));
-       _Progress(progress, "Searching for removable values", 30.f);
+       _Progress(progress, B_TRANSLATE("Searching for removable values"), 
30.f);
 
        while (!*quit && removeCount > 0 && tries-- > 0) {
                SudokuField copy(field);

Modified: haiku/trunk/src/apps/sudoku/SudokuWindow.cpp
===================================================================
--- haiku/trunk/src/apps/sudoku/SudokuWindow.cpp        2011-03-08 16:51:29 UTC 
(rev 40873)
+++ haiku/trunk/src/apps/sudoku/SudokuWindow.cpp        2011-03-08 17:40:58 UTC 
(rev 40874)
@@ -10,6 +10,7 @@
 
 #include <Alert.h>
 #include <Application.h>
+#include <Catalog.h>
 #include <File.h>
 #include <FilePanel.h>
 #include <FindDirectory.h>
@@ -29,6 +30,9 @@
 #include "SudokuView.h"
 
 
+#undef B_TRANSLATE_CONTEXT
+#define B_TRANSLATE_CONTEXT "SudokuWindow"
+
 const uint32 kMsgOpenFilePanel = 'opfp';
 const uint32 kMsgGenerateSudoku = 'gnsu';
 const uint32 kMsgAbortSudokuGenerator = 'asgn';
@@ -111,7 +115,9 @@
 
        bigtime_t start = system_time();
        generator.Generate(&fField, 40 - fLevel * 5, fProgress, &fQuit);
-       printf("generated in %g msecs\n",
+       printf(B_TRANSLATE_WITH_CONTEXT("generated in %g msecs\n",
+               "When Sudoku is launched from a Terminal window, this message "
+               "is shown there."),
                (system_time() - start) / 1000.0);
 
        BMessage done(kMsgSudokuGenerated);
@@ -138,8 +144,8 @@
 
 
 SudokuWindow::SudokuWindow()
-       : BWindow(BRect(100, 100, 500, 520), "Sudoku", B_TITLED_WINDOW,
-               B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE),
+       : BWindow(BRect(100, 100, 500, 520), B_TRANSLATE("Sudoku"),
+       B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE),
        fGenerator(NULL),
        fStoredState(NULL),
        fExportFormat(kExportAsText)
@@ -189,29 +195,31 @@
        // add menu
 
        // "File" menu
-       BMenu* menu = new BMenu("File");
-       fNewMenu = new BMenu("New");
+       BMenu* menu = new BMenu(B_TRANSLATE("File"));
+       fNewMenu = new BMenu(B_TRANSLATE("New"));
        menu->AddItem(new BMenuItem(fNewMenu, new 
BMessage(kMsgGenerateSudoku)));
        fNewMenu->Superitem()->SetShortcut('N', B_COMMAND_KEY);
 
        BMessage* message = new BMessage(kMsgGenerateSudoku);
        message->AddInt32("level", kEasyLevel);
-       fNewMenu->AddItem(new BMenuItem("Easy", message));
+       fNewMenu->AddItem(new BMenuItem(B_TRANSLATE("Easy"), message));
        message = new BMessage(kMsgGenerateSudoku);
        message->AddInt32("level", kAdvancedLevel);
-       fNewMenu->AddItem(new BMenuItem("Advanced", message));
+       fNewMenu->AddItem(new BMenuItem(B_TRANSLATE("Advanced"), message));
        message = new BMessage(kMsgGenerateSudoku);
        message->AddInt32("level", kHardLevel);
-       fNewMenu->AddItem(new BMenuItem("Hard", message));
+       fNewMenu->AddItem(new BMenuItem(B_TRANSLATE("Hard"), message));
 
        fNewMenu->AddSeparatorItem();
-       fNewMenu->AddItem(new BMenuItem("Blank", new BMessage(kMsgNewBlank)));
+       fNewMenu->AddItem(new BMenuItem(B_TRANSLATE("Blank"),
+               new BMessage(kMsgNewBlank)));
 
-       menu->AddItem(new BMenuItem("Start again", new 
BMessage(kMsgStartAgain)));
+       menu->AddItem(new BMenuItem(B_TRANSLATE("Start again"),
+               new BMessage(kMsgStartAgain)));
        menu->AddSeparatorItem();
        BMenu* recentsMenu = BRecentFilesList::NewFileListMenu(
-               "Open file" B_UTF8_ELLIPSIS, NULL, NULL, this, 10, false, NULL,
-               kSignature);
+               B_TRANSLATE("Open file" B_UTF8_ELLIPSIS), NULL, NULL, this, 10, 
false,
+               NULL, kSignature);
        BMenuItem *item;
        menu->AddItem(item = new BMenuItem(recentsMenu,
                new BMessage(kMsgOpenFilePanel)));
@@ -219,35 +227,38 @@
 
        menu->AddSeparatorItem();
 
-       BMenu* subMenu = new BMenu("Export as" B_UTF8_ELLIPSIS);
+       BMenu* subMenu = new BMenu(B_TRANSLATE("Export as" B_UTF8_ELLIPSIS));
        message = new BMessage(kMsgExportAs);
        message->AddInt32("as", kExportAsText);
-       subMenu->AddItem(new BMenuItem("Text", message));
+       subMenu->AddItem(new BMenuItem(B_TRANSLATE("Text"), message));
        message= new BMessage(kMsgExportAs);
        message->AddInt32("as", kExportAsHTML);
-       subMenu->AddItem(new BMenuItem("HTML", message));
+       subMenu->AddItem(new BMenuItem(B_TRANSLATE("HTML"), message));
        menu->AddItem(subMenu);
 
-       menu->AddItem(item = new BMenuItem("Copy", new BMessage(B_COPY), 'C'));
+       menu->AddItem(item = new BMenuItem(B_TRANSLATE("Copy"),
+               new BMessage(B_COPY), 'C'));
 
        menu->AddSeparatorItem();
 
-       menu->AddItem(item = new BMenuItem("About Sudoku" B_UTF8_ELLIPSIS,
+       menu->AddItem(item = new BMenuItem(
+               B_TRANSLATE("About Sudoku" B_UTF8_ELLIPSIS),
                new BMessage(B_ABOUT_REQUESTED)));
        menu->AddSeparatorItem();
 
-       menu->AddItem(new BMenuItem("Quit", new BMessage(B_QUIT_REQUESTED), 
'Q'));
+       menu->AddItem(new BMenuItem(B_TRANSLATE("Quit"),
+               new BMessage(B_QUIT_REQUESTED), 'Q'));
        menu->SetTargetForItems(this);
        item->SetTarget(be_app);
        menuBar->AddItem(menu);
 
        // "View" menu
-       menu = new BMenu("View");
-       menu->AddItem(item = new BMenuItem("Mark invalid values",
+       menu = new BMenu(B_TRANSLATE("View"));
+       menu->AddItem(item = new BMenuItem(B_TRANSLATE("Mark invalid values"),
                new BMessage(kMsgMarkInvalid)));
        if ((fSudokuView->HintFlags() & kMarkInvalid) != 0)
                item->SetMarked(true);
-       menu->AddItem(item = new BMenuItem("Mark valid hints",
+       menu->AddItem(item = new BMenuItem(B_TRANSLATE("Mark valid hints"),
                new BMessage(kMsgMarkValidHints)));
        if ((fSudokuView->HintFlags() & kMarkValidHints) != 0)
                item->SetMarked(true);
@@ -255,23 +266,27 @@
        menuBar->AddItem(menu);
 
        // "Help" menu
-       menu = new BMenu("Help");
-       menu->AddItem(fUndoItem = new BMenuItem("Undo", new BMessage(B_UNDO), 
'Z'));
+       menu = new BMenu(B_TRANSLATE("Help"));
+       menu->AddItem(fUndoItem = new BMenuItem(B_TRANSLATE("Undo"),
+               new BMessage(B_UNDO), 'Z'));
        fUndoItem->SetEnabled(false);
-       menu->AddItem(fRedoItem = new BMenuItem("Redo", new BMessage(B_REDO), 
'Z',
+       menu->AddItem(fRedoItem = new BMenuItem(B_TRANSLATE("Redo"),
+               new BMessage(B_REDO), 'Z',
                B_SHIFT_KEY));
        fRedoItem->SetEnabled(false);
        menu->AddSeparatorItem();
 
-       menu->AddItem(new BMenuItem("Snapshot current",
+       menu->AddItem(new BMenuItem(B_TRANSLATE("Snapshot current"),
                new BMessage(kMsgStoreState)));
-       menu->AddItem(fRestoreStateItem = new BMenuItem("Restore snapshot",
+       menu->AddItem(fRestoreStateItem = new BMenuItem(
+               B_TRANSLATE("Restore snapshot"),
                new BMessage(kMsgRestoreState)));
        fRestoreStateItem->SetEnabled(fStoredState != NULL);
        menu->AddSeparatorItem();
 
-       menu->AddItem(new BMenuItem("Solve", new BMessage(kMsgSolveSudoku)));
-       menu->AddItem(new BMenuItem("Solve single field",
+       menu->AddItem(new BMenuItem(B_TRANSLATE("Solve"),
+               new BMessage(kMsgSolveSudoku)));
+       menu->AddItem(new BMenuItem(B_TRANSLATE("Solve single field"),
                new BMessage(kMsgSolveSingle)));
        menu->SetTargetForItems(fSudokuView);
        menuBar->AddItem(menu);
@@ -396,15 +411,16 @@
                char buffer[1024];
                if (hasRef) {
                        snprintf(buffer, sizeof(buffer),
-                               "Could not open \"%s\":\n"
-                               "%s", ref.name, strerror(status));
+                               B_TRANSLATE("Could not open \"%s\":\n%s\n"), 
ref.name,
+                               strerror(status));
                } else {
-                       snprintf(buffer, sizeof(buffer), "Could not set 
Sudoku:\n%s",
+                       snprintf(buffer, sizeof(buffer),
+                               B_TRANSLATE("Could not set Sudoku:\n%s\n"),
                                strerror(status));
                }
 
-               (new BAlert("Sudoku request",
-                       buffer, "OK", NULL, NULL,
+               (new BAlert(B_TRANSLATE("Sudoku request"),
+                       buffer, B_TRANSLATE("OK"), NULL, NULL,
                        B_WIDTH_AS_USUAL, B_STOP_ALERT))->Go();
        }
 }
@@ -546,8 +562,9 @@
                }
 
                case kMsgSudokuSolved:
-                       (new BAlert("Sudoku request",
-                               "Sudoku solved - congratulations!", "OK", NULL, 
NULL,
+                       (new BAlert(B_TRANSLATE("Sudoku request"),
+                               B_TRANSLATE("Sudoku solved - 
congratulations!\n"),
+                               B_TRANSLATE("OK"), NULL, NULL,
                                B_WIDTH_AS_USUAL, B_IDEA_ALERT))->Go();
                        break;
 


Other related posts:

  • » [haiku-commits] r40874 - haiku/trunk/src/apps/sudoku - axeld