Commit dd95f238 authored by Alexander Potashev's avatar Alexander Potashev Committed by Dmitry Kazakov

Import kundo2_aware_xgettext.sh from calligra.git repo

Reviewers: dkazakov, rempt

Reviewed By: rempt

Differential Revision: https://phabricator.kde.org/D3645
parent 86f7c654
#! /bin/sh
source krita_xgettext.sh
source kundo2_aware_xgettext.sh
$EXTRACTRC `find . -name \*.ui | grep -v '/tests/'` >> rc.cpp
RCFILES=`find . -name \*.xmlgui \
......@@ -19,7 +19,7 @@ perl extracti18n.pl > i18ndata
# Ignore sdk/templates which contains templates for writing future plugins.
# Also ignore crashreporter, it has it's own catalog
# None of the placeholder strings inside will be seen by users.
krita_xgettext krita.pot i18ndata rc.cpp \
kundo2_aware_xgettext krita.pot i18ndata rc.cpp \
`find . -name \*.cc -o -name \*.h -o -name \*.cpp | \
grep -v '/tests/' | grep -v './sdk/templates' | grep -v './krita/crashreporter/'`
......
#
# Helper function for extracting translatable messages from krita source code.
# Usage: krita_xgettext <pot-filename-without-path> <source-files-list>
# Helper function for extracting translatable messages from Calligra/Krita/Kexi source code.
# Usage: kundo2_aware_xgettext <pot-filename-without-path> <source-files-list>
# If there are no messages or the <source-files-list> is empty, the pot file is deleted.
#
# Example usage that creates $podir/myapp.pot file:
# krita_xgettext myapp.pot `find . -name \*.cpp -o -name \*.h`
# kundo2_aware_xgettext myapp.pot `find . -name \*.cpp -o -name \*.h`
#
function krita_xgettext() {
function kundo2_aware_xgettext() {
POTFILE="$podir/$1"
shift
if test -n "$*"; then
krita_xgettext_internal $* | tee "${POTFILE}" | tail -n1 | grep "^msgstr \"\"\$" > /dev/null \
# we rely on last line being a 'msgstr' signaling that strings has been extracted (a header is always present)
# normally it ends with 'msgstr ""' but if plural it can end with eg 'msgstr[1] ""'
kundo2_aware_xgettext_internal $* | tee "${POTFILE}" | tail -n1 | grep "^msgstr" > /dev/null \
|| rm -f "${POTFILE}" 2> /dev/null
fi
}
......@@ -32,10 +34,11 @@ function add_ctxt_qtundo() {
# Add msgctxt "(qtundo-format)" to messages not having msgctxt yet
#
# lastLine != "#, fuzzy" is the check for the .pot header.
# If lastLine starts with '"' the msgctxt has been split on several lines and is treated by sed above, so skip it
mv "${POT_PART_QUNDOFORMAT}" "${POT_PART_QUNDOFORMAT2}"
cat "${POT_PART_QUNDOFORMAT2}" | awk '
/^msgid "/ {
if (lastLine !~ /^msgctxt/ && lastLine !~ /^"/ && lastLine != "#, fuzzy") {
if (lastLine !~ /^\"/ && lastLine !~ /^msgctxt/ && lastLine != "#, fuzzy") {
print "msgctxt \"(qtundo-format)\""
}
}
......@@ -44,14 +47,23 @@ function add_ctxt_qtundo() {
rm -f "${POT_PART_QUNDOFORMAT2}"
}
function krita_xgettext_internal() {
function kundo2_aware_xgettext_internal() {
SRC_FILES="$*"
POT_PART_NORMAL="`mktemp $podir/_normal_XXXXXXXX.pot`"
POT_PART_QUNDOFORMAT="`mktemp $podir/_qundoformat_XXXXXXXX.pot`"
POT_MERGED="`mktemp $podir/_merged_XXXXXXXX.pot`"
$XGETTEXT ${CXG_EXTRA_ARGS} ${SRC_FILES} -o "${POT_PART_NORMAL}" --force-po
$XGETTEXT_PROGRAM --from-code=UTF-8 -C --kde -kkundo2_i18n:1 -kkundo2_i18np:1,2 -kkundo2_i18nc:1c,2 -kkundo2_i18ncp:1c,2,3 ${CXG_EXTRA_ARGS} ${SRC_FILES} -o "${POT_PART_QUNDOFORMAT}"
XGETTEXT_FLAGS_KUNDO2="\
--copyright-holder=This_file_is_part_of_KDE \
--msgid-bugs-address=http://bugs.kde.org \
--from-code=UTF-8
-C -k --kde \
-kkundo2_i18n:1 -kkundo2_i18np:1,2 -kkundo2_i18nc:1c,2 -kkundo2_i18ncp:1c,2,3 \
"
$XGETTEXT_PROGRAM ${XGETTEXT_FLAGS_KUNDO2} ${CXG_EXTRA_ARGS} ${SRC_FILES} -o "${POT_PART_QUNDOFORMAT}"
if [ $(cat ${POT_PART_NORMAL} ${POT_PART_QUNDOFORMAT} | grep -c \(qtundo-format\)) != 0 ]; then
echo "ERROR: Context '(qtundo-format)' should not be added manually. Use kundo2_i18n*() calls instead." 1>&2
......@@ -63,9 +75,12 @@ function krita_xgettext_internal() {
fi
if [ -s "${POT_PART_NORMAL}" -a -s "${POT_PART_QUNDOFORMAT}" ]; then
# ensure an empty line or else KDE_HEADER search will fail
# in case POT_PART_NORMAL only contains header
echo "" >>${POT_PART_NORMAL}
${MSGCAT} -F "${POT_PART_NORMAL}" "${POT_PART_QUNDOFORMAT}" > ${POT_MERGED}
MERGED_HEADER_LINE_COUNT=$(cat ${POT_MERGED} | grep "^$" -B 100000 --max-count=1 | wc -l)
KDE_HEADER="$(cat ${POT_PART_NORMAL} | grep "^$" -B 100000 --max-count=1)"
MERGED_TAIL="$(cat ${POT_MERGED} | tail -n +$MERGED_HEADER_LINE_COUNT)"
......@@ -73,8 +88,10 @@ function krita_xgettext_internal() {
echo "$KDE_HEADER"
echo "$MERGED_TAIL"
elif [ -s "${POT_PART_NORMAL}" ]; then
echo "# POT_PART_NORMAL only"
cat "${POT_PART_NORMAL}"
elif [ -s "${POT_PART_QUNDOFORMAT}" ]; then
echo "# POT_PART_QUNDOFORMAT only"
cat "${POT_PART_QUNDOFORMAT}"
fi
......@@ -83,7 +100,7 @@ function krita_xgettext_internal() {
# Sets EXCLUDE variable to excludes compatible with the find(1) command, e.g. '-path a -o -path b'.
# To unconditionally exclude dir (with subdirs) just put an empty file .i18n in it.
# To exclude dir for all translations but one, e.g. foo.pot, put a single "foo" line into the .i18n file.
# To disable excluding for given file, e.g. foo.pot, add "foo.pot" line to the .i18n file.
function find_exclude() {
EXCLUDE=""
for f in `find . -name .i18n | sed 's/\/\.i18n$//g' | sort`; do
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment