forked from Jibec/blog-hugo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_pot.sh
executable file
·87 lines (67 loc) · 2.17 KB
/
make_pot.sh
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
#!/bin/bash
# You need po4a > 0.54, see https://github.com/mquinson/po4a/releases
# There is no need of system-wide installation of po4a
# Usage: PERLLIB=/path/to/po4a/lib make_pot.sh
# you may set following variables
# SRCDIR root of the documentation repository
# POTDIR place where to create the pot
####################################
# INITILIZE VARIABLES
####################################
# root of the documentation repository
SRCDIR_MODULE="./content/fr"
# place where to create the pot files
if [ -z "$POTDIR" ] ; then
POTDIR="./l10n/pot"
fi
# place where the po files are
if [ -z "$PO_DIR" ] ; then
PO_DIR="./l10n/po"
fi
####################################
# TEST IF IT CAN WORK
####################################
if [ ! -d "$SRCDIR_MODULE" ] ; then
echo "Error, please check that SRCDIR match to the root of the documentation repository"
echo "You specified modules are in $SRCDIR_MODULE"
exit 1
fi
####################################
# HANDLE articles and pages
####################################
while IFS= read -r -d '' file
do
basename=$(basename -s .md "$file")
dirname=$(dirname "$file")
path="${dirname#$SRCDIR_MODULE/}"
if [ "$dirname" = "$SRCDIR_MODULE" ]; then
potname=$basename.pot
else
potname=$path/$basename.pot
mkdir -p "$POTDIR/$path"
fi
po4a-gettextize \
--format asciidoc \
--master "$file" \
--master-charset "UTF-8" \
--po "$POTDIR/$potname"
for lang in $(ls "$PO_DIR" ); do
po_file="$PO_DIR/$lang/${potname%.pot}.po"
# po4a-updatepo would be angry otherwise
sed -i 's/Content-Type: text\/plain; charset=CHARSET/Content-Type: text\/plain; charset=UTF-8/g' "$po_file"
if ! po4a-updatepo \
--format asciidoc \
--master "$file" \
--master-charset "UTF-8" \
--po "$po_file" ; then
echo ""
echo "Error updating $lang PO file for: $adoc_file"
fi
done
done < <(find -L "$SRCDIR_MODULE" -name "*.md" -print0)
echo ""
echo "REMOVE TEMPORARY FILES"
for lang in $(ls "$PO_DIR" ); do
rm "l10n/po/$lang/contact/"*.po~
rm "l10n/po/$lang/articles/"*.po~
done