[BUGFIX] Namespace prefix t3 for id on file is not defined
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Build / Scripts / xlfcheck.sh
1 #!/bin/bash
2
3 #########################
4 #
5 # Find all xmlns:t3 namespace definition and
6 # t3:id numbers in XLF language files
7 # and check their uniqueness.
8 #
9 # Use from within TYPO3 CMS source
10 #
11 # @author Markus Klein <klein.t3@reelworx.at>
12 # @date 2014-11-14
13 #
14 ##########################
15
16 XLF_FILES="xlffiles.txt"
17 XLF_IDS="xlfids.txt"
18 XLF_XMLNS="xlfxmlns.txt"
19
20 function join { local IFS="$1"; shift; echo "$*"; }
21
22 echo 'Collecting XLF files'
23 find typo3/ -name '*.xlf' > $XLF_FILES
24 XLFCNT=$(cat xlffiles.txt | wc -l)
25
26 # Check for xmlns
27 echo 'Extracting xmlns:t3 information'
28 sed -ne 's/.*\(xmlns:t3="http:\/\/typo3.org\/schemas\/xliff"\)/\1/pg' `cat $XLF_FILES` | sort > $XLF_XMLNS
29 XLFXMLNSCNT=$(cat $XLF_XMLNS | wc -l)
30 DIFFXMLNS=$(join , $(uniq -d $XLF_XMLNS))
31 MISSINGXMLNS=$(join , $(grep -L 'xmlns:t3="http://typo3.org/schemas/xliff"' `cat $XLF_FILES`))
32
33 # Checks for t3:id
34 echo 'Extracting t3:id information'
35 sed -ne 's/.*t3:id="\([0-9]\+\)".*/\1/pg' `cat $XLF_FILES` | sort > $XLF_IDS
36
37 echo 'Processing ids'
38 XLFIDCNT=$(cat $XLF_IDS | wc -l)
39 UXLFIDCNT=$(uniq $XLF_IDS | wc -l)
40 DIFFIDS=$(join , $(uniq -d $XLF_IDS))
41 MISSINGIDS=$(join , $(grep -L 't3:id' `cat $XLF_FILES`))
42
43 # Cleanup of temporary files
44 rm $XLF_IDS $XLF_FILES $XLF_XMLNS
45
46 if [ $XLFCNT -ne $XLFXMLNSCNT ];
47 then
48 echo "There is at least one XLF file missing a xmlns for t3 (xmlns:t3)."
49 echo "Missing in: $MISSINGXMLNS"
50 exit 1
51 fi
52
53 if [ $XLFCNT -ne $XLFIDCNT ];
54 then
55 echo "There is at least one XLF file missing a unique ID (t3:id)."
56 echo "Missing in: $MISSINGIDS"
57 exit 1
58 fi
59 if [ $XLFIDCNT -ne $UXLFIDCNT ];
60 then
61 echo "There is an XLF id that does not seem to be UNIQUE."
62 echo "Search for t3:id $DIFFIDS"
63 exit 1
64 fi
65
66 exit 0