-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchange_locale.sh
executable file
·80 lines (66 loc) · 2.04 KB
/
change_locale.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
#
# Helper script for changing the locale of the CV.
# The localized section need to be nested in a '%@@@LOCALIZATION@@@' block.
# The order of the localizations: en, fi, sw.
# Stop execution on error.
set -e
LANG=
# Check for flags.
while test $# -gt 0; do
case "$1" in
-en|--english)
LANG="en"
shift
;;
-fi|--finnish)
LANG="fi"
shift
;;
-sw|--swedish)
LANG="sw"
shift
;;
*)
break
;;
esac
done
if [ $# -ne 1 ]; then
echo "Provide a single input file for copying!"
exit 1
fi
if [ -z $LANG ]; then
echo "USAGE: change_locale.sh LANG-FLAG DOCUMENT"
echo " LANG-FLAGS:"
echo " -en|--english: english locale"
echo " -fi|--finnish: finnish locale"
echo " -sw|--swedish: swedish locale"
exit 1
fi
echo "Changing locale to $LANG..."
# Clean all previous comments
sed -i "/@@@LOCALIZATION@@@/{n;s/%//}" $1
sed -i "/@@@LOCALIZATION@@@/{n;n;s/%//}" $1
sed -i "/@@@LOCALIZATION@@@/{n;n;n;s/%//}" $1
# Comment out the irrelevant sections
case $LANG in
en)
sed -i "/@@@LOCALIZATION@@@/{n;n;s/^/%/}" $1
sed -i "/@@@LOCALIZATION@@@/{n;n;n;s/^/%/}" $1
sed -i -E 's/langname \{(english|finnish|swedish)\}/langname \{english\}/' $1
;;
fi)
sed -i "/@@@LOCALIZATION@@@/{n;s/^/%/}" $1
sed -i "/@@@LOCALIZATION@@@/{n;n;n;s/^/%/}" $1
sed -i -E 's/langname \{(english|finnish|swedish)\}/langname \{finnish\}/' $1
;;
sw)
sed -i "/@@@LOCALIZATION@@@/{n;s/^/%/}"
sed -i "/@@@LOCALIZATION@@@/{n;n;s/^/%/}"
sed -i -E 's/langname \{(english|finnish|swedish)\}/langname \{swedish\}/' $1
;;
*)
;;
esac
echo "Finished!"