]> git.mxchange.org Git - friendica.git/blob - bin/run_xgettext.sh
Deprecated the notify table/classes
[friendica.git] / bin / run_xgettext.sh
1 #!/bin/bash
2 set -eo pipefail
3
4 function resolve {
5         if [ "$(uname)" == "Darwin" ]
6         then
7                 realpath "$1"
8         else
9                 readlink -f "$1"
10         fi
11 }
12
13 FULLPATH=$(dirname "$(resolve "$0")")
14
15 if [ "$1" == "--help" ] || [ "$1" == "-h" ]
16 then
17         echo "$(basename "$(resolve "$0")") [options]"
18         echo
19         echo "-a | --addon <name>       extract strings from addon 'name'"
20         echo "-s | --single                             single addon mode: extract string from current folder"
21         exit
22 fi
23
24 MODE='default'
25 ADDONNAME=
26 if [ "$1" == "--addon" ] || [ "$1" == "-a" ]
27 then
28         MODE='addon'
29         if [ -z "$2" ]; then echo -e "ERROR: missing addon name\n\nrun_xgettext.sh -a <addonname>"; exit 1; fi
30         ADDONNAME=$2
31         if [ ! -d "$FULLPATH/../addon/$ADDONNAME" ]; then echo "ERROR: addon '$ADDONNAME' not found"; exit 2; fi
32 fi
33
34 if [ "$1" == "--single" ] || [ "$1" == "-s" ]
35 then
36         MODE='single'
37 fi
38
39 case "$MODE" in
40         'addon')
41                 cd "$FULLPATH/../addon/$ADDONNAME"
42                 mkdir -p "$FULLPATH/../addon/$ADDONNAME/lang/C"
43                 OUTFILE="$FULLPATH/../addon/$ADDONNAME/lang/C/messages.po"
44                 FINDSTARTDIR="."
45                 FINDOPTS="-path ./vendor -prune -or"
46         ;;
47         'single')
48                 FULLPATH=$PWD
49                 ADDONNAME=$(basename "$FULLPATH")
50                 mkdir -p "$FULLPATH/lang/C"
51                 OUTFILE="$FULLPATH/lang/C/messages.po"
52                 FINDSTARTDIR="."
53                 FINDOPTS="-path ./vendor -prune -or"
54                 echo "Extract strings for single addon '$ADDONNAME'"
55         ;;
56         'default')
57                 cd "$FULLPATH/.."
58                 OUTFILE="$FULLPATH/../view/lang/C/messages.po"
59                 FINDSTARTDIR="."
60                 # skip addon folder
61                 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"
62                 
63                 F9KVERSION=$(cat ./VERSION);
64                 echo "Friendica version $F9KVERSION"
65         ;;
66 esac
67
68
69 KEYWORDS="-k -kt -ktt:1,2"
70
71 echo "Extract strings to $OUTFILE.."
72 [ -f "$OUTFILE" ] && rm "$OUTFILE"; touch "$OUTFILE"
73
74 # shellcheck disable=SC2086  # $FINDOPTS is meant to be split
75 find_result=$(find "$FINDSTARTDIR" $FINDOPTS -name "*.php" -type f | LC_ALL=C sort --stable)
76
77 total_files=$(wc -l <<< "${find_result}")
78
79 count=1
80 for file in $find_result
81 do
82         echo -ne "                                            \r"
83         echo -ne "Reading file $count/$total_files..."
84
85         # On Windows, find still outputs the name of pruned folders
86         if [ ! -d "$file" ]
87         then
88                 # shellcheck disable=SC2086  # $KEYWORDS is meant to be split
89                 xgettext $KEYWORDS -j -o "$OUTFILE" --from-code=UTF-8 "$file" || exit 1
90                 sed -i.bkp "s/CHARSET/UTF-8/g" "$OUTFILE"
91         fi
92         (( count++ ))
93 done
94 echo -ne "\n"
95
96 echo "Interpolate metadata.."
97
98 sed -i.bkp "s/^\"Plural-Forms.*$//g" "$OUTFILE"
99
100 case "$MODE" in
101         'addon'|'single')
102                 sed -i.bkp "s/SOME DESCRIPTIVE TITLE./ADDON $ADDONNAME/g" "$OUTFILE"
103                 sed -i.bkp "s/YEAR THE PACKAGE'S COPYRIGHT HOLDER//g" "$OUTFILE"
104                 sed -i.bkp "s/FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.//g" "$OUTFILE"
105                 sed -i.bkp "s/PACKAGE VERSION//g" "$OUTFILE"
106                 sed -i.bkp "s/PACKAGE/Friendica $ADDONNAME addon/g" "$OUTFILE"
107         ;;
108         'default')
109                 sed -i.bkp "s/SOME DESCRIPTIVE TITLE./FRIENDICA Distributed Social Network/g" "$OUTFILE"
110                 sed -i.bkp "s/YEAR THE PACKAGE'S COPYRIGHT HOLDER/2010-$(date +%Y), the Friendica project/g" "$OUTFILE"
111                 sed -i.bkp "s/FIRST AUTHOR <EMAIL@ADDRESS>, YEAR./Mike Macgirvin, 2010/g" "$OUTFILE"
112                 sed -i.bkp "s/PACKAGE VERSION/$F9KVERSION/g" "$OUTFILE"
113                 sed -i.bkp "s/PACKAGE/Friendica/g" "$OUTFILE"
114         ;;
115 esac
116
117 if [ "" != "$1" ] && [ "$MODE" == "default" ]
118 then
119         UPDATEFILE="$(resolve "${FULLPATH}/$1")"
120         echo "Merging new strings to $UPDATEFILE.."
121         msgmerge -U "$OUTFILE" "$UPDATEFILE"
122 fi
123
124 [ -f "$OUTFILE.bkp" ] && rm "$OUTFILE.bkp" 
125
126 echo "Done."