[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [calligra] /: i18n: Add/fix unit tests, fix calligra_xgettext.sh to pass all tests
From:       Dag Andersen <danders () get2net ! dk>
Date:       2016-12-01 14:22:10
Message-ID: E1cCSFW-00027U-C1 () code ! kde ! org
[Download RAW message or body]

Git commit 6b8b84d61edd513c54db4077f3c53e95558d3393 by Dag Andersen.
Committed on 01/12/2016 at 14:18.
Pushed by danders into branch 'master'.

i18n: Add/fix unit tests, fix calligra_xgettext.sh to pass all tests

Todo: Proper headers in pot files

CCMAIL: staniek@kde.org
Note: Kexi have the same problems

M  +12   -4    calligra_xgettext.sh
M  +1    -0    tests/CMakeLists.txt
M  +16   -0    tests/parameters.sh
M  +1    -1    tests/test_i18nc_long.cpp
A  +1    -0    tests/test_i18np.cpp     [License: Trivial file]
C  +4    -4    tests/test_i18np.sh [from: tests/test_xi18np.sh - 084% similarity]
M  +2    -2    tests/test_kundo2_i18n.sh
M  +1    -1    tests/test_kundo2_i18nc.sh
M  +1    -1    tests/test_kundo2_i18nc_long.sh
M  +1    -1    tests/test_xi18nc.sh
M  +1    -1    tests/test_xi18nc_long.sh
M  +1    -1    tests/test_xi18ncp.cpp
M  +1    -1    tests/test_xi18ncp.sh
M  +1    -1    tests/test_xi18np.cpp
M  +1    -1    tests/test_xi18np.sh

https://commits.kde.org/calligra/6b8b84d61edd513c54db4077f3c53e95558d3393

diff --git a/calligra_xgettext.sh b/calligra_xgettext.sh
index 5c9e639..d59351e 100644
--- a/calligra_xgettext.sh
+++ b/calligra_xgettext.sh
@@ -10,7 +10,9 @@ function calligra_xgettext() {
     POTFILE="$podir/$1"
     shift
     if test -n "$*"; then
-        calligra_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] ""' +        \
calligra_xgettext_internal $* | tee "${POTFILE}" | tail -n1 | grep "^msgstr" > \
/dev/null \  || rm -f "${POTFILE}" 2> /dev/null
     fi
 }
@@ -23,7 +25,7 @@ function calligra_xgettext_internal() {
     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_PROGRAM ${XGETTEXT_FLAGS_CALLIGRA} \
${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 @@ -37,10 +39,11 @@ function \
                calligra_xgettext_internal() {
         # 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 != "#, fuzzy") {
+                if (lastLine !~ /^\"/ && lastLine !~ /^msgctxt/ && lastLine != "#, \
fuzzy") {  print "msgctxt \"(qtundo-format)\""
                 }
             }
@@ -48,9 +51,12 @@ function calligra_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)"
 
@@ -58,8 +64,10 @@ function calligra_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
 
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 7b8b6f4..d3c6bac 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -29,6 +29,7 @@ if (BASH_PROGRAM AND XGETTEXT_PROGRAM AND MSGCAT_PROGRAM)
     # add tests here
     CALLIGRA_ADD_UNIT_TEST(test_i18n)
     CALLIGRA_ADD_UNIT_TEST(test_i18nc)
+    CALLIGRA_ADD_UNIT_TEST(test_i18np)
     CALLIGRA_ADD_UNIT_TEST(test_i18nc_long)
     CALLIGRA_ADD_UNIT_TEST(test_i18n_noop)
     CALLIGRA_ADD_UNIT_TEST(test_i18n_noop2)
diff --git a/tests/parameters.sh b/tests/parameters.sh
index e01bbfa..2236ff3 100644
--- a/tests/parameters.sh
+++ b/tests/parameters.sh
@@ -19,3 +19,19 @@ XGETTEXT_FLAGS="\
 -kI18N_NOOP2:1c,2 -kI18N_NOOP2_NOSTRIP:1c,2 \
 -ktr2i18n:1 -ktr2xi18n:1 \
 "
+# copy from extract-messages.sh
+XGETTEXT_FLAGS_WWW="\
+--copyright-holder=This_file_is_part_of_KDE \
+--msgid-bugs-address=http://bugs.kde.org \
+--from-code=UTF-8 \
+-L PHP \
+-ki18n -ki18n_var -ki18n_noop \
+"
+# flags for kundo extraction
+XGETTEXT_FLAGS_CALLIGRA="\
+--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 \
+"
diff --git a/tests/test_i18nc_long.cpp b/tests/test_i18nc_long.cpp
index 3ff4c99..40c4fde 100644
--- a/tests/test_i18nc_long.cpp
+++ b/tests/test_i18nc_long.cpp
@@ -1 +1 @@
-i18nc("This is a long kundo2_i18nc context string. It should be so long it is put on \
separate line from the 'msgctxt' by xgettext.", "long i18nc"); +i18nc("This is a long \
i18nc context string. It should be so long it is put on separate line from the \
                'msgctxt' by xgettext.", "long i18nc");
diff --git a/tests/test_i18np.cpp b/tests/test_i18np.cpp
new file mode 100644
index 0000000..6e6441f
--- /dev/null
+++ b/tests/test_i18np.cpp
@@ -0,0 +1 @@
+i18np("i18np singular", "i18np plural");
diff --git a/tests/test_xi18np.sh b/tests/test_i18np.sh
similarity index 84%
copy from tests/test_xi18np.sh
copy to tests/test_i18np.sh
index 245edbc..5f50f57 100644
--- a/tests/test_xi18np.sh
+++ b/tests/test_i18np.sh
@@ -1,5 +1,5 @@
 #! /bin/sh
-# test_xi18np:
+# test_i18np:
 # $1: calligra_xgettext.sh 
 # $2: xgettext
 # $3: msgcat
@@ -18,8 +18,8 @@ podir=$4
 # calligra_xgettext.sh wants this in one variable
 XGETTEXT="$XGETTEXT_PROGRAM $XGETTEXT_FLAGS"
 
-potfile="test_xi18np.pot"
-cppfile="test_xi18np.cpp"
+potfile="test_i18np.pot"
+cppfile="test_i18np.cpp"
 
 calligra_xgettext  $potfile $cppfile
 
@@ -32,7 +32,7 @@ if test 0 -ne `grep qtundo-format $podir/$potfile|wc -l`; then
     echo "FAIL: there should be 0 qtundo-format strings"
     exit 2
 fi
-if test 2 -ne `grep msgid $podir/$potfile|wc -l`; then
+if test 2 -ne `grep "^msgid \"" $podir/$potfile|wc -l`; then
     echo "FAIL: there should be 2 message strings"
     exit 3
 fi
diff --git a/tests/test_kundo2_i18n.sh b/tests/test_kundo2_i18n.sh
index 65413af..ddbe327 100644
--- a/tests/test_kundo2_i18n.sh
+++ b/tests/test_kundo2_i18n.sh
@@ -32,8 +32,8 @@ if test 1 -ne `grep qtundo-format $podir/$potfile|wc -l`; then
     echo "FAIL: there should be 1 qtundo-format strings"
     exit 2
 fi
-if test 2 -ne `grep msgid $podir/$potfile|wc -l`; then
-    echo "FAIL: there should be 2 message strings strings"
+if test 3 -ne `grep "^msgid \"" $podir/$potfile|wc -l`; then
+    echo "FAIL: there should be 3 message strings strings"
     exit 3
 fi
 
diff --git a/tests/test_kundo2_i18nc.sh b/tests/test_kundo2_i18nc.sh
index 935437d..90ab8ec 100644
--- a/tests/test_kundo2_i18nc.sh
+++ b/tests/test_kundo2_i18nc.sh
@@ -32,7 +32,7 @@ if test 1 -ne `grep qtundo-format $podir/$potfile|wc -l`; then
     echo "FAIL: there should be 1 qtundo-format strings"
     exit 2
 fi
-if test 2 -ne `grep msgid $podir/$potfile|wc -l`; then
+if test 2 -ne `grep "^msgid \"" $podir/$potfile|wc -l`; then
     echo "FAIL: there should be 2 message strings"
     exit 3
 fi
diff --git a/tests/test_kundo2_i18nc_long.sh b/tests/test_kundo2_i18nc_long.sh
index e040362..e0e5aef 100644
--- a/tests/test_kundo2_i18nc_long.sh
+++ b/tests/test_kundo2_i18nc_long.sh
@@ -32,7 +32,7 @@ if test 1 -ne `grep qtundo-format $podir/$potfile|wc -l`; then
     echo "FAIL: there should be 1 qtundo-format strings"
     exit 1
 fi
-if test 2 -ne `grep msgid $podir/$potfile|wc -l`; then
+if test 2 -ne `grep "^msgid \"" $podir/$potfile|wc -l`; then
     echo "FAIL: there should be 2 message strings"
     exit 1
 fi
diff --git a/tests/test_xi18nc.sh b/tests/test_xi18nc.sh
index 1216418..759e783 100644
--- a/tests/test_xi18nc.sh
+++ b/tests/test_xi18nc.sh
@@ -32,7 +32,7 @@ if test 0 -ne `grep qtundo-format $podir/$potfile|wc -l`; then
     echo "FAIL: there should be 0 qtundo-format strings"
     exit 2
 fi
-if test 2 -ne `grep msgid $podir/$potfile|wc -l`; then
+if test 2 -ne `grep "^msgid \"" $podir/$potfile|wc -l`; then
     echo "FAIL: there should be 2 message strings"
     exit 3
 fi
diff --git a/tests/test_xi18nc_long.sh b/tests/test_xi18nc_long.sh
index a903a91..3dcfcd5 100644
--- a/tests/test_xi18nc_long.sh
+++ b/tests/test_xi18nc_long.sh
@@ -32,7 +32,7 @@ if test 0 -ne `grep qtundo-format $podir/$potfile|wc -l`; then
     echo "FAIL: there should be 0 qtundo-format strings"
     exit 2
 fi
-if test 2 -ne `grep msgid $podir/$potfile|wc -l`; then
+if test 2 -ne `grep "^msgid \"" $podir/$potfile|wc -l`; then
     echo "FAIL: there should be 2 message strings"
     exit 3
 fi
diff --git a/tests/test_xi18ncp.cpp b/tests/test_xi18ncp.cpp
index 2e78d5e..bcca9ac 100644
--- a/tests/test_xi18ncp.cpp
+++ b/tests/test_xi18ncp.cpp
@@ -1 +1 @@
-xi18ncp("@info context", "xi18ncp singular", "xi18ncp plural %1", 2);
+xi18ncp("@info context", "xi18ncp singular: %1", "xi18ncp plural %1", 2);
diff --git a/tests/test_xi18ncp.sh b/tests/test_xi18ncp.sh
index 2aefb9b..4d7c52b 100644
--- a/tests/test_xi18ncp.sh
+++ b/tests/test_xi18ncp.sh
@@ -32,7 +32,7 @@ if test 0 -ne `grep qtundo-format $podir/$potfile|wc -l`; then
     echo "FAIL: there should be 0 qtundo-format strings"
     exit 2
 fi
-if test 2 -ne `grep msgid $podir/$potfile|wc -l`; then
+if test 2 -ne `grep "^msgid \"" $podir/$potfile|wc -l`; then
     echo "FAIL: there should be 2 message strings"
     exit 3
 fi
diff --git a/tests/test_xi18np.cpp b/tests/test_xi18np.cpp
index 4b67188..141a96a 100644
--- a/tests/test_xi18np.cpp
+++ b/tests/test_xi18np.cpp
@@ -1 +1 @@
-xI18np("xI18np singular", "xI18np plural", 2);
+xi18np("xi18np singular", "xi18np plural");
diff --git a/tests/test_xi18np.sh b/tests/test_xi18np.sh
index 245edbc..d3e2e36 100644
--- a/tests/test_xi18np.sh
+++ b/tests/test_xi18np.sh
@@ -32,7 +32,7 @@ if test 0 -ne `grep qtundo-format $podir/$potfile|wc -l`; then
     echo "FAIL: there should be 0 qtundo-format strings"
     exit 2
 fi
-if test 2 -ne `grep msgid $podir/$potfile|wc -l`; then
+if test 2 -ne `grep "^msgid \"" $podir/$potfile|wc -l`; then
     echo "FAIL: there should be 2 message strings"
     exit 3
 fi


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic