5 if [ "$(uname)" == "Darwin" ]
13 FULLPATH=$(dirname "$(resolve "$0")")
15 if [ "$1" == "--help" ] || [ "$1" == "-h" ]
17 echo "$(basename "$(resolve "$0")") [options]"
19 echo "-a | --addon <name> extract strings from addon 'name'"
20 echo "-s | --single single addon mode: extract string from current folder"
26 if [ "$1" == "--addon" ] || [ "$1" == "-a" ]
29 if [ -z "$2" ]; then echo -e "ERROR: missing addon name\n\nrun_xgettext.sh -a <addonname>"; exit 1; fi
31 if [ ! -d "$FULLPATH/../addon/$ADDONNAME" ]; then echo "ERROR: addon '$ADDONNAME' not found"; exit 2; fi
34 if [ "$1" == "--single" ] || [ "$1" == "-s" ]
41 cd "$FULLPATH/../addon/$ADDONNAME"
42 mkdir -p "$FULLPATH/../addon/$ADDONNAME/lang/C"
43 OUTFILE="$FULLPATH/../addon/$ADDONNAME/lang/C/messages.po"
45 FINDOPTS="-path ./vendor -prune -or"
49 ADDONNAME=$(basename "$FULLPATH")
50 mkdir -p "$FULLPATH/lang/C"
51 OUTFILE="$FULLPATH/lang/C/messages.po"
53 FINDOPTS="-path ./vendor -prune -or"
54 echo "Extract strings for single addon '$ADDONNAME'"
58 OUTFILE="$FULLPATH/../view/lang/C/messages.po"
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"
63 F9KVERSION=$(cat ./VERSION);
64 echo "Friendica version $F9KVERSION"
69 KEYWORDS="-k -kt -ktt:1,2"
71 echo "Extract strings to $OUTFILE.."
72 [ -f "$OUTFILE" ] && rm "$OUTFILE"; touch "$OUTFILE"
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)
77 total_files=$(wc -l <<< "${find_result}")
80 for file in $find_result
83 echo -ne "Reading file $count/$total_files..."
85 # On Windows, find still outputs the name of pruned folders
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"
96 echo "Interpolate metadata.."
98 sed -i.bkp "s/^\"Plural-Forms.*$//g" "$OUTFILE"
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"
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"
117 if [ "" != "$1" ] && [ "$MODE" == "default" ]
119 UPDATEFILE="$(resolve "${FULLPATH}/$1")"
120 echo "Merging new strings to $UPDATEFILE.."
121 msgmerge -U "$OUTFILE" "$UPDATEFILE"
124 [ -f "$OUTFILE.bkp" ] && rm "$OUTFILE.bkp"