Skip to content

Commit

Permalink
Add translation support to CMake
Browse files Browse the repository at this point in the history
Add some strings for initial german translation
  • Loading branch information
carstene1ns committed Jun 18, 2022
1 parent 3870715 commit ba6e95f
Show file tree
Hide file tree
Showing 4 changed files with 8,774 additions and 2 deletions.
18 changes: 18 additions & 0 deletions CMakeLists.txt
Expand Up @@ -362,6 +362,7 @@ find_package(Qt5Core REQUIRED)
find_package(Qt5Multimedia REQUIRED)
find_package(Qt5Gui REQUIRED)
find_package(Qt5Svg REQUIRED)
find_package(Qt5LinguistTools REQUIRED)
find_package(ZLIB REQUIRED)
# liblcf
option(EDITOR_BUILD_LIBLCF "Instead of detecting liblcf the liblcf repository is cloned into lib/liblcf and built together with the Player. This is convenient for development" OFF)
Expand Down Expand Up @@ -440,6 +441,23 @@ set_target_properties(${EXE_NAME} PROPERTIES
AUTORCC ON
)

# Translations
set(TRANSLATION_SOURCES
translations/editor_de.ts
)
set(TRANSLATION_RES ${CMAKE_CURRENT_BINARY_DIR}/translations/editor.qrc)
configure_file(translations/editor.qrc ${TRANSLATION_RES} COPYONLY)
set_source_files_properties(${TRANSLATION_SOURCES} PROPERTIES
OUTPUT_LOCATION "translations")
qt5_add_translation(EDITOR_TRANSLATIONS ${TRANSLATION_SOURCES}
OPTIONS -compress -nounfinished -removeidentical)
target_sources(${EXE_NAME} PRIVATE ${TRANSLATION_RES} ${EDITOR_TRANSLATIONS})
add_custom_target(translations
COMMAND ${Qt5_LUPDATE_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/src -ts ${TRANSLATION_SOURCES}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Create/Update translations..."
COMMAND_EXPAND_LISTS VERBATIM)

# Add resources
target_sources(${EXE_NAME} PRIVATE "resources/Resources.qrc")

Expand Down
4 changes: 2 additions & 2 deletions src/main.cpp
Expand Up @@ -51,9 +51,9 @@ int main(int argc, char *argv[])
QString e = getenv("EASYRPG_EDITOR_LANG_FILE");
if (!e.isEmpty())
found = t.load(e);
#else
found = t.load(QLocale(), QLatin1String("easyrpg-editor"), QLatin1String("_"), QLatin1String(":/i18n"));
#endif
if (!found)
found = t.load(QLocale(), QLatin1String("easyrpg-editor"), QLatin1String("_"), QLatin1String(":/i18n"));
if (found)
a.installTranslator(&t);
else
Expand Down
5 changes: 5 additions & 0 deletions translations/editor.qrc
@@ -0,0 +1,5 @@
<RCC>
<qresource prefix="/i18n">
<file alias="easyrpg-editor_de.qm">editor_de.qm</file>
</qresource>
</RCC>

0 comments on commit ba6e95f

Please sign in to comment.