-
Notifications
You must be signed in to change notification settings - Fork 41
/
update-and-compile-translations.sh
executable file
·80 lines (68 loc) · 1.99 KB
/
update-and-compile-translations.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
#!/bin/bash
EXTENSION_ID="[email protected]"
TRANSLATION_ID="notes-extension"
if [ $# = 0 ]; then
echo "No parameter, exiting now."
echo ""
echo "Parameters and options for this script:"
echo " xx update only the language xx, and compile only xx"
echo " --pot update the pot file"
echo " --compile compile all languages (without updating them first)"
echo " --all update all translations files, and compile them all"
echo " --add xx add a .po file for the language xx"
exit 1
fi
################################################################################
function update_pot () {
echo "Generating .pot file..."
xgettext --files-from=POTFILES.in --from-code=UTF-8 --add-location=file --output=$EXTENSION_ID/locale/$TRANSLATION_ID.pot
}
function update_lang () {
echo "Updating translation for: $1"
msgmerge --update --previous $prefix/$1/LC_MESSAGES/$TRANSLATION_ID.po $prefix/$TRANSLATION_ID.pot
}
function compile_lang () {
echo "Compiling translation for: $1"
msgfmt $prefix/$1/LC_MESSAGES/$TRANSLATION_ID.po -o $prefix/$1/LC_MESSAGES/$TRANSLATION_ID.mo
rm -f "$prefix/$1/LC_MESSAGES/$TRANSLATION_ID.po~"
}
function create_po () {
mkdir -p $prefix/$1/LC_MESSAGES
msginit -i $prefix/$TRANSLATION_ID.pot --locale=el_GR -o $prefix/$1/LC_MESSAGES/$TRANSLATION_ID.po
update_lang $1
}
################################################################################
IFS='
'
liste=`ls ./$EXTENSION_ID/locale/`
prefix="./$EXTENSION_ID/locale"
if [ $1 = "--all" ]; then
update_pot
for lang_id in $liste
do
if [ "$lang_id" != "$TRANSLATION_ID.pot" ]; then
update_lang $lang_id
compile_lang $lang_id
fi
done
elif [ $1 = "--pot" ]; then
update_pot
elif [ $1 = "--compile-only" ]; then
for lang_id in $liste
do
if [ "$lang_id" != "$TRANSLATION_ID.pot" ]; then
compile_lang $lang_id
fi
done
elif [ $1 = "--add" ]; then
create_po $2
else
for lang_id in $@
do
if [ "$lang_id" != "$TRANSLATION_ID.pot" ]; then
update_lang $lang_id
compile_lang $lang_id
fi
done
fi
exit 0