Add translation output to Cmake

This commit is contained in:
Mario Hüttel 2019-10-18 22:51:31 +02:00
parent b2ffc709bb
commit 7753e42078
3 changed files with 28 additions and 0 deletions

View File

@ -39,6 +39,7 @@ ENDIF(CMAKE_BUILD_TYPE STREQUAL "Debug")
add_subdirectory(resources)
add_subdirectory(doxygen)
add_subdirectory(translations)
add_subdirectory(version)
include_directories(${GLIB_INCLUDE_DIRS} ${GTK3_INCLUDE_DIRS} ${CAIRO_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}/include)

View File

@ -0,0 +1,4 @@
add_custom_target(translations
COMMAND ./generate-mo.sh "${PROJECT_BINARY_DIR}/translations"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Generating translation locales")

23
translations/generate-mo.sh Executable file
View File

@ -0,0 +1,23 @@
#!/bin/bash
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null && pwd )"
cd "$DIR"
if [ -z $1 ]; then
echo "Must supply an output name"
exit -2
fi
for langdir in `find ./pot/po -mindepth 1 -maxdepth 1 -type d`; do
lang=`basename "$langdir"`
dest="$1/locale/$lang/LC_MESSAGES"
mkdir -p "$dest"
pofiles=`find "$langdir" -name "*.po"`
msgfmt --output-file="$dest/gds-render.mo" "$pofiles"
done