-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathqtsmerge
52 lines (44 loc) · 1.19 KB
/
qtsmerge
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
#!/bin/bash -e
# 'msgmerge' for Qt Ts.
# Very naive method -- transform to po{,t}, merge and sweep.
trap '
_ret=("${PIPESTATUS[@]}") IFS=,
printf 'E:\t%s' "Line $LINENO, rets: ${_ret[*]}" >&2
exit "$_ret"
:' ERR
if [[ $1 == '--help' ]]; then
cat <<'EOF'
qtsmerge: merges Qt ts files using msgmerge for drunk guys.
The usage is the same as msgmerge, except that the output is always def.po.
(I don't want to parse -o for now)
EOF
exec msgmerge --help
# die early die quick
command -v msgmerge mktemp >/dev/null
if command -v lconvert >/dev/null; then
ts2po(){ lconvert -if ts -of po -locations relative -o "$2" "$1"; }
po2ts(){ lconvert -if po -of ts -locations absolute -o "$2" "$1"; }
elif command -v po2ts ts2po >/dev/null; then
:
else
false # No convertors found!
fi
tmpdir="$(mktemp -d)"
args=("$@")
cmd_subst(){
result=$("$@"; echo x)
result=${result%x}
}
# wild assumptions on args
pos=()
tss=()
for ts in "${args[-2]}" "${args[-1]}"; do
cmd_subst basename -- "$ts"
pos+=("${tmpdir}/${result%.[tT][sS]}.po")
tss+=("$ts")
ts2po "$ts" "${pos[-1]}"
done
# 0: po, 1: pot
cp -l "${tss[0]}"{,.bak}
msgmerge -o "${pos[1]}" "${@:1:$#-2}" "${pos[1]}" "${pos[0]}"
po2ts "${pos[0]}" "${tss[0]}"