Skip to content

Commit

Permalink
Added localization (#6)
Browse files Browse the repository at this point in the history
Still missing: generating the en.catkeys
  • Loading branch information
humdingerb authored Jun 23, 2024
1 parent 9eef830 commit 6475520
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 47 deletions.
2 changes: 1 addition & 1 deletion Source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ include_directories(AFTER SYSTEM

haiku_add_executable(${PROJECT_NAME} ${${PROJECT_NAME}_sources})

target_link_libraries(${PROJECT_NAME} be shared tracker)
target_link_libraries(${PROJECT_NAME} be localestub shared tracker)

install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION add-ons/Tracker)
25 changes: 16 additions & 9 deletions Source/CommandSelectWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <Application.h>
#include <Box.h>
#include <Button.h>
#include <Catalog.h>
#include <CheckBox.h>
#include <FilePanel.h>
#include <FindDirectory.h>
Expand All @@ -21,6 +22,10 @@
#include <StringView.h>


#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "CommandSelectWindow"


enum {
kBrowseCommandAction = 'BrCm',
kBrowseDirectoryAction = 'BrDr',
Expand Down Expand Up @@ -73,19 +78,19 @@ CommandSelectWindow::CommandSelectWindow(BMessage* message)
else
find_directory(B_USER_DIRECTORY, &cwdPath);

fDirectoryTextControl = new BTextControl("CWDTextControl", "Directory:", cwdPath.Path(), NULL);
fCommandTextControl = new BTextControl("CommandTextControl", "Command:", "", NULL);
fDirectoryTextControl = new BTextControl("CWDTextControl", B_TRANSLATE("Folder:"), cwdPath.Path(), NULL);
fCommandTextControl = new BTextControl("CommandTextControl", B_TRANSLATE("Command:"), "", NULL);
fCommandTextControl->SetModificationMessage(new BMessage(kCommandTextAction));
// prevent the text control from growing vertically due to the button
fCommandTextControl->TextView()->SetExplicitMaxSize(BSize(B_SIZE_UNSET, fCommandTextControl->TextView()->MinSize().Height()));

fUseTerminalCheckBox = new BCheckBox("Use Terminal");
fUseTerminalCheckBox = new BCheckBox(B_TRANSLATE("Use Terminal"));
// allow the checkbox to grow horizontally as the window resizes
BSize size(fUseTerminalCheckBox->ExplicitMaxSize());
size.SetWidth(B_SIZE_UNLIMITED);
fUseTerminalCheckBox->SetExplicitMaxSize(size);

fRunButton = new BButton("Run", new BMessage(kRunCommandAction));
fRunButton = new BButton(B_TRANSLATE("Run"), new BMessage(kRunCommandAction));
fRunButton->MakeDefault(true);

// clang-format off
Expand All @@ -95,14 +100,14 @@ CommandSelectWindow::CommandSelectWindow(BMessage* message)
.AddStrut(10.0)
.AddGrid(B_USE_HALF_ITEM_SPACING, B_USE_HALF_ITEM_SPACING)
.AddTextControl(fCommandTextControl, 0, 0, B_ALIGN_RIGHT)
.Add(new BButton("Browse" B_UTF8_ELLIPSIS, new BMessage(kBrowseCommandAction)), 2, 0)
.Add(new BButton(B_TRANSLATE("Browse" B_UTF8_ELLIPSIS), new BMessage(kBrowseCommandAction)), 2, 0)
.AddTextControl(fDirectoryTextControl, 0, 1, B_ALIGN_RIGHT)
.Add(new BButton("Browse" B_UTF8_ELLIPSIS, new BMessage(kBrowseDirectoryAction)), 2, 1)
.Add(new BButton(B_TRANSLATE("Browse" B_UTF8_ELLIPSIS), new BMessage(kBrowseDirectoryAction)), 2, 1)
.Add(fUseTerminalCheckBox, 1, 2)
.End()
.AddGroup(B_HORIZONTAL, B_USE_HALF_ITEM_SPACING, 1.0)
.AddGlue()
.Add(new BButton("Cancel", new BMessage(B_QUIT_REQUESTED)))
.Add(new BButton(B_TRANSLATE("Cancel"), new BMessage(B_QUIT_REQUESTED)))
.Add(fRunButton)
.End()
.End();
Expand Down Expand Up @@ -217,9 +222,11 @@ CommandSelectWindow::_Run()

fRefsMessage->AddMessage(kCommandDataKey, &itemMessage);

if (RunnerAddOn::RunCommand(fRefsMessage) != B_OK)
if (RunnerAddOn::RunCommand(fRefsMessage) != B_OK) {
//TODO improve error message
(new BAlert("RunAlert", "Error running the command!", "OK", NULL, NULL, B_WIDTH_FROM_LABEL, B_STOP_ALERT))->Go();
(new BAlert("RunAlert", B_TRANSLATE("Error running the command!"), B_TRANSLATE("OK"),
NULL, NULL, B_WIDTH_FROM_LABEL, B_STOP_ALERT))->Go();
}

PostMessage(B_QUIT_REQUESTED);
}
Expand Down
30 changes: 20 additions & 10 deletions Source/CommandsWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <Application.h>
#include <Bitmap.h>
#include <Button.h>
#include <Catalog.h>
#include <CheckBox.h>
#include <FilePanel.h>
#include <IconUtils.h>
Expand All @@ -26,6 +27,9 @@
#include <private/shared/ToolBar.h>


#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "CommandsWindow"

enum {
kDeleteCommandAction = 'DeLc',
kModificationAction = 'MoDa',
Expand Down Expand Up @@ -53,18 +57,21 @@ CommandsWindow::CommandsWindow(BString& title)
scrollView->SetExplicitMaxSize(BSize(250, B_SIZE_UNSET));

fToolbar = new BToolBar();
fToolbar->AddAction(kNewCommandAction, this, _ResourceBitmap("EntryAdd", 16, 16), "Create a new command entry", "New");
fToolbar->AddAction(kDeleteCommandAction, this, _ResourceBitmap("EntryDelete", 16, 16), "Delete the selected command entry", "Delete");
fToolbar->AddAction(kNewCommandAction, this, _ResourceBitmap("EntryAdd", 16, 16),
B_TRANSLATE("Create a new command entry"), B_TRANSLATE("New"));
fToolbar->AddAction(kDeleteCommandAction, this, _ResourceBitmap("EntryDelete", 16, 16),
B_TRANSLATE("Delete the selected command entry"), B_TRANSLATE("Delete"));
fToolbar->AddGlue();
fToolbar->AddAction(kUserGuideAction, this, _ResourceBitmap("UserGuide", 16, 16), "Open the user guide", "User Guide");
fToolbar->AddAction(kUserGuideAction, this, _ResourceBitmap("UserGuide", 16, 16),
B_TRANSLATE("Open the user guide"), B_TRANSLATE("User Guide"));

fNameControl = new BTextControl("Name:", NULL, NULL);
fNameControl = new BTextControl(B_TRANSLATE("Name:"), NULL, NULL);
fNameControl->SetModificationMessage(new BMessage(kModificationAction));

fCommandControl = new BTextControl("Command:", NULL, NULL);
fCommandControl = new BTextControl(B_TRANSLATE("Command:"), NULL, NULL);
fCommandControl->SetModificationMessage(new BMessage(kModificationAction));

fTerminalCheckBox = new BCheckBox("Use Terminal", new BMessage(kModificationAction));
fTerminalCheckBox = new BCheckBox(B_TRANSLATE("Use Terminal"), new BMessage(kModificationAction));
BSize size(fTerminalCheckBox->ExplicitMaxSize());
size.SetWidth(B_SIZE_UNLIMITED);
fTerminalCheckBox->SetExplicitMaxSize(size);
Expand All @@ -82,9 +89,11 @@ CommandsWindow::CommandsWindow(BString& title)
.AddTextControl(fCommandControl, 0, 1, B_ALIGN_RIGHT)
.AddGroup(B_HORIZONTAL, 0, 1, 2)
.SetInsets(0)
.Add(fBrowseButton = new BButton("Browse" B_UTF8_ELLIPSIS, new BMessage(kBrowseCommandAction)))
.Add(fBrowseButton = new BButton(B_TRANSLATE("Browse" B_UTF8_ELLIPSIS),
new BMessage(kBrowseCommandAction)))
.AddGlue()
.Add(fShowButton = new BButton("Show in Tracker", new BMessage(kShowCommandAction)))
.Add(fShowButton = new BButton(B_TRANSLATE("Show in Tracker"),
new BMessage(kShowCommandAction)))
.End()
.Add(fTerminalCheckBox, 1, 3)
.End()
Expand Down Expand Up @@ -270,8 +279,9 @@ CommandsWindow::_DeleteCommand()
return;

BString alertString;
alertString.SetToFormat("Do you wish to delete %s ?", item->Text());
if ((new BAlert("DeleteAlert", alertString, "Delete", "Cancel", NULL, B_WIDTH_FROM_LABEL, B_INFO_ALERT))->Go() == 1)
alertString.SetToFormat(B_TRANSLATE("Do you wish to delete '%s'?"), item->Text());
if ((new BAlert("DeleteAlert", alertString, B_TRANSLATE("Delete"), B_TRANSLATE("Cancel"),
NULL, B_WIDTH_FROM_LABEL, B_INFO_ALERT))->Go() == 1)
return;

fListView->RemoveItem(item);
Expand Down
14 changes: 10 additions & 4 deletions Source/PreferencesWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@

#include <Application.h>
#include <Button.h>
#include <Catalog.h>
#include <CheckBox.h>
#include <LayoutBuilder.h>


#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "PreferencesWindow"


enum {
kDefaultsButtonWhat = 'DfLt',
#ifdef USE_MENUITEM_ICONS
Expand All @@ -28,11 +33,12 @@ PreferencesWindow::PreferencesWindow(BString& title)
BMessage message;
Preferences::ReadPreferences(message);

fMenuLabelControl = new BTextControl("Menu label:", message.GetString(kMenuLabelKey, kAppTitle), NULL);
fMenuLabelControl = new BTextControl(B_TRANSLATE("Menu label:"),
message.GetString(kMenuLabelKey, kAppTitle), NULL);
fMenuLabelControl->SetModificationMessage(new BMessage(kMenuLabelWhat));

#ifdef USE_MENUITEM_ICONS
fIconMenuCheckBox = new BCheckBox("Use icons in menus", new BMessage(kIconCheckBoxWhat));
fIconMenuCheckBox = new BCheckBox(B_TRANSLATE("Use icons in menus"), new BMessage(kIconCheckBoxWhat));
BSize size(fIconMenuCheckBox->ExplicitMaxSize());
size.SetWidth(B_SIZE_UNLIMITED);
fIconMenuCheckBox->SetExplicitMaxSize(size);
Expand All @@ -49,8 +55,8 @@ PreferencesWindow::PreferencesWindow(BString& title)
.AddGlue()
.AddGroup(B_HORIZONTAL)
.AddGlue()
.Add(new BButton("DefaultsButton", "Defaults", new BMessage(kDefaultsButtonWhat)))
.Add(new BButton("CloseButton", "Close", new BMessage(B_QUIT_REQUESTED)))
.Add(new BButton("DefaultsButton", B_TRANSLATE("Defaults"), new BMessage(kDefaultsButtonWhat)))
.Add(new BButton("CloseButton", B_TRANSLATE("Close"), new BMessage(B_QUIT_REQUESTED)))
.End()
.End();
// clang-format on
Expand Down
55 changes: 37 additions & 18 deletions Source/RunnerAddOn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "Preferences.h"

#include <Alert.h>
#include <Catalog.h>
#include <InterfaceDefs.h>
#include <LayoutBuilder.h>
#include <Menu.h>
Expand All @@ -21,6 +22,11 @@
#include <private/tracker/IconMenuItem.h>
#endif


#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "RunnerAddOn"


enum {
kCommandWhat = 'CMND',
kUserGuideWhat = 'GUID',
Expand Down Expand Up @@ -125,8 +131,10 @@ RunnerAddOn::OpenUserGuide(bool useAppImage)
if (entry.InitCheck() != B_OK || !entry.Exists()) {
// search other document locations using the BPathFinder API if needed
BStringList list;
if (BPathFinder::FindPaths(B_FIND_PATH_DOCUMENTATION_DIRECTORY, "TrackRunner/UserGuide/index.html", B_FIND_PATH_EXISTING_ONLY, list) != B_OK) {
(new BAlert("Error", "Unable to locate UserGuide html files", "Ok", NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT))->Go();
if (BPathFinder::FindPaths(B_FIND_PATH_DOCUMENTATION_DIRECTORY,
"TrackRunner/UserGuide/index.html", B_FIND_PATH_EXISTING_ONLY, list) != B_OK) {
(new BAlert("Error", B_TRANSLATE("Unable to locate UserGuide html files"),
B_TRANSLATE("OK"), NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT))->Go();
return B_ERROR;
}
indexLocation.SetTo(list.First());
Expand All @@ -136,7 +144,8 @@ RunnerAddOn::OpenUserGuide(bool useAppImage)

status_t rc = be_roster->Launch("application/x-vnd.Be.URL.https", 1, args);
if (rc != B_OK && rc != B_ALREADY_RUNNING) {
(new BAlert("Error", "Failed to launch URL", "Ok", NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT))->Go();
(new BAlert("Error", B_TRANSLATE("Failed to launch URL"), B_TRANSLATE("OK"),
NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT))->Go();
return rc;
}

Expand Down Expand Up @@ -237,13 +246,13 @@ populate_menu(BMessage* message, BMenu* menu, BHandler* handler)
BMenu* prefsSubMenu = NULL;
builder
.AddSeparator()
.AddMenu("Preferences & Help")
.AddMenu(B_TRANSLATE("Settings & Help"))
.GetMenu(prefsSubMenu)
.AddItem("Manage Commands" B_UTF8_ELLIPSIS, commandsMenuMessage)
.AddItem("Preferences" B_UTF8_ELLIPSIS, prefsMenuMessage)
.AddItem(B_TRANSLATE("Manage commands" B_UTF8_ELLIPSIS), commandsMenuMessage)
.AddItem(B_TRANSLATE("Settings" B_UTF8_ELLIPSIS), prefsMenuMessage)
.AddSeparator()
.AddItem("User Guide", guideMenuMessage)
.AddItem("Github Page", githubMenuMessage)
.AddItem(B_TRANSLATE("User guide"), guideMenuMessage)
.AddItem(B_TRANSLATE("Github page"), githubMenuMessage)
.End()
.End();
// clang-format on
Expand Down Expand Up @@ -275,23 +284,29 @@ message_received(BMessage* message)
switch (what) {
case kCommandWhat:
//TODO improve alert message
if (RunnerAddOn::RunCommand(message) != B_OK)
(new BAlert("ErrorAlert", "Error running command", "OK", NULL, NULL, B_WIDTH_FROM_LABEL, B_STOP_ALERT))->Go();
if (RunnerAddOn::RunCommand(message) != B_OK) {
(new BAlert("ErrorAlert", B_TRANSLATE("Error running command"), B_TRANSLATE("OK"),
NULL, NULL, B_WIDTH_FROM_LABEL, B_STOP_ALERT))->Go();
}
break;
case kManageCommandsWhat:
{
BMessage launchMessage(kLaunchManageWhat);
status_t rc = be_roster->Launch(kAppSignature, &launchMessage);
if (rc != B_OK && rc != B_ALREADY_RUNNING)
(new BAlert("ErrorAlert", "Unable to launch TrackRunner application", "OK", NULL, NULL, B_WIDTH_FROM_LABEL, B_STOP_ALERT))->Go();
if (rc != B_OK && rc != B_ALREADY_RUNNING) {
(new BAlert("ErrorAlert", B_TRANSLATE("Unable to launch TrackRunner application"),
B_TRANSLATE("OK"), NULL, NULL, B_WIDTH_FROM_LABEL, B_STOP_ALERT))->Go();
}
break;
}
case kLaunchPrefsWhat:
{
BMessage launchMessage(kLaunchPrefsWhat);
status_t rc = be_roster->Launch(kAppSignature, &launchMessage);
if (rc != B_OK && rc != B_ALREADY_RUNNING)
(new BAlert("ErrorAlert", "Unable to launch TrackRunner application", "OK", NULL, NULL, B_WIDTH_FROM_LABEL, B_STOP_ALERT))->Go();
if (rc != B_OK && rc != B_ALREADY_RUNNING) {
(new BAlert("ErrorAlert", B_TRANSLATE("Unable to launch TrackRunner application"),
B_TRANSLATE("OK"), NULL, NULL, B_WIDTH_FROM_LABEL, B_STOP_ALERT))->Go();
}
break;
}
case kUserGuideWhat:
Expand All @@ -301,8 +316,10 @@ message_received(BMessage* message)
{
const char* args[] = {kGithubUrl, NULL};
status_t rc = be_roster->Launch("application/x-vnd.Be.URL.https", 1, args);
if (rc != B_OK && rc != B_ALREADY_RUNNING)
(new BAlert("Error", "Failed to launch URL", "Ok", NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT))->Go();
if (rc != B_OK && rc != B_ALREADY_RUNNING) {
(new BAlert("Error", B_TRANSLATE("Failed to launch URL"), B_TRANSLATE("OK"),
NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT))->Go();
}
break;
}
default:
Expand All @@ -322,6 +339,8 @@ process_refs(entry_ref directory, BMessage* refs, void* /*reserved*/)
launchMessage.AddRef("TrackRunner:cwd", &directory);

status_t rc = be_roster->Launch(kAppSignature, &launchMessage);
if (rc != B_OK && rc != B_ALREADY_RUNNING)
(new BAlert("ErrorAlert", "Unable to launch TrackRunner application", "OK", NULL, NULL, B_WIDTH_FROM_LABEL, B_STOP_ALERT))->Go();
if (rc != B_OK && rc != B_ALREADY_RUNNING) {
(new BAlert("ErrorAlert", B_TRANSLATE("Unable to launch TrackRunner application"),
B_TRANSLATE("OK"), NULL, NULL, B_WIDTH_FROM_LABEL, B_STOP_ALERT))->Go();
}
}
16 changes: 11 additions & 5 deletions Source/RunnerApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@

#include <Alert.h>
#include <Application.h>
#include <Catalog.h>


#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "RunnerApp"


RunnerApp::RunnerApp()
Expand Down Expand Up @@ -87,15 +92,16 @@ RunnerApp::RefsReceived(BMessage* message)
void
RunnerApp::AboutRequested()
{
(new BAlert("AboutWindow", "TrackRunner\nWritten by Chris Roberts", "OK", NULL, NULL, B_WIDTH_FROM_LABEL))->Go();
(new BAlert("AboutWindow", B_TRANSLATE("TrackRunner\nWritten by Chris Roberts"),
B_TRANSLATE("OK"), NULL, NULL, B_WIDTH_FROM_LABEL))->Go();
}


void
RunnerApp::_ShowPreferencesWindow()
{
BString title(kAppTitle);
title << " Preferences";
BString title(B_TRANSLATE("%trackrunner% settings"));
title.ReplaceFirst("%trackrunner%", kAppTitle);
PreferencesWindow* window = new PreferencesWindow(title);
window->Lock();
window->CenterOnScreen();
Expand All @@ -107,8 +113,8 @@ RunnerApp::_ShowPreferencesWindow()
void
RunnerApp::_ShowManageWindow()
{
BString title(kAppTitle);
title << " Commands";
BString title(B_TRANSLATE("%trackrunner% commands"));
title.ReplaceFirst("%trackrunner%", kAppTitle);
CommandsWindow* window = new CommandsWindow(title);
window->Lock();
window->CenterOnScreen();
Expand Down

0 comments on commit 6475520

Please sign in to comment.