forked from cyclingzealot/bin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generatePotFiles.bash
executable file
·149 lines (112 loc) · 3.37 KB
/
generatePotFiles.bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/usr/bin/env bash
#Usage, assuming a *nix box (Mac or Linux):
#
# * place the above in ~/bin/gen_pot.sh and make it executable
# * make sure that ~/bin is in your $PATH
# * in wp-content/themes, run gen_pot.sh yourtheme
# * or from within in your theme's dir, run gen_pot.sh
# * it'll output the pot file automatically...
START=$(date +%s.%N)
#Set the config file
configFile='~/.binJlam/templateConfig'
#exit when command fails (use || true when a command can fail)
set -o errexit
#exit when your script tries to use undeclared variables
#set -o nounset
#(a.k.a set -x) to trace what gets executed
########set -o xtrace
# in scripts to catch mysqldump fails
set -o pipefail
# Set magic variables for current file & dir
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
__root="$(cd "$(dirname "${__dir}")" && pwd)" # <-- change this
__file="${__dir}/$(basename "${BASH_SOURCE[0]}")"
__base="$(basename ${__file} .sh)"
ts=`date +'%Y%m%d-%H%M%S'`
#Capture everything to log
log=~/log/$__base-${ts}.log
exec > >(tee -a $log)
exec 2> >(tee -a $log >&2)
#Check that the config file exists
#if [[ ! -f "$configFile" ]] ; then
# echo "I need a file at $configFile with ..."
# exit 1
#fi
echo Begin `date` .....
### BEGIN SCRIPT ###############################################################
#!/bin/sh
#
# Author: Denis de Bernardy <http://www.mesoconcepts.com>
# Version: 0.1
# GPL licensed
# From: http://wordpress.stackexchange.com/questions/3555/how-do-i-add-a-new-string-to-a-po-or-pot-file#answer-3557
#
# Created by Ryan Boren
# Later code and patches from
# Kimmo Suominen (more) and Nikolay Bachiyski (less)
# Denis de Bernardy
cwd=`pwd`
firstArg=${1:-""}
if [ -n "$firstArg" ];
then
cd "$firstArg" || exit 1
slug=`basename $firstArg`
dir=$cwd/$slug
else
dir=$cwd
slug=`basename $cwd`
fi
pot_file=$slug.pot
cp /dev/null "$dir/$pot_file"
find . -name '*.php' -print \
| sed -e 's,^\./,,' \
| sort \
| xargs xgettext \
--keyword=__ \
--keyword=_e \
--keyword=_c \
--keyword=__ngettext:1,2 \
--keyword=_n:1,2 \
--default-domain=$slug \
--language=php \
--output="$dir/$pot_file" \
--join-existing \
--from-code utf-8 \
--copyright-holder='Mesoconcepts <http://www.mesoconcepts.com>' \
--msgid-bugs-address=https://tickets.semiologic.com
# sub only the YEAR in the copyright message (the 2nd line)
pwd
sed -e '2s/YEAR/'`date +%Y`'/' "$pot_file"
# and the cherry of the pie - extract version using magic - versoextracanus!~
if [ -f $dir/style.css ];
then
name=`fgrep -i 'Theme Name:' $dir/style.css`
version=`fgrep -i 'Version:' $dir/style.css`
elif [ -f $dir/$slug.php ];
then
#statements
name=`fgrep -i 'Plugin Name:' $dir/$slug.php`
version=`fgrep -i 'Version:' $dir/$slug.php`
else
name=$slug
version=
fi
name=${name##*:}
name=${name##[[:space:]]}
version=${version##*:}
version=${version##[[:space:]]}
version=${version%%[[:space:]]*}
if [ "$name" != '' ];
then
sed -e "1s/^# SOME DESCRIPTIVE TITLE/# $name pot file/" "$pot_file"
sed -e "s/\(^#.*\)PACKAGE\(.*\)/\1$name\2/g" "$pot_file"
fi
if [ "$version" != '' ];
then
sed -e "s/\(Project-Id-Version: \)PACKAGE VERSION/\1$version/" "$pot_file"
fi
cd "$cwd"
### END SCIPT ##################################################################
END=$(date +%s.%N)
DIFF=$(echo "$END - $START" | bc)
echo Done. `date` - $DIFF seconds