share/hedgewars/Data/Locale/CMakeLists.txt
branchgettext
changeset 11168 e104e060911b
parent 10388 665d8b699d35
child 11172 db1d14179b6c
--- a/share/hedgewars/Data/Locale/CMakeLists.txt	Sat Sep 12 19:00:52 2015 +0200
+++ b/share/hedgewars/Data/Locale/CMakeLists.txt	Sat Sep 12 20:01:26 2015 +0200
@@ -1,29 +1,138 @@
 find_package(Qt4 REQUIRED)
 include(${QT_USE_FILE})
+find_package(Gettext REQUIRED)
 
 file(GLOB txttrans2 ??.txt)
 file(GLOB txttrans5 ?????.txt)
 file(GLOB tsfiles *.ts)
-file(GLOB luafiles *.lua)
 file(GLOB missionfiles missions_*.txt)
 file(GLOB campaignfiles campaigns_*.txt)
 file(GLOB tipfiles tips_*.xml)
 
-QT4_ADD_TRANSLATION(QM ${tsfiles})
+#QT4_ADD_TRANSLATION(QM ${tsfiles})
 
-add_custom_target (release-translation ALL
-        DEPENDS ${QM}
+set(qtpro "${PROJECT_SOURCE_DIR}/project_files/hedgewars.pro")
+
+add_custom_target(release-translation-qt
+        COMMAND ${QT_LRELEASE_EXECUTABLE} -silent ${qtpro}
         COMMENT "Compiling ts files"
 )
 
+file(GLOB pofiles *.po)
+
+string(REGEX REPLACE "(^|;)[^;]*/([^/]+).po($|;)" "\\1${CMAKE_CURRENT_BINARY_DIR}/\\2.mo\\3" mofiles "${pofiles}")
+
+add_custom_target(release-translation-lua
+        DEPENDS ${pofiles}
+        COMMENT "Compiling po files"
+)
+
+# compile all the pofiles
+foreach(pofile ${pofiles})
+
+    string(REGEX REPLACE "^.*/([^/]+).po" "\\1.mo" mofile ${pofile})
+
+#    add_custom_command(OUTPUT ${mofile}
+    add_custom_command(TARGET release-translation-lua
+        #COMMAND ${GETTEXT_MSGFMT_EXECUTABLE} "--statistics" "--output=${mofile}" ${pofile}
+        COMMAND ${GETTEXT_MSGFMT_EXECUTABLE} "--output=${mofile}" ${pofile}
+        #DEPENDS ${pofile}
+#        COMMENT "Compiling po file ${mofile}"
+    )
+
+endforeach(pofile)
+
+add_custom_target(release-translation ALL
+        DEPENDS release-translation-qt release-translation-lua
+)
+
+
+
+if(UPDATE_TRANSLATIONS)
+    # lua
+    set(loctemplate "messages.pot")
+    #set(luasearchroot "${PROJECT_SOURCE_DIR}/share/hedgewars/Data")
+    set(luasearchroot "..")
+
+    set(poargs
+            "--no-wrap"
+            "--add-location"
+            "--sort-by-file"
+    )
+
+    # make sure to pass relative paths
+    file(GLOB_RECURSE luafiles RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "${luasearchroot}/*.lua")
+
+    add_custom_command(OUTPUT ${loctemplate}
+        COMMAND "xgettext"
+            "--output=${CMAKE_CURRENT_BINARY_DIR}/${loctemplate}"
+            "--from-code=UTF-8"
+            "-k" "--keyword=loc"
+            ${poargs}
+            #"--add-comments=@loc"
+            ${luafiles}
+        DEPENDS ${luafiles}
+        # since we're using relative paths we need to work from within the source dir
+        WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+        COMMENT "Creating po template"
+    )
+
+    add_custom_target(update-translation-lua
+            COMMENT "Updating po files"
+            DEPENDS ${loctemplate}
+    )
+
+    # merge template with existing PO files
+    foreach(pofile ${pofiles})
+        add_custom_command(TARGET update-translation-lua
+            COMMAND ${GETTEXT_MSGMERGE_EXECUTABLE} "--quiet" "--update" "--backup=off" ${poargs} ${pofile} ${loctemplate}
+#COMMENT "Updating file ${pofile}"
+        )
+    endforeach(pofile)
+
+    add_dependencies(release-translation-lua update-translation-lua)
+
+    # qt
+    set(svrmsgsfile "${CMAKE_SOURCE_DIR}/QTfrontend/servermessages.h")
+
+    if(NOT EXISTS ${svrmsgsfile})
+        message(WARNING "\n"
+            "${svrmsgs} not found.\n"
+            "It is required for a proper QT translation files update!\n"
+            "\n"
+            "This is normal for out-of-dir builds.\n"
+            "Make a symlink to the file in the build-dir.\n"
+        )
+    endif()
+
+    add_custom_target(update-translation-qt
+        COMMAND ${QT_LUPDATE_EXECUTABLE} -silent -locations absolute -pro ${qtpro}
+        DEPENDS ${svrmsgsfile}
+        COMMENT "Updating ts files"
+    )
+
+    add_dependencies(release-translation-qt update-translation-qt)
+
+endif(UPDATE_TRANSLATIONS)
+
+
+
+#install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} DESTINATION "${SHAREPATH}Data"
+#        FILES_MATCHING PATTERN "*.mo"
+#        PATTERN "*/CMakeFiles" EXCLUDE
+#)
+
+#file(GLOB luafiles *.lua)
+
 install(FILES
+    ${mofiles}
+    #${luafiles}
     ${txttrans2}
     ${txttrans5}
     ${QM}
-    ${luafiles}
     ${missionfiles}
     ${campaignfiles}
     ${tipfiles}
-    DESTINATION ${SHAREPATH}Data/Locale
+    DESTINATION "${SHAREPATH}Data/Locale"
 )