]> git.mxchange.org Git - friendica.git/blob - bin/run_xgettext.sh
Partly revert coding for compatibility issues
[friendica.git] / bin / 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="-path ./vendor -prune -or"
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="-path ./vendor -prune -or"
44                 echo "Extract strings for single addon '$ADDONNAME'"
45         ;;
46         'default')
47                 cd "$FULLPATH/.."
48                 OUTFILE="$FULLPATH/../view/lang/C/messages.po"
49                 FINDSTARTDIR="."
50                 # skip addon folder
51                 FINDOPTS="( -path ./addon -or -path ./addons -or -path ./addons-extra -or -path ./tests -or -path ./view/lang -or -path ./view/smarty3 -or -path ./vendor ) -prune -or"
52                 
53                 F9KVERSION=$(cat ./VERSION);
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
64 find_result=$(find "$FINDSTARTDIR" $FINDOPTS -name "*.php" -type f)
65
66 total_files=$(wc -l <<< "${find_result}")
67
68 for file in $find_result
69 do
70         ((count++))
71         echo -ne "                                            \r"
72         echo -ne "Reading file $count/$total_files..."
73
74         # On Windows, find still outputs the name of pruned folders
75         if [ ! -d "$file" ]
76         then
77                 xgettext $KEYWORDS -j -o "$OUTFILE" --from-code=UTF-8 "$file" || exit 1
78                 sed -i "s/CHARSET/UTF-8/g" "$OUTFILE"
79         fi
80 done
81 echo -ne "\n"
82
83 echo "Interpolate metadata.."
84
85 sed -i "s/^\"Plural-Forms.*$//g" "$OUTFILE"
86
87 case "$MODE" in
88         'addon'|'single')
89                 sed -i "s/SOME DESCRIPTIVE TITLE./ADDON $ADDONNAME/g" "$OUTFILE"
90                 sed -i "s/YEAR THE PACKAGE'S COPYRIGHT HOLDER//g" "$OUTFILE"
91                 sed -i "s/FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.//g" "$OUTFILE"
92                 sed -i "s/PACKAGE VERSION//g" "$OUTFILE"
93                 sed -i "s/PACKAGE/Friendica $ADDONNAME addon/g" "$OUTFILE"
94         ;;
95         'default')
96                 sed -i "s/SOME DESCRIPTIVE TITLE./FRIENDICA Distributed Social Network/g" "$OUTFILE"
97                 sed -i "s/YEAR THE PACKAGE'S COPYRIGHT HOLDER/2010-$(date +%Y) the Friendica Project/g" "$OUTFILE"
98                 sed -i "s/FIRST AUTHOR <EMAIL@ADDRESS>, YEAR./Mike Macgirvin, 2010/g" "$OUTFILE"
99                 sed -i "s/PACKAGE VERSION/$F9KVERSION/g" "$OUTFILE"
100                 sed -i "s/PACKAGE/Friendica/g" "$OUTFILE"
101         ;;
102 esac
103
104 if [ "" != "$1" -a "$MODE" == "default" ]
105 then
106         UPDATEFILE="$(readlink -f ${FULLPATH}/$1)"
107         echo "Merging new strings to $UPDATEFILE.."
108         msgmerge -U $OUTFILE $UPDATEFILE
109 fi
110
111 echo "Done."