From b686a498e75e043efbbd3adddef1df12b7d64536 Mon Sep 17 00:00:00 2001 From: Evan Teran Date: Wed, 17 Jan 2024 18:00:28 -0500 Subject: [PATCH] adding in the basics of translations! (#847) --- .vscode/settings.json | 5 ++++- src/CMakeLists.txt | 19 ++++++++++++++++++- src/main.cpp | 13 ++++++++----- src/res/translations/.gitkeep | 0 4 files changed, 30 insertions(+), 7 deletions(-) create mode 100644 src/res/translations/.gitkeep diff --git a/.vscode/settings.json b/.vscode/settings.json index 098701272..7450e2a04 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,6 +1,9 @@ { "files.associations": { - "system_error": "cpp" + "*.go": "go", + "*.json": "json", + "system_error": "cpp", + "*.tcc": "cpp" }, "cSpell.words": [ "CLASSINFO", diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 862a6a193..a4b45f250 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -5,13 +5,30 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOUIC ON) -find_package(Qt5 5.0.0 REQUIRED Widgets Xml XmlPatterns Svg) +find_package(Qt5 5.0.0 REQUIRED Widgets Xml XmlPatterns Svg LinguistTools) + +qt5_add_translation(QM_FILES + # add translation files in /src/res/translations here +) + +# Create translations QRC file - translations.qrc +set(TRANSLATIONS_QRC "${CMAKE_CURRENT_BINARY_DIR}/translations.qrc") + +file(WRITE ${TRANSLATIONS_QRC} "\n\t") +foreach(QM_FILE ${QM_FILES}) + get_filename_component(QM_FILE_NAME ${QM_FILE} NAME) + file(APPEND ${TRANSLATIONS_QRC} "\n\t\t${QM_FILE_NAME}") +endforeach() + +file(APPEND ${TRANSLATIONS_QRC} "\n\t\n") +list(APPEND QRC_FILES ${TRANSLATIONS_QRC}) qt5_add_resources(QRC_SOURCES res/debugger.qrc res/themes.qrc res/breeze-edb.qrc res/breeze-dark-edb.qrc + ${TRANSLATIONS_QRC} ) foreach(FILE IN LISTS QRC_SOURCES) diff --git a/src/main.cpp b/src/main.cpp index b0ee5a1fa..8177d75ef 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -200,12 +200,15 @@ int start_debugger(const LaunchArguments &launch_args) { void load_translations() { // load some translations QTranslator qtTranslator; - qtTranslator.load("qt_" + QLocale::system().name(), QLibraryInfo::location(QLibraryInfo::TranslationsPath)); - qApp->installTranslator(&qtTranslator); + if (qtTranslator.load(QLocale(), QLatin1String("qtbase"), QLatin1String("_"), QLibraryInfo::location(QLibraryInfo::TranslationsPath))) { + qApp->installTranslator(&qtTranslator); + } - QTranslator myappTranslator; - myappTranslator.load("edb_" + QLocale::system().name()); - qApp->installTranslator(&myappTranslator); + QTranslator translator; + // look up e.g. :/translations/edb_{lang}.qm + if (translator.load(QLocale(), QLatin1String("edb"), QLatin1String("_"), QLatin1String(":/translations"))) { + qApp->installTranslator(&translator); + } } // See QtCreator: src/libs/utils/theme/theme.cpp diff --git a/src/res/translations/.gitkeep b/src/res/translations/.gitkeep new file mode 100644 index 000000000..e69de29bb