blob: 7d480818a6e7d28ef3aea20c42910ade81b600dd (
plain)
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
|
#!/usr/bin/env bash
set -eu
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "$SCRIPT_DIR"
# shellcheck disable=SC1091
source utils/log
function main {
case ${1:-""} in
prepare) prepare_localization_strings;;
upload) upload_to_crowdin;;
download) download_from_crowdin;;
sync-local-files) sync_localizations;;
verify) verify;;
"")
echo "Available subcommands: prepare, upload, download, sync-local-files and verify"
;;
*)
echo "Unknown parameter: $1"
exit 1
;;
esac
}
function sync_localizations {
# Update desktop strings in messages.pot
log_header "Extracting localization strings from desktop app source code"
pushd ../gui
npm run update-translations
popd
# Update android strings and add Android strings to messages.pot
log_header "Extracting localization strings from android app source code"
pushd ../android/translations-converter/
cargo run
popd
}
function update_relay_locations_pot {
log_header "Retrieving relay locations from server list and translating by using map data"
pushd ../gui/scripts
# Download geo data
curl -L -O https://www.naturalearthdata.com/http//www.naturalearthdata.com/download/50m/cultural/ne_50m_admin_0_countries.zip
curl -L -O https://www.naturalearthdata.com/http//www.naturalearthdata.com/download/50m/cultural/ne_50m_admin_1_states_provinces_lines.zip
curl -L -O https://www.naturalearthdata.com/http//www.naturalearthdata.com/download/10m/cultural/ne_10m_populated_places.zip
unzip ne_50m_admin_0_countries.zip -d ne_50m_admin_0_countries/
unzip ne_50m_admin_1_states_provinces_lines.zip -d ne_50m_admin_1_states_provinces_lines/
unzip ne_10m_populated_places.zip -d ne_10m_populated_places/
# Add translations from geo data
python3 extract-geo-data.py
python3 integrate-into-app.py
# Remove geo data
rm ne_10m_populated_places.zip \
ne_50m_admin_0_countries.zip \
ne_50m_admin_1_states_provinces_lines.zip
rm -r ne_10m_populated_places ne_50m_admin_0_countries ne_50m_admin_1_states_provinces_lines
git restore ../assets
popd
}
function commit_changes {
if [[ $(git diff --shortstat 2> /dev/null | tail -n1) != "" ]]; then
git commit -a -S -m "$1"
fi
}
function prepare_localization_strings {
sync_localizations
commit_changes "Update messages.pot"
update_relay_locations_pot
commit_changes "Update relay-locations.pot"
}
function ensure_crowdin_api_key {
test ! -z "$CROWDIN_API_KEY"
}
function upload_to_crowdin {
ensure_crowdin_api_key
log_header "Uploading translations to crowdin"
pushd ../gui
crowdin upload sources
popd
}
function download_from_crowdin {
ensure_crowdin_api_key
log_header "Downloading translations from crowdin"
pushd ../gui
crowdin download
popd
# Add new translations to Android xml-files
log_header "Updating Android xml-files with new translations"
sync_localizations
commit_changes "Update translations"
}
function verify {
sync_localizations
git diff
# shellcheck disable=SC2251
! git status -s | grep .
local out_of_sync=$?
pushd ../gui/scripts
npm exec ts-node verify-translations-format.ts
local incorrect_format=$?
popd
if [ "$out_of_sync" -ne 0 ] || [ "$incorrect_format" -ne 0 ]; then
exit 1
fi
}
main "$@"
|