SerialConnect: Add localization.

Add localization for menus, statusbar and system name.

Change-Id: I85ef95c1ff940c6d794f49a859ff1b696b866839
Reviewed-on: https://review.haiku-os.org/c/haiku/+/2602
Reviewed-by: Adrien Destugues <pulkomandy@gmail.com>
This commit is contained in:
Murai Takashi 2020-05-07 20:31:07 +09:00 committed by waddlesplash
parent 693e2f4fb4
commit 2e6ca31c5a
4 changed files with 67 additions and 34 deletions

View File

@ -24,3 +24,10 @@ Application SerialConnect :
: SerialConnect.rdef
;
DoCatalogs SerialConnect :
x-vnd.haiku.SerialConnect
:
CustomRateWindow.cpp
SerialWindow.cpp
XModem.cpp
;

View File

@ -1,6 +1,8 @@
resource app_signature "application/x-vnd.haiku.SerialConnect";
resource app_name_catalog_entry "x-vnd.haiku.SerialConnect:System name:SerialConnect";
resource app_version {
major = 0,
middle = 0,

View File

@ -8,6 +8,7 @@
#include <stdio.h>
#include <Catalog.h>
#include <FilePanel.h>
#include <GroupLayout.h>
#include <Menu.h>
@ -21,6 +22,9 @@
#include "TermView.h"
#define B_TRANSLATION_CONTEXT "SerialWindow"
const int SerialWindow::kBaudrates[] = { 50, 75, 110, 134, 150, 200, 300, 600,
1200, 1800, 2400, 4800, 9600, 19200, 31250, 38400, 57600, 115200, 230400
};
@ -35,11 +39,13 @@ const int SerialWindow::kBaudrateConstants[] = { B_50_BPS, B_75_BPS, B_110_BPS,
};
const char* SerialWindow::kWindowTitle = "SerialConnect";
const char* SerialWindow::kWindowTitle =
B_TRANSLATE_MARK_SYSTEM_NAME("SerialConnect");
SerialWindow::SerialWindow()
: BWindow(BRect(100, 100, 400, 400), SerialWindow::kWindowTitle,
: BWindow(BRect(100, 100, 400, 400),
B_TRANSLATE_NOCOLLECT_SYSTEM_NAME(SerialWindow::kWindowTitle),
B_DOCUMENT_WINDOW, B_QUIT_ON_WINDOW_CLOSE | B_AUTO_UPDATE_SIZE_LIMITS)
, fLogFilePanel(NULL)
, fSendFilePanel(NULL)
@ -69,7 +75,8 @@ SerialWindow::SerialWindow()
r = fTermView->Frame();
r.top = r.bottom - 37;
fStatusBar = new BStatusBar(r, "file transfer progress", NULL, NULL);
fStatusBar = new BStatusBar(r, B_TRANSLATE("file transfer progress"),
NULL, NULL);
fStatusBar->SetResizingMode(B_FOLLOW_BOTTOM | B_FOLLOW_LEFT_RIGHT);
fStatusBar->SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
fStatusBar->Hide();
@ -79,10 +86,10 @@ SerialWindow::SerialWindow()
AddChild(scrollBar);
AddChild(fStatusBar);
fConnectionMenu = new BMenu("Connection");
fFileMenu = new BMenu("File");
BMenu* settingsMenu = new BMenu("Settings");
BMenu* editMenu = new BMenu("Edit");
fConnectionMenu = new BMenu(B_TRANSLATE("Connection"));
fFileMenu = new BMenu(B_TRANSLATE("File"));
BMenu* settingsMenu = new BMenu(B_TRANSLATE("Settings"));
BMenu* editMenu = new BMenu(B_TRANSLATE("Edit"));
fConnectionMenu->SetRadioMode(true);
@ -91,20 +98,21 @@ SerialWindow::SerialWindow()
menuBar->AddItem(fFileMenu);
menuBar->AddItem(settingsMenu);
BMenuItem* logFile = new BMenuItem("Log to file" B_UTF8_ELLIPSIS,
new BMessage(kMsgLogfile));
BMenuItem* logFile = new BMenuItem(
B_TRANSLATE("Log to file" B_UTF8_ELLIPSIS), new BMessage(kMsgLogfile));
fFileMenu->AddItem(logFile);
// The "send" items are disabled initially. They are enabled only once we
// are connected to a serial port.
BMessage* sendMsg = new BMessage(kMsgSendFile);
sendMsg->AddString("protocol", "xmodem");
BMenuItem* xmodemSend = new BMenuItem("XModem send" B_UTF8_ELLIPSIS,
BMenuItem* xmodemSend = new BMenuItem(
B_TRANSLATE("XModem send" B_UTF8_ELLIPSIS),
sendMsg);
fFileMenu->AddItem(xmodemSend);
xmodemSend->SetEnabled(false);
BMenuItem* rawSend = new BMenuItem("Raw send" B_UTF8_ELLIPSIS,
BMenuItem* rawSend = new BMenuItem(B_TRANSLATE("Raw send" B_UTF8_ELLIPSIS),
new BMessage(kMsgSendFile));
fFileMenu->AddItem(rawSend);
rawSend->SetEnabled(false);
@ -118,7 +126,7 @@ SerialWindow::SerialWindow()
#endif
// Items for the edit menu
BMenuItem* clearScreen = new BMenuItem("Clear history",
BMenuItem* clearScreen = new BMenuItem(B_TRANSLATE("Clear history"),
new BMessage(kMsgClear));
editMenu->AddItem(clearScreen);
@ -126,41 +134,44 @@ SerialWindow::SerialWindow()
// Configuring all this by menus may be a bit unhandy. Make a setting
// window instead ?
fBaudrateMenu = new BMenu("Baud rate");
fBaudrateMenu = new BMenu(B_TRANSLATE("Baud rate"));
fBaudrateMenu->SetRadioMode(true);
settingsMenu->AddItem(fBaudrateMenu);
fParityMenu = new BMenu("Parity");
fParityMenu = new BMenu(B_TRANSLATE("Parity"));
fParityMenu->SetRadioMode(true);
settingsMenu->AddItem(fParityMenu);
fStopbitsMenu = new BMenu("Stop bits");
fStopbitsMenu = new BMenu(B_TRANSLATE("Stop bits"));
fStopbitsMenu->SetRadioMode(true);
settingsMenu->AddItem(fStopbitsMenu);
fFlowcontrolMenu = new BMenu("Flow control");
fFlowcontrolMenu = new BMenu(B_TRANSLATE("Flow control"));
fFlowcontrolMenu->SetRadioMode(true);
settingsMenu->AddItem(fFlowcontrolMenu);
fDatabitsMenu = new BMenu("Data bits");
fDatabitsMenu = new BMenu(B_TRANSLATE("Data bits"));
fDatabitsMenu->SetRadioMode(true);
settingsMenu->AddItem(fDatabitsMenu);
fLineTerminatorMenu = new BMenu("Line terminator");
fLineTerminatorMenu = new BMenu(B_TRANSLATE("Line terminator"));
fLineTerminatorMenu->SetRadioMode(true);
settingsMenu->AddItem(fLineTerminatorMenu);
BMessage* message = new BMessage(kMsgSettings);
message->AddInt32("parity", B_NO_PARITY);
BMenuItem* parityNone = new BMenuItem("None", message);
BMenuItem* parityNone =
new BMenuItem(B_TRANSLATE_COMMENT("None", "Parity"), message);
message = new BMessage(kMsgSettings);
message->AddInt32("parity", B_ODD_PARITY);
BMenuItem* parityOdd = new BMenuItem("Odd", message);
BMenuItem* parityOdd = new BMenuItem(B_TRANSLATE_COMMENT("Odd", "Parity"),
message);
message = new BMessage(kMsgSettings);
message->AddInt32("parity", B_EVEN_PARITY);
BMenuItem* parityEven = new BMenuItem("Even", message);
BMenuItem* parityEven =
new BMenuItem(B_TRANSLATE_COMMENT("Even", "Parity"), message);
fParityMenu->AddItem(parityNone);
fParityMenu->AddItem(parityOdd);
@ -205,26 +216,32 @@ SerialWindow::SerialWindow()
}
message = new BMessage(kMsgCustomBaudrate);
BMenuItem* custom = new BMenuItem("custom" B_UTF8_ELLIPSIS, message);
BMenuItem* custom =
new BMenuItem(B_TRANSLATE_COMMENT("custom" B_UTF8_ELLIPSIS,
"Baudrate"), message);
fBaudrateMenu->AddItem(custom);
fBaudrateMenu->SetTargetForItems(be_app);
message = new BMessage(kMsgSettings);
message->AddInt32("flowcontrol", B_HARDWARE_CONTROL);
BMenuItem* hardware = new BMenuItem("Hardware", message);
BMenuItem* hardware =
new BMenuItem(B_TRANSLATE_COMMENT("Hardware", "Flowcontrol"), message);
message = new BMessage(kMsgSettings);
message->AddInt32("flowcontrol", B_SOFTWARE_CONTROL);
BMenuItem* software = new BMenuItem("Software", message);
BMenuItem* software =
new BMenuItem(B_TRANSLATE_COMMENT("Software", "Flowcontrol"), message);
message = new BMessage(kMsgSettings);
message->AddInt32("flowcontrol", B_HARDWARE_CONTROL | B_SOFTWARE_CONTROL);
BMenuItem* both = new BMenuItem("Both", message);
BMenuItem* both =
new BMenuItem(B_TRANSLATE_COMMENT("Both", "Flowcontrol"), message);
message = new BMessage(kMsgSettings);
message->AddInt32("flowcontrol", 0);
BMenuItem* noFlow = new BMenuItem("None", message);
BMenuItem* noFlow =
new BMenuItem(B_TRANSLATE_COMMENT("None", "Flowcontrol"), message);
fFlowcontrolMenu->AddItem(hardware);
fFlowcontrolMenu->AddItem(software);
@ -292,14 +309,15 @@ void SerialWindow::MenusBeginning()
if (deviceCount > 0) {
fConnectionMenu->AddSeparatorItem();
BMenuItem* disconnect = new BMenuItem("Disconnect",
BMenuItem* disconnect = new BMenuItem(B_TRANSLATE("Disconnect"),
new BMessage(kMsgOpenPort), 'Z', B_OPTION_KEY);
if (!connected)
disconnect->SetEnabled(false);
disconnect->SetTarget(be_app);
fConnectionMenu->AddItem(disconnect);
} else {
BMenuItem* noDevices = new BMenuItem("<no serial port available>", NULL);
BMenuItem* noDevices =
new BMenuItem(B_TRANSLATE("<no serial port available>"), NULL);
noDevices->SetEnabled(false);
fConnectionMenu->AddItem(noDevices);
}

View File

@ -8,12 +8,16 @@
#include "SerialApp.h"
#include <Catalog.h>
#include <String.h>
#include <stdio.h>
#include <string.h>
#define B_TRANSLATION_CONTEXT "XModemStatus"
// ASCII control characters used in XMODEM protocol
static const char kSOH = 1;
static const char kEOT = 4;
@ -33,7 +37,7 @@ XModemSender::XModemSender(BDataIO* source, BSerialPort* sink, BHandler* listene
fEotSent(false),
fUseCRC(false)
{
fStatus = "Waiting for receiver" B_UTF8_ELLIPSIS;
fStatus = B_TRANSLATE("Waiting for receiver" B_UTF8_ELLIPSIS);
BPositionIO* pos = dynamic_cast<BPositionIO*>(source);
if (pos)
@ -65,7 +69,7 @@ XModemSender::BytesReceived(const uint8_t* data, size_t length)
// in place of an 8-bit checksum.
// In any other place, it is ignored.
if (fBlockNumber <= 1) {
fStatus = "CRC requested";
fStatus = B_TRANSLATE("CRC requested");
fUseCRC = true;
SendBlock();
} else
@ -74,7 +78,7 @@ XModemSender::BytesReceived(const uint8_t* data, size_t length)
if (fEotSent) {
fSink->Write(&kEOT, 1);
} else {
fStatus = "Checksum error, re-send block";
fStatus = B_TRANSLATE("Checksum error, re-send block");
SendBlock();
}
break;
@ -85,10 +89,11 @@ XModemSender::BytesReceived(const uint8_t* data, size_t length)
}
if (NextBlock() == B_OK) {
fStatus = "Sending" B_UTF8_ELLIPSIS;
fStatus = B_TRANSLATE("Sending" B_UTF8_ELLIPSIS);
SendBlock();
} else {
fStatus = "Everything sent, waiting for acknowledge";
fStatus = B_TRANSLATE("Everything sent, "
"waiting for acknowledge");
fSink->Write(&kEOT, 1);
fEotSent = true;
}
@ -99,7 +104,8 @@ XModemSender::BytesReceived(const uint8_t* data, size_t length)
BMessage msg(kMsgProgress);
msg.AddInt32("pos", 0);
msg.AddInt32("size", 0);
msg.AddString("info", "Remote cancelled transfer");
msg.AddString("info",
B_TRANSLATE("Remote cancelled transfer"));
fListener.SendMessage(&msg);
return true;
}