Skip to content

Commit

Permalink
Initial support for internationalization
Browse files Browse the repository at this point in the history
  • Loading branch information
Dax89 committed Aug 13, 2021
1 parent 0f78287 commit 21e211f
Show file tree
Hide file tree
Showing 21 changed files with 164 additions and 157 deletions.
48 changes: 25 additions & 23 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ cmake_minimum_required(VERSION 3.12)

project(REDasm)

set(QT_VERSION_REQ "5.11")
set(_QT_VERSION_REQ 5.11)
set(QT_VERSION_REQ "${_QT_VERSION_REQ}")
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
Expand All @@ -13,7 +14,8 @@ string(TIMESTAMP REDASM_BUILD_TIMESTAMP "%Y%m%d")
set(REDASM_GIT_VERSION "unknown")
set(REDASM_VERSION_BASE "3.0-BETA6")

find_package(Qt5 5.11 REQUIRED COMPONENTS Widgets)
find_package(Qt5 ${_QT_VERSION_REQ} REQUIRED COMPONENTS Widgets)
find_package(Qt5 ${_QT_VERSION_REQ} COMPONENTS LinguistTools)
find_package(Git)

if(GIT_FOUND)
Expand Down Expand Up @@ -43,7 +45,7 @@ add_subdirectory(submodules/plugins)
add_subdirectory(submodules/assemblers)
add_subdirectory(submodules/loaders)
add_subdirectory(submodules/database)
QT5_WRAP_UI(UI_HDRS ${UI_FILES})
qt5_wrap_ui(UI_HDRS ${UI_FILES})

# Widgets
file(GLOB_RECURSE WIDGETS_HEADERS CONFIGURE_DEPENDS widgets/*.h )
Expand Down Expand Up @@ -89,8 +91,7 @@ SET(HEADERS
mainwindow.h
themeprovider.h
redasmsettings.h
redasmfonts.h
)
redasmfonts.h)

SET(SOURCES
${QHEXVIEW_SOURCES}
Expand All @@ -106,31 +107,35 @@ SET(SOURCES
mainwindow.cpp
themeprovider.cpp
redasmsettings.cpp
redasmfonts.cpp
)
redasmfonts.cpp)

set(FORMS
${WIDGETS_UIS}
${DIALOGS_UIS}
${UI_UIS}
)
${UI_UIS})

set(RESOURCES
resources.qrc
themes.qrc
)
themes.qrc)

if(WIN32)
set(GUI_TYPE WIN32)
endif()

if(Qt5_LRELEASE_EXECUTABLE) # Prepare translations
message(STATUS "${PROJECT_NAME}: Adding multilanguage support")
set(ALL_SOURCES ${SOURCES} ${HEADERS} ${FORMS})
qt5_create_translation(QM_FILES ${ALL_SOURCES} translations/redasm_en.ts)
configure_file(translations.qrc ${CMAKE_BINARY_DIR} COPYONLY)
set(TRANSLATIONS_QRC ${CMAKE_BINARY_DIR}/translations.qrc)
else()
message(STATUS "${PROJECT_NAME}: Multilanguage support not available")
endif()

add_executable(${PROJECT_NAME} ${GUI_TYPE}
${SOURCES}
${HEADERS}
${FORMS}
${RESOURCES}
${CMAKE_SOURCE_DIR}/res/windows/resources.rc
)
${ALL_SOURCES} ${RESOURCES}
${TRANSLATIONS_QRC} ${QM_FILES}
${CMAKE_SOURCE_DIR}/res/windows/resources.rc)

target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_17)
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_EXTENSIONS OFF)
Expand All @@ -139,17 +144,15 @@ set_target_properties(${PROJECT_NAME} PROPERTIES CXX_EXTENSIONS OFF)
target_include_directories(${PROJECT_NAME} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
LibREDasm
libs
)
libs)

target_link_libraries(${PROJECT_NAME} PRIVATE
Qt5::Core
Qt5::Gui
Qt5::Widgets
KDAB::kddockwidgets
qhexview-lib
LibREDasm
)
LibREDasm)

# Include Threads
# TODO: perhaps this should be a PUBLIC dependency of LibREDasm?
Expand All @@ -173,8 +176,7 @@ if(Qt5_FOUND AND WIN32 AND TARGET Qt5::qmake AND NOT TARGET Qt5::windeployqt)
COMMAND "${_qt5_qmake_location}" -query QT_INSTALL_PREFIX
RESULT_VARIABLE return_code
OUTPUT_VARIABLE qt5_install_prefix
OUTPUT_STRIP_TRAILING_WHITESPACE
)
OUTPUT_STRIP_TRAILING_WHITESPACE)

set(_WINDEPLOYQT_EXECUTABLE "${qt5_install_prefix}/bin/windeployqt.exe")

Expand Down
2 changes: 1 addition & 1 deletion dialogs/analyzerdialog/analyzerdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void AnalyzerDialog::onAnalyzerItemChanged(QStandardItem* item)
void AnalyzerDialog::getAnalyzers()
{
m_analyzersmodel->clear();
m_analyzersmodel->setHorizontalHeaderLabels({"Name", "Description", "ID", "Order"});
m_analyzersmodel->setHorizontalHeaderLabels({tr("Name"), tr("Description"), tr("ID"), tr("Order")});

RDContext_GetAnalyzers(m_context.get(), [](const RDAnalyzer* a, void* userdata) {
auto* thethis = reinterpret_cast<AnalyzerDialog*>(userdata);
Expand Down
4 changes: 2 additions & 2 deletions dialogs/databasedialog/databasedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ DatabaseDialog::DatabaseDialog(const RDContextPtr& ctx, QWidget *parent) : QDial
QByteArray decompiled;

if(!dbdatamodel->decompile(decompiled)) {
QMessageBox::information(this, "Decompilation Failed", QString("Cannot decompile '%1'").arg(dbdatamodel->databaseName()));
QMessageBox::information(this, tr("Decompilation Failed"), tr("Cannot decompile '%1'").arg(dbdatamodel->databaseName()));
return;
}

QString s = QFileDialog::getSaveFileName(this, "Export Database", QString("%1.json").arg(dbdatamodel->databaseName()), "REDasm Source Database (*.json)");
QString s = QFileDialog::getSaveFileName(this, tr("Export Database"), tr("%1.json").arg(dbdatamodel->databaseName()), "REDasm Source Database (*.json)");
if(s.isEmpty()) return;

QFile f(s);
Expand Down
30 changes: 15 additions & 15 deletions hooks/disassemblerhooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void DisassemblerHooks::resetLayout()

void DisassemblerHooks::open()
{
QString s = QFileDialog::getOpenFileName(m_mainwindow, "Disassemble file...");
QString s = QFileDialog::getOpenFileName(m_mainwindow, tr("Disassemble file..."));
if(!s.isEmpty()) this->load(s);
}

Expand All @@ -120,7 +120,7 @@ void DisassemblerHooks::saveAs()
RDContextPtr ctx = DisassemblerHooks::activeContext();
if(!ctx) return;

QString s = QFileDialog::getSaveFileName(m_mainwindow, "Save State...", m_fileinfo.fileName(), "REDasm State (*.rds)");
QString s = QFileDialog::getSaveFileName(m_mainwindow, tr("Save State..."), m_fileinfo.fileName(), "REDasm State (*.rds)");
if(!s.isEmpty()) this->saveAs(ctx, s);
}

Expand All @@ -147,7 +147,7 @@ void DisassemblerHooks::showFLC()
void DisassemblerHooks::showCallGraph(rd_address address)
{
auto* cgv = new CallGraphView(this->activeContext());
this->showDialog("Callgraph @ " + QString::fromStdString(rd_tohex(address)), cgv);
this->showDialog(tr("Callgraph @ ") + QString::fromStdString(rd_tohex(address)), cgv);
cgv->walk(address);
}

Expand Down Expand Up @@ -185,8 +185,8 @@ void DisassemblerHooks::statusAddress(const SurfaceQt* surface) const
RDLocation functionstart = RDDocument_GetFunctionStart(doc, address);
RDLocation offset = RD_Offset(surface->context().get(), address);

QString segm = hassegment ? segment.name : "UNKNOWN",
offs = hassegment && offset.valid ? RD_ToHexAuto(surface->context().get(), offset.value) : "UNKNOWN",
QString segm = hassegment ? segment.name : tr("UNKNOWN"),
offs = hassegment && offset.valid ? RD_ToHexAuto(surface->context().get(), offset.value) : tr("UNKNOWN"),
addr = RD_ToHexAuto(surface->context().get(), address);

QString s = QString::fromWCharArray(L"<b>Address: </b>%1\u00A0\u00A0").arg(addr);
Expand Down Expand Up @@ -267,9 +267,9 @@ void DisassemblerHooks::showLoaders(const QString& filepath, RDBuffer* buffer)

const RDLoader* loader = RDContext_GetLoader(ctx.get());
const RDAssembler* assembler = RDContext_GetAssembler(ctx.get());
rd_log(qUtf8Printable(QString("Selected loader '%1' with '%2' assembler").arg(RDLoader_GetName(loader), RDAssembler_GetName(assembler))));
rd_log(qUtf8Printable(tr("Selected loader '%1' with '%2' assembler").arg(RDLoader_GetName(loader), RDAssembler_GetName(assembler))));

rd_log(qUtf8Printable(QString("Minimum string length set to %1").arg(dlgloader.selectedMinString())));
rd_log(qUtf8Printable(tr("Minimum string length set to %1").arg(dlgloader.selectedMinString())));
RDContext_SetMinString(ctx.get(), dlgloader.selectedMinString());

AnalyzerDialog dlganalyzer(ctx, m_mainwindow);
Expand Down Expand Up @@ -322,7 +322,7 @@ void DisassemblerHooks::loadRecents()
if(recents.empty()) return;

mnurecents->addSeparator();
QAction* action = mnurecents->addAction("Clear");
QAction* action = mnurecents->addAction(tr("Clear"));

connect(action, &QAction::triggered, this, [=]() {
this->clearRecents();
Expand Down Expand Up @@ -386,8 +386,8 @@ void DisassemblerHooks::reshortcutWindow()

void DisassemblerHooks::checkListingMode()
{
if(RDContext_HasFlag(this->activeContext().get(), ContextFlags_ShowRDIL)) m_pbrenderer->setText("RDIL");
else m_pbrenderer->setText("Listing");
if(RDContext_HasFlag(this->activeContext().get(), ContextFlags_ShowRDIL)) m_pbrenderer->setText(tr("RDIL"));
else m_pbrenderer->setText(tr("Listing"));
}

void DisassemblerHooks::showOutput()
Expand Down Expand Up @@ -450,8 +450,8 @@ void DisassemblerHooks::enableMenu(QMenu* menu, bool enable)

void DisassemblerHooks::saveAs(const RDContextPtr& ctx, const QString& filepath)
{
std::string fp = filepath.toStdString();
if(RDContext_Save(ctx.get(), fp.c_str())) rd_log("Saving Database '" + fp + "'");
if(RDContext_Save(ctx.get(), qUtf8Printable(filepath)))
rd_log(tr("Saving Database '%1'").arg(filepath).toStdString());
}

bool DisassemblerHooks::openDatabase(const QString& filepath)
Expand All @@ -476,7 +476,7 @@ void DisassemblerHooks::enableViewCommands(bool enable)
void DisassemblerHooks::openHomePage() const { QDesktopServices::openUrl(QUrl("https://redasm.io")); }
void DisassemblerHooks::openTwitter() const { QDesktopServices::openUrl(QUrl("https://twitter.com/re_dasm")); }
void DisassemblerHooks::openTelegram() const { QDesktopServices::openUrl(QUrl("https://t.me/REDasmDisassembler")); }
void DisassemblerHooks::openReddit() const { QDesktopServices::openUrl(QUrl("https://www.reddit.com/r/REDasm")); }
void DisassemblerHooks::openReddit() const { QDesktopServices::openUrl(QUrl("https://www.reddit.com/r/REDasm")); }
void DisassemblerHooks::openGitHub() const { QDesktopServices::openUrl(QUrl("https://github.com/REDasmOrg/REDasm/issues")); }

void DisassemblerHooks::showMessage(const QString& title, const QString& msg, size_t icon)
Expand All @@ -501,7 +501,7 @@ void DisassemblerHooks::updateViewWidgets(bool busy)

if(busy)
{
m_mainwindow->setWindowTitle(QString("%1 (Working)").arg(m_fileinfo.fileName()));
m_mainwindow->setWindowTitle(QString("%1 (%2)").arg(m_fileinfo.fileName(), tr("Working")));
m_lblstatusicon->setStyleSheet("color: red;");
}
else
Expand All @@ -515,7 +515,7 @@ void DisassemblerHooks::updateViewWidgets(bool busy)
if(this->activeContext())
{
m_pbproblems->setVisible(!busy && RDContext_HasProblems(this->activeContext().get()));
m_pbproblems->setText(QString::number(RDContext_GetProblemsCount(this->activeContext().get())) + " problem(s)");
m_pbproblems->setText(QString::number(RDContext_GetProblemsCount(this->activeContext().get())) + tr(" problem(s)"));
}
else
m_pbproblems->setVisible(false);
Expand Down
62 changes: 31 additions & 31 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ MainWindow::MainWindow() : KDDockWidgets::MainWindow("MainWindow", KDDockWidgets
toolbar->setMovable(false);
toolbar->setFloatable(false);
toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
toolbar->addAction(FA_ICON(0xf07c), "Open", []() { DisassemblerHooks::instance()->open(); });
toolbar->addAction(FA_ICON(0xf0c7), "Save", []() { DisassemblerHooks::instance()->save(); });
toolbar->addAction(FA_ICON(0xf07c), tr("Open"), []() { DisassemblerHooks::instance()->open(); });
toolbar->addAction(FA_ICON(0xf0c7), tr("Save"), []() { DisassemblerHooks::instance()->save(); });
this->addToolBar(Qt::ToolBarArea::TopToolBarArea, toolbar);

m_lblstatus = new QLabel(this);
Expand Down Expand Up @@ -132,23 +132,23 @@ void MainWindow::createFileMenu()
{
auto* mnubar = this->menuBar();

auto* mnufile = new QMenu("&File", mnubar);
auto* actopen = mnufile->addAction("Open");
auto* mnufile = new QMenu(tr("&File"), mnubar);
auto* actopen = mnufile->addAction(tr("Open"));

auto* actsave = mnufile->addAction("Save");
auto* actsave = mnufile->addAction(tr("Save"));

auto* actsaveas = mnufile->addAction("Save As");
auto* actsaveas = mnufile->addAction(tr("Save As"));
actsaveas->setObjectName(HOOK_ACTION_SAVE_AS);

auto* mnurecents = new QMenu("&Recent Files", mnubar);
auto* mnurecents = new QMenu(tr("&Recent Files"), mnubar);
mnurecents->setObjectName(HOOK_ACTION_RECENT_FILES);
mnufile->addMenu(mnurecents);

auto* actclose = mnufile->addAction("Close");
auto* actclose = mnufile->addAction(tr("Close"));
actclose->setObjectName(HOOK_ACTION_CLOSE);

mnufile->addSeparator();
auto* actexit = mnufile->addAction("Exit");
auto* actexit = mnufile->addAction(tr("Exit"));

actopen->setIcon(FA_ICON(0xf07c));
actsave->setIcon(FA_ICON(0xf0c7));
Expand All @@ -166,11 +166,11 @@ void MainWindow::createREDasmMenu()
auto* mnubar = this->menuBar();
auto* mnuredasm = new QMenu("&REDasm", mnubar);

auto* actflc = mnuredasm->addAction("FLC");
auto* actdevtools = mnuredasm->addAction("Developer Tools");
auto* actdatabase = mnuredasm->addAction("Database");
auto* actflc = mnuredasm->addAction(tr("FLC"));
auto* actdevtools = mnuredasm->addAction(tr("Developer Tools"));
auto* actdatabase = mnuredasm->addAction(tr("Database"));
mnuredasm->addSeparator();
auto* actsettings = mnuredasm->addAction("Settings");
auto* actsettings = mnuredasm->addAction(tr("Settings"));
mnubar->addMenu(mnuredasm);

actflc->setShortcut(QKeySequence("CTRL+F"));
Expand All @@ -189,21 +189,21 @@ void MainWindow::createREDasmMenu()
void MainWindow::createWindowMenu()
{
auto* mnubar = this->menuBar();
auto* mnuwindow = new QMenu("&Window", mnubar);
auto* mnuwindow = new QMenu(tr("&Window"), mnubar);
mnuwindow->setObjectName(HOOK_MENU_WINDOW);

mnuwindow->addAction("&Manage Layouts");
auto* actresetlayout = mnuwindow->addAction("&Reset Layout");
mnuwindow->addAction(tr("&Manage Layouts"));
auto* actresetlayout = mnuwindow->addAction(tr("&Reset Layout"));

QMenu* mnusubviews = mnuwindow->addMenu("&Open Subviews");
mnusubviews->addAction("Listing", this, []() { if(DisassemblerHooks::docks()) DisassemblerHooks::docks()->showListing(); });
mnusubviews->addAction("Segments", this, []() { if(DisassemblerHooks::docks()) DisassemblerHooks::docks()->showSegments(); });
mnusubviews->addAction("Exports", this, []() { if(DisassemblerHooks::docks()) DisassemblerHooks::docks()->showExports(); });
mnusubviews->addAction("Imports", this, []() { if(DisassemblerHooks::docks()) DisassemblerHooks::docks()->showImports(); });
mnusubviews->addAction("Strings", this, []() { if(DisassemblerHooks::docks()) DisassemblerHooks::docks()->showStrings(); });
QMenu* mnusubviews = mnuwindow->addMenu(tr("&Open Subviews"));
mnusubviews->addAction(tr("Listing"), this, []() { if(DisassemblerHooks::docks()) DisassemblerHooks::docks()->showListing(); });
mnusubviews->addAction(tr("Segments"), this, []() { if(DisassemblerHooks::docks()) DisassemblerHooks::docks()->showSegments(); });
mnusubviews->addAction(tr("Exports"), this, []() { if(DisassemblerHooks::docks()) DisassemblerHooks::docks()->showExports(); });
mnusubviews->addAction(tr("Imports"), this, []() { if(DisassemblerHooks::docks()) DisassemblerHooks::docks()->showImports(); });
mnusubviews->addAction(tr("Strings"), this, []() { if(DisassemblerHooks::docks()) DisassemblerHooks::docks()->showStrings(); });
mnusubviews->addSeparator();
mnusubviews->addAction("Functions", this, []() { if(DisassemblerHooks::docks()) DisassemblerHooks::docks()->showFunctions(); });
mnusubviews->addAction("Map", this, []() { if(DisassemblerHooks::docks()) DisassemblerHooks::docks()->showMap(); });
mnusubviews->addAction(tr("Functions"), this, []() { if(DisassemblerHooks::docks()) DisassemblerHooks::docks()->showFunctions(); });
mnusubviews->addAction(tr("Map"), this, []() { if(DisassemblerHooks::docks()) DisassemblerHooks::docks()->showMap(); });

mnuwindow->addSeparator();
mnubar->addMenu(mnuwindow);
Expand All @@ -216,11 +216,11 @@ void MainWindow::createHelpMenu()
auto* mnubar = this->menuBar();
auto* mnuhelp = new QMenu("&?", mnubar);

auto* acttelegram = mnuhelp->addAction("&Telegram");
auto* actreddit = mnuhelp->addAction("&Reddit");
auto* acttelegram = mnuhelp->addAction(tr("&Telegram"));
auto* actreddit = mnuhelp->addAction(tr("&Reddit"));
mnuhelp->addSeparator();
auto* actgithub = mnuhelp->addAction("Report an &Issue");
auto* actabout = mnuhelp->addAction("&About");
auto* actgithub = mnuhelp->addAction(tr("Report an &Issue"));
auto* actabout = mnuhelp->addAction(tr("&About"));
mnubar->addMenu(mnuhelp);

connect(acttelegram, &QAction::triggered, DisassemblerHooks::instance(), &DisassemblerHooks::openTelegram);
Expand Down Expand Up @@ -284,8 +284,8 @@ bool MainWindow::canClose()
if(DisassemblerHooks::instance()->isLoaded())
{
QMessageBox msgbox(this);
msgbox.setWindowTitle("Closing");
msgbox.setText("Are you sure?");
msgbox.setWindowTitle(tr("Closing"));
msgbox.setText(tr("Are you sure?"));
msgbox.setStandardButtons(QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel);

if(msgbox.exec() != QMessageBox::Yes)
Expand All @@ -310,7 +310,7 @@ void MainWindow::initializeConfig()

RDConfig_SetProgressCallback([](size_t pending, void* userdata) {
QLabel* lblprogress = reinterpret_cast<QLabel*>(userdata);
QMetaObject::invokeMethod(lblprogress, "setText", Qt::QueuedConnection, Q_ARG(QString, QString("%1 state(s) pending").arg(pending)));
QMetaObject::invokeMethod(lblprogress, "setText", Qt::QueuedConnection, Q_ARG(QString, tr("%1 state(s) pending").arg(pending)));
}, m_lblprogress);

RDConfig_AddDatabasePath(qUtf8Printable(QDir(RDConfig_GetRuntimePath()).absoluteFilePath(DATABASE_FOLDER_NAME)));
Expand Down
10 changes: 5 additions & 5 deletions models/dev/blocklistmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ QVariant BlockListModel::headerData(int section, Qt::Orientation orientation, in

switch(section)
{
case 0: return "Start Address";
case 1: return "End Address";
case 2: return "Size";
case 3: return "Type";
case 4: return "Label";
case 0: return tr("Start Address");
case 1: return tr("End Address");
case 2: return tr("Size");
case 3: return tr("Type");
case 4: return tr("Label");
default: break;
}

Expand Down
Loading

0 comments on commit 21e211f

Please sign in to comment.