Skip to content

Commit

Permalink
adding in the basics of translations! (#847)
Browse files Browse the repository at this point in the history
  • Loading branch information
eteran authored Jan 17, 2024
1 parent 64fca61 commit b686a49
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 7 deletions.
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"files.associations": {
"system_error": "cpp"
"*.go": "go",
"*.json": "json",
"system_error": "cpp",
"*.tcc": "cpp"
},
"cSpell.words": [
"CLASSINFO",
Expand Down
19 changes: 18 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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} "<RCC>\n\t<qresource prefix=\"/translations\">")
foreach(QM_FILE ${QM_FILES})
get_filename_component(QM_FILE_NAME ${QM_FILE} NAME)
file(APPEND ${TRANSLATIONS_QRC} "\n\t\t<file>${QM_FILE_NAME}</file>")
endforeach()

file(APPEND ${TRANSLATIONS_QRC} "\n\t</qresource>\n</RCC>")
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)
Expand Down
13 changes: 8 additions & 5 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Empty file added src/res/translations/.gitkeep
Empty file.

0 comments on commit b686a49

Please sign in to comment.