Commit dfa7f89c94fdc55b70cdf4722b7f1af9bd3414f0
1 parent
5de9f043
Compile translations into a ressource file and load them from there instead of m…
…essing around with installation paths.
Showing
5 changed files
with
19 additions
and
13 deletions
.travis.yml
| @@ -44,7 +44,7 @@ matrix: | @@ -44,7 +44,7 @@ matrix: | ||
| 44 | env: CMAKE_CXX_COMPILER=clang++-3.6 | 44 | env: CMAKE_CXX_COMPILER=clang++-3.6 |
| 45 | os: linux | 45 | os: linux |
| 46 | - compiler: clang | 46 | - compiler: clang |
| 47 | - env: CMAKE_CXX_COMPILER=clang++-3.6 | 47 | + env: CMAKE_CXX_COMPILER=/usr/bin/clang++ |
| 48 | os: osx | 48 | os: osx |
| 49 | 49 | ||
| 50 | before_install: | 50 | before_install: |
openhantek/CMakeLists.txt
| @@ -23,7 +23,7 @@ add_subdirectory(translations) | @@ -23,7 +23,7 @@ add_subdirectory(translations) | ||
| 23 | add_subdirectory(res) | 23 | add_subdirectory(res) |
| 24 | 24 | ||
| 25 | # make executable | 25 | # make executable |
| 26 | -add_executable(${PROJECT_NAME} ${SRC} ${HEADERS} ${QRC}) | 26 | +add_executable(${PROJECT_NAME} ${SRC} ${HEADERS} ${QRC} "${CMAKE_BINARY_DIR}/translations.qrc") |
| 27 | target_link_libraries(${PROJECT_NAME} Qt5::Widgets Qt5::PrintSupport Qt5::OpenGL ${OPENGL_LIBRARIES} ) | 27 | target_link_libraries(${PROJECT_NAME} Qt5::Widgets Qt5::PrintSupport Qt5::OpenGL ${OPENGL_LIBRARIES} ) |
| 28 | #target_compile_features(${PROJECT_NAME} PRIVATE cxx_range_for) | 28 | #target_compile_features(${PROJECT_NAME} PRIVATE cxx_range_for) |
| 29 | 29 |
openhantek/src/main.cpp
| @@ -38,12 +38,13 @@ int main(int argc, char *argv[]) { | @@ -38,12 +38,13 @@ int main(int argc, char *argv[]) { | ||
| 38 | QApplication openHantekApplication(argc, argv); | 38 | QApplication openHantekApplication(argc, argv); |
| 39 | 39 | ||
| 40 | QTranslator qtTranslator; | 40 | QTranslator qtTranslator; |
| 41 | - qtTranslator.load("qt_" + QLocale::system().name(), QLibraryInfo::location(QLibraryInfo::TranslationsPath)); | ||
| 42 | - openHantekApplication.installTranslator(&qtTranslator); | 41 | + if (qtTranslator.load("qt_" + QLocale::system().name(), QLibraryInfo::location(QLibraryInfo::TranslationsPath))) |
| 42 | + openHantekApplication.installTranslator(&qtTranslator); | ||
| 43 | 43 | ||
| 44 | QTranslator openHantekTranslator; | 44 | QTranslator openHantekTranslator; |
| 45 | - openHantekTranslator.load("openhantek_" + QLocale::system().name(), QMAKE_TRANSLATIONS_PATH); | ||
| 46 | - openHantekApplication.installTranslator(&openHantekTranslator); | 45 | + if (openHantekTranslator.load(QLocale(), QLatin1String("openhantek"), QLatin1String("_"), QLatin1String(":/translations"))) |
| 46 | + openHantekApplication.installTranslator(&openHantekTranslator); | ||
| 47 | + | ||
| 47 | 48 | ||
| 48 | OpenHantekMainWindow *openHantekMainWindow = new OpenHantekMainWindow(); | 49 | OpenHantekMainWindow *openHantekMainWindow = new OpenHantekMainWindow(); |
| 49 | openHantekMainWindow->show(); | 50 | openHantekMainWindow->show(); |
openhantek/translations/CMakeLists.txt
| @@ -6,8 +6,6 @@ if (NOT FOUND_Qt5LinguistTools) | @@ -6,8 +6,6 @@ if (NOT FOUND_Qt5LinguistTools) | ||
| 6 | return() | 6 | return() |
| 7 | endif() | 7 | endif() |
| 8 | 8 | ||
| 9 | -### translation stuff | ||
| 10 | - | ||
| 11 | file(GLOB TRANSLATION_FILES ${CMAKE_CURRENT_LIST_DIR}/*.ts) | 9 | file(GLOB TRANSLATION_FILES ${CMAKE_CURRENT_LIST_DIR}/*.ts) |
| 12 | 10 | ||
| 13 | qt5_create_translation(TRANSLATION_MESSAGES ${SRC} ${TRANSLATION_FILES}) | 11 | qt5_create_translation(TRANSLATION_MESSAGES ${SRC} ${TRANSLATION_FILES}) |
| @@ -15,8 +13,10 @@ qt5_add_translation(TRANSLATION_QM ${TRANSLATION_FILES}) | @@ -15,8 +13,10 @@ qt5_add_translation(TRANSLATION_QM ${TRANSLATION_FILES}) | ||
| 15 | add_custom_target(translations_update DEPENDS ${TRANSLATION_MESSAGES}) | 13 | add_custom_target(translations_update DEPENDS ${TRANSLATION_MESSAGES}) |
| 16 | add_custom_target(translations DEPENDS ${TRANSLATION_QM}) | 14 | add_custom_target(translations DEPENDS ${TRANSLATION_QM}) |
| 17 | 15 | ||
| 18 | -if(APPLE AND UNIX) ## OSX | ||
| 19 | - install(FILES ${TRANSLATION_QM} DESTINATION ${PROJECT_NAME}.app/Contents/Resources/translations) | ||
| 20 | -else() | ||
| 21 | - install(FILES ${TRANSLATION_QM} DESTINATION translations) | ||
| 22 | -endif() | ||
| 23 | \ No newline at end of file | 16 | \ No newline at end of file |
| 17 | +# We prepare the translations.qrc file and insert all available compiled translation files now. | ||
| 18 | +set(QRC_ITEMS "") | ||
| 19 | +foreach(TRANSLATION_FILE ${TRANSLATION_MESSAGES}) | ||
| 20 | + get_filename_component(FILENAME "${TRANSLATION_FILE}" NAME) | ||
| 21 | + set(QRC_ITEMS "${QRC_ITEMS}\n<file alias=\"${FILENAME}\">${TRANSLATION_FILE}</file>") | ||
| 22 | +endforeach() | ||
| 23 | +configure_file("${CMAKE_CURRENT_LIST_DIR}/translations.qrc" "${CMAKE_BINARY_DIR}/translations.qrc" @ONLY) |