[TASK] Add XLF file checker for TRAVIS CI
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Build / Scripts / xlfcheck.sh
1 #!/bin/bash
2
3 #########################
4 #
5 # Find all t3:id numbers in XLF language files
6 # and check their uniqueness.
7 #
8 # @author Markus Klein <klein.t3@reelworx.at>
9 # @date 2014-11-14
10 #
11 ##########################
12
13 function join { local IFS="$1"; shift; echo "$*"; }
14
15 find typo3 -name '*.xlf' > xlffiles.txt
16 sed -ne 's/.*t3:id="\([0-9]\+\)".*/\1/pgM' `cat xlffiles.txt` | sort > xlfids.txt
17 uniq xlfids.txt > uxlfids.txt
18 XLFCNT=$(cat xlffiles.txt | wc -l)
19 XLFIDCNT=$(cat xlfids.txt | wc -l)
20 UXLFIDCNT=$(cat uxlfids.txt | wc -l)
21 DIFFIDS=$(join , $(uniq -d xlfids.txt))
22 MISSINGIDS=$(join , $(grep -LP 't3:id' `cat xlffiles.txt`))
23 rm xlfids.txt uxlfids.txt xlffiles.txt
24 if [ $XLFCNT -ne $XLFIDCNT ];
25 then
26 echo "There is at least one XLF file missing a unique ID (t3:id)."
27 echo "Missing in: $MISSINGIDS"
28 exit 1
29 fi
30 if [ $XLFIDCNT -ne $UXLFIDCNT ];
31 then
32 echo "There is an XLF id that does not seem to be UNIQUE."
33 echo "Search for t3:id $DIFFIDS"
34 exit 1
35 fi
36 exit 0