-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtranslate.sh
executable file
·142 lines (128 loc) · 3.63 KB
/
translate.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
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
#!/bin/bash
#
# This script includes three tools to help with bulk translation operations:
# - One tool updates all translation .po files for every extension in the ADR project and copies
# the resulting files into a single folder `./build/translations` for sharing with UNAIDS
# - A further tool then copies files from this folder back to their original location
# - A final tool then runs compile_catalog for every language and every extension
#
# It is recommended prior to running these commands that you ensure that you have every repo
# checked out with latest development branch. You may then use `adx forall` command to make bulk
# operations across all desired repos.
#
# Also, check that the variables LANGUAGES and EXTENSIONS are set correctly prior to execution.
#
# To use this script:
# ```
# adx bash ckan
#
# bash /usr/lib/adx/translate.sh update_catalogs
#
# # Translate files that have been copied to `build/translations`
#
# bash /usr/lib/adx/translate.sh copy_translations
#
# # Check that files have been correctly copied back to their original position
#
# bash /usr/lib/adx/translate.sh compile_translations
# ```
set -e # exit when any command fails
LANGUAGES=(
fr
pt_PT
)
EXTENSIONS=(
unaids
restricted
scheming
validation
ytp-request
emailasusername
pages
dhis2harvester
harvest
blob-storage
versions
# Untranslated extensions
# geoview
)
read_manifest_xml () {
local IFS=\/\>
read -d \< ENTITY CONTENT
local ret=$?
TAG_NAME=${ENTITY%% *}
ATTRIBUTES=${ENTITY#* }
return $ret
}
process_extension () {
name=$1
if [[ $name == ckanext-* ]]; then
name=ckanext-$extension
echo $name
cd /usr/lib/adx/submodules/$name
python setup.py extract_messages
for lang in ${LANGUAGES[*]}
do
if ! ls /usr/lib/adx/submodules/$name/ckanext/**/i18n/$lang 1> /dev/null 2>&1; then
python setup.py init_catalog --locale $lang
fi
python setup.py update_catalog --locale $lang
cp /usr/lib/adx/submodules/$name/ckanext/**/i18n/$lang/LC_MESSAGES/*.po /usr/lib/adx/build/translations/$lang/
done
fi
}
process_all_extensions () {
for extension in ${EXTENSIONS[*]}
do
process_extension ckanext-$extension
done
cd /usr/lib/adx/build/translations
}
create_directory_structure () {
for lang in ${LANGUAGES[*]}
do
mkdir -p /usr/lib/adx/build/translations/$lang/
done
rm -f /usr/lib/adx/build/translations/**/*.po
}
report_work_done () {
echo "Extracted translation POs for..."
printf "ckanext-%s " "${EXTENSIONS[@]}"
echo ""
echo "and language codes..."
printf "%s " "${LANGUAGES[@]}"
echo ""
}
copy_translations () {
for extension in ${EXTENSIONS[*]}
do
for lang in ${LANGUAGES[*]}
do
folder_name=${extension//[-]/_}
name=ckanext-$extension
extension_name=${name//[-]/_}
cp /usr/lib/adx/build/translations/$lang/$extension_name.po /usr/lib/adx/submodules/$name/ckanext/$folder_name/i18n/$lang/LC_MESSAGES/ || :
done
done
}
compile_catalogs () {
for extension in ${EXTENSIONS[*]}
do
name=ckanext-$extension
echo $name
cd /usr/lib/adx/submodules/$name
for lang in ${LANGUAGES[*]}
do
python setup.py compile_catalog --locale $lang
done
done
cd /usr/lib/adx/build/translations
}
update_catalogs () {
create_directory_structure
process_all_extensions
report_work_done
}
source /usr/lib/ckan/venv/bin/activate
$1
deactivate