Changeset View
Changeset View
Standalone View
Standalone View
krita_xgettext.sh
Show All 9 Lines | 9 | function krita_xgettext() { | |||
---|---|---|---|---|---|
10 | POTFILE="$podir/$1" | 10 | POTFILE="$podir/$1" | ||
11 | shift | 11 | shift | ||
12 | if test -n "$*"; then | 12 | if test -n "$*"; then | ||
13 | krita_xgettext_internal $* | tee "${POTFILE}" | tail -n1 | grep "^msgstr \"\"\$" > /dev/null \ | 13 | krita_xgettext_internal $* | tee "${POTFILE}" | tail -n1 | grep "^msgstr \"\"\$" > /dev/null \ | ||
14 | || rm -f "${POTFILE}" 2> /dev/null | 14 | || rm -f "${POTFILE}" 2> /dev/null | ||
15 | fi | 15 | fi | ||
16 | } | 16 | } | ||
17 | 17 | | |||
18 | function krita_xgettext_internal() { | 18 | # How to unit test: | ||
19 | SRC_FILES="$*" | 19 | # export podir=. | ||
20 | POT_PART_NORMAL="`mktemp $podir/_normal_XXXXXXXX.pot`" | 20 | # cp init-sample.pot sample.pot | ||
21 | POT_PART_QUNDOFORMAT="`mktemp $podir/_qundoformat_XXXXXXXX.pot`" | 21 | # source krita_xgettext.sh | ||
22 | # add_ctxt_qtundo sample.pot | ||||
23 | # | ||||
24 | # Then check that all messages in sample.pot have "(qtundo-format)" in msgctxt. | ||||
25 | function add_ctxt_qtundo() { | ||||
26 | POT_PART_QUNDOFORMAT="$1" | ||||
22 | POT_PART_QUNDOFORMAT2="`mktemp $podir/_qundoformat2_XXXXXXXX.pot`" | 27 | POT_PART_QUNDOFORMAT2="`mktemp $podir/_qundoformat2_XXXXXXXX.pot`" | ||
23 | POT_MERGED="`mktemp $podir/_merged_XXXXXXXX.pot`" | | |||
24 | | ||||
25 | $XGETTEXT ${CXG_EXTRA_ARGS} ${SRC_FILES} -o "${POT_PART_NORMAL}" --force-po | | |||
26 | $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}" | | |||
27 | 28 | | |||
28 | if [ $(cat ${POT_PART_NORMAL} ${POT_PART_QUNDOFORMAT} | grep -c \(qtundo-format\)) != 0 ]; then | | |||
29 | echo "ERROR: Context '(qtundo-format)' should not be added manually. Use kundo2_i18n*() calls instead." 1>&2 | | |||
30 | exit 17 | | |||
31 | fi | | |||
32 | | ||||
33 | if [ -s "${POT_PART_QUNDOFORMAT}" ]; then | | |||
34 | # Prepend "(qtundo-format)" to existing msgctxt properties of messages | 29 | # Prepend "(qtundo-format)" to existing msgctxt properties of messages | ||
35 | sed -i -e 's/^msgctxt "/msgctxt "(qtundo-format) /' "${POT_PART_QUNDOFORMAT}" | 30 | sed -i -e 's/^msgctxt "/msgctxt "(qtundo-format) /' "${POT_PART_QUNDOFORMAT}" | ||
36 | 31 | | |||
37 | # Add msgctxt "(qtundo-format)" to messages not having msgctxt yet | 32 | # Add msgctxt "(qtundo-format)" to messages not having msgctxt yet | ||
38 | # | 33 | # | ||
39 | # lastLine != "#, fuzzy" is the check for the .pot header. | 34 | # lastLine != "#, fuzzy" is the check for the .pot header. | ||
40 | mv "${POT_PART_QUNDOFORMAT}" "${POT_PART_QUNDOFORMAT2}" | 35 | mv "${POT_PART_QUNDOFORMAT}" "${POT_PART_QUNDOFORMAT2}" | ||
41 | cat "${POT_PART_QUNDOFORMAT2}" | awk ' | 36 | cat "${POT_PART_QUNDOFORMAT2}" | awk ' | ||
42 | /^msgid "/ { | 37 | /^msgid "/ { | ||
43 | if (lastLine !~ /^msgctxt/ && lastLine != "#, fuzzy") { | 38 | if (lastLine !~ /^msgctxt/ && lastLine !~ /^"/ && lastLine != "#, fuzzy") { | ||
44 | print "msgctxt \"(qtundo-format)\"" | 39 | print "msgctxt \"(qtundo-format)\"" | ||
45 | } | 40 | } | ||
46 | } | 41 | } | ||
47 | { print ; lastLine = $0 }' > "${POT_PART_QUNDOFORMAT}" | 42 | { print ; lastLine = $0 }' > "${POT_PART_QUNDOFORMAT}" | ||
43 | | ||||
44 | rm -f "${POT_PART_QUNDOFORMAT2}" | ||||
45 | } | ||||
46 | | ||||
47 | function krita_xgettext_internal() { | ||||
48 | SRC_FILES="$*" | ||||
49 | POT_PART_NORMAL="`mktemp $podir/_normal_XXXXXXXX.pot`" | ||||
50 | POT_PART_QUNDOFORMAT="`mktemp $podir/_qundoformat_XXXXXXXX.pot`" | ||||
51 | POT_MERGED="`mktemp $podir/_merged_XXXXXXXX.pot`" | ||||
52 | | ||||
53 | $XGETTEXT ${CXG_EXTRA_ARGS} ${SRC_FILES} -o "${POT_PART_NORMAL}" --force-po | ||||
54 | $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}" | ||||
55 | | ||||
56 | if [ $(cat ${POT_PART_NORMAL} ${POT_PART_QUNDOFORMAT} | grep -c \(qtundo-format\)) != 0 ]; then | ||||
57 | echo "ERROR: Context '(qtundo-format)' should not be added manually. Use kundo2_i18n*() calls instead." 1>&2 | ||||
58 | exit 17 | ||||
59 | fi | ||||
60 | | ||||
61 | if [ -s "${POT_PART_QUNDOFORMAT}" ]; then | ||||
62 | add_ctxt_qtundo "${POT_PART_QUNDOFORMAT}" | ||||
48 | fi | 63 | fi | ||
49 | 64 | | |||
50 | if [ -s "${POT_PART_NORMAL}" -a -s "${POT_PART_QUNDOFORMAT}" ]; then | 65 | if [ -s "${POT_PART_NORMAL}" -a -s "${POT_PART_QUNDOFORMAT}" ]; then | ||
51 | ${MSGCAT} -F "${POT_PART_NORMAL}" "${POT_PART_QUNDOFORMAT}" > ${POT_MERGED} | 66 | ${MSGCAT} -F "${POT_PART_NORMAL}" "${POT_PART_QUNDOFORMAT}" > ${POT_MERGED} | ||
52 | MERGED_HEADER_LINE_COUNT=$(cat ${POT_MERGED} | grep "^$" -B 100000 --max-count=1 | wc -l) | 67 | MERGED_HEADER_LINE_COUNT=$(cat ${POT_MERGED} | grep "^$" -B 100000 --max-count=1 | wc -l) | ||
53 | 68 | | |||
54 | KDE_HEADER="$(cat ${POT_PART_NORMAL} | grep "^$" -B 100000 --max-count=1)" | 69 | KDE_HEADER="$(cat ${POT_PART_NORMAL} | grep "^$" -B 100000 --max-count=1)" | ||
55 | MERGED_TAIL="$(cat ${POT_MERGED} | tail -n +$MERGED_HEADER_LINE_COUNT)" | 70 | MERGED_TAIL="$(cat ${POT_MERGED} | tail -n +$MERGED_HEADER_LINE_COUNT)" | ||
56 | 71 | | |||
57 | # Print out the resulting .pot | 72 | # Print out the resulting .pot | ||
58 | echo "$KDE_HEADER" | 73 | echo "$KDE_HEADER" | ||
59 | echo "$MERGED_TAIL" | 74 | echo "$MERGED_TAIL" | ||
60 | elif [ -s "${POT_PART_NORMAL}" ]; then | 75 | elif [ -s "${POT_PART_NORMAL}" ]; then | ||
61 | cat "${POT_PART_NORMAL}" | 76 | cat "${POT_PART_NORMAL}" | ||
62 | elif [ -s "${POT_PART_QUNDOFORMAT}" ]; then | 77 | elif [ -s "${POT_PART_QUNDOFORMAT}" ]; then | ||
63 | cat "${POT_PART_QUNDOFORMAT}" | 78 | cat "${POT_PART_QUNDOFORMAT}" | ||
64 | fi | 79 | fi | ||
65 | 80 | | |||
66 | rm -f "${POT_PART_NORMAL}" "${POT_PART_QUNDOFORMAT}" "${POT_PART_QUNDOFORMAT2}" "${POT_MERGED}" | 81 | rm -f "${POT_PART_NORMAL}" "${POT_PART_QUNDOFORMAT}" "${POT_MERGED}" | ||
67 | } | 82 | } | ||
68 | 83 | | |||
69 | # Sets EXCLUDE variable to excludes compatible with the find(1) command, e.g. '-path a -o -path b'. | 84 | # Sets EXCLUDE variable to excludes compatible with the find(1) command, e.g. '-path a -o -path b'. | ||
70 | # To unconditionally exclude dir (with subdirs) just put an empty file .i18n in it. | 85 | # To unconditionally exclude dir (with subdirs) just put an empty file .i18n in it. | ||
71 | # To exclude dir for all translations but one, e.g. foo.pot, put a single "foo" line into the .i18n file. | 86 | # To exclude dir for all translations but one, e.g. foo.pot, put a single "foo" line into the .i18n file. | ||
72 | function find_exclude() { | 87 | function find_exclude() { | ||
73 | EXCLUDE="" | 88 | EXCLUDE="" | ||
74 | for f in `find . -name .i18n | sed 's/\/\.i18n$//g' | sort`; do | 89 | for f in `find . -name .i18n | sed 's/\/\.i18n$//g' | sort`; do | ||
75 | if ! grep -q "^${1}$" "$f/.i18n" ; then | 90 | if ! grep -q "^${1}$" "$f/.i18n" ; then | ||
76 | if [ -n "$EXCLUDE" ] ; then EXCLUDE="$EXCLUDE -o " ; fi | 91 | if [ -n "$EXCLUDE" ] ; then EXCLUDE="$EXCLUDE -o " ; fi | ||
77 | EXCLUDE="$EXCLUDE -path $f" | 92 | EXCLUDE="$EXCLUDE -path $f" | ||
78 | fi | 93 | fi | ||
79 | done | 94 | done | ||
80 | if [ -z "$EXCLUDE" ] ; then EXCLUDE="-path __dummy__" ; fi # needed because -prune in find needs args | 95 | if [ -z "$EXCLUDE" ] ; then EXCLUDE="-path __dummy__" ; fi # needed because -prune in find needs args | ||
81 | } | 96 | } |