]> git.mxchange.org Git - friendica.git/blob - util/run_xgettext.sh
Merge pull request #2471 from annando/1604-diaspora-always-on
[friendica.git] / util / run_xgettext.sh
1 #!/bin/bash
2 FULLPATH=$(dirname $(readlink -f "$0"))
3
4 if [ "$1" == "--help" -o "$1" == "-h" ]
5 then
6         echo "$(basename $(readlink -f "$0")) [options]"
7         echo
8         echo "-a | --addon <name>       extract strings from addon 'name'"
9         echo "-s | --single                             single addon mode: extract string from current folder"
10         exit
11 fi
12
13 MODE='default'
14 ADDONNAME=
15 if [ "$1" == "--addon" -o "$1" == "-a" ]
16 then
17         MODE='addon'
18         if [ -z $2 ]; then echo -e "ERROR: missing addon name\n\nrun_xgettext.sh -a <addonname>"; exit 1; fi
19         ADDONNAME=$2
20         if [ ! -d "$FULLPATH/../addon/$ADDONNAME" ]; then echo "ERROR: addon '$ADDONNAME' not found"; exit 2; fi
21 fi
22
23 if [ "$1" == "--single" -o "$1" == "-s" ]
24 then
25         MODE='single'
26 fi
27
28
29 case "$MODE" in
30         'addon')
31                 cd "$FULLPATH/../addon/$ADDONNAME"
32                 mkdir -p "$FULLPATH/../addon/$ADDONNAME/lang/C"
33                 OUTFILE="$FULLPATH/../addon/$ADDONNAME/lang/C/messages.po"
34                 FINDSTARTDIR="."
35                 FINDOPTS=
36         ;;
37         'single')
38                 FULLPATH=$PWD
39                 ADDONNAME=$(basename $FULLPATH)
40                 mkdir -p "$FULLPATH/lang/C"
41                 OUTFILE="$FULLPATH/lang/C/messages.po"
42                 FINDSTARTDIR="."
43                 FINDOPTS=               
44                 echo "Extract strings for single addon '$ADDONNAME'"
45         ;;
46         'default')
47                 cd "$FULLPATH/.."
48                 OUTFILE="$FULLPATH/messages.po"
49                 FINDSTARTDIR="."
50                 # skip addon folder
51                 FINDOPTS="( -wholename */addon -or -wholename */addons-extra -or -wholename */smarty3 ) -prune -o"
52                 
53                 F9KVERSION=$(sed -n "s/.*'FRIENDICA_VERSION'.*'\([0-9.]*\)'.*/\1/p" ./boot.php);
54                 echo "Friendica version $F9KVERSION"
55         ;;
56 esac
57
58
59 KEYWORDS="-k -kt -ktt:1,2"
60
61 echo "extract strings to $OUTFILE.."
62 rm "$OUTFILE"; touch "$OUTFILE"
63 for f in $(find "$FINDSTARTDIR" $FINDOPTS -name "*.php" -type f)
64 do
65         if [ ! -d "$f" ]
66         then
67                 xgettext $KEYWORDS -j -o "$OUTFILE" --from-code=UTF-8 "$f"
68                 sed -i "s/CHARSET/UTF-8/g" "$OUTFILE"
69         fi
70 done
71
72 echo "setup base info.."
73 case "$MODE" in 
74         'addon'|'single')
75                 sed -i "s/SOME DESCRIPTIVE TITLE./ADDON $ADDONNAME/g" "$OUTFILE"
76                 sed -i "s/YEAR THE PACKAGE'S COPYRIGHT HOLDER//g" "$OUTFILE"
77                 sed -i "s/FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.//g" "$OUTFILE"
78                 sed -i "s/PACKAGE VERSION//g" "$OUTFILE"
79                 sed -i "s/PACKAGE/Friendica $ADDONNAME addon/g" "$OUTFILE"
80                 sed -i "s/CHARSET/UTF-8/g" "$OUTFILE"
81                 sed -i "s/^\"Plural-Forms.*$//g" "$OUTFILE"
82         ;;
83         'default')
84                 sed -i "s/SOME DESCRIPTIVE TITLE./FRIENDICA Distributed Social Network/g" "$OUTFILE"
85                 sed -i "s/YEAR THE PACKAGE'S COPYRIGHT HOLDER/2010, 2011, 2012, 2013 the Friendica Project/g" "$OUTFILE"
86                 sed -i "s/FIRST AUTHOR <EMAIL@ADDRESS>, YEAR./Mike Macgirvin, 2010/g" "$OUTFILE"
87                 sed -i "s/PACKAGE VERSION/$F9KVERSION/g" "$OUTFILE"
88                 sed -i "s/PACKAGE/Friendica/g" "$OUTFILE"
89                 sed -i "s/CHARSET/UTF-8/g" "$OUTFILE"
90                 sed -i "s/^\"Plural-Forms.*$//g" "$OUTFILE"
91         ;;
92 esac
93
94 if [ "" != "$1" -a "$MODE" == "default" ]
95 then
96         UPDATEFILE="$(readlink -f ${FULLPATH}/$1)"
97         echo "merging new strings to $UPDATEFILE.."
98         msgmerge -U $OUTFILE $UPDATEFILE
99 fi
100
101 echo "done."