blob: ac0bf9924016b520a097ebaf7e8a13066453f603 (
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
131
132
133
134
135
136
137
138
139
140
141
142
|
#!/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 ../desktop/packages/mullvad-vpn
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 ../desktop/packages/mullvad-vpn/scripts
# Add translations from geo data
python3 fetch-relay-locations.py
python3 integrate-relay-locations.py
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"
update_ios_strings export
commit_changes "Update en.xliff"
}
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 ../desktop/packages/mullvad-vpn
crowdin upload sources
crowdin upload translations
popd
pushd ../ios/translation
crowdin upload sources
crowdin upload translations
popd
}
function download_from_crowdin {
ensure_crowdin_api_key
log_header "Downloading translations from crowdin"
pushd ../desktop/packages/mullvad-vpn
crowdin download
popd
pushd ../ios/translation
crowdin download
popd
# Add new translations to Android xml-files
log_header "Updating Android xml-files with new translations"
sync_localizations
# Add new translations to iOS source code
update_ios_strings import
commit_changes "Update translations"
}
function verify {
sync_localizations
git diff
# shellcheck disable=SC2251
! git status -s | grep .
local out_of_sync=$?
pushd ../desktop/packages/mullvad-vpn
npm exec ts-node scripts/verify-translations-format.ts
local incorrect_format=$?
popd
if [ "$out_of_sync" -ne 0 ] || [ "$incorrect_format" -ne 0 ]; then
exit 1
fi
}
function update_ios_strings {
if [ $# -ne 1 ] || { [ "$1" != "export" ] && [ "$1" != "import" ]; }; then
echo "Usage: update_ios_strings [export|import]" >&2
return 2
fi
if [ "$1" = "export" ]; then
log_header "Extracting strings from iOS app source code"
else
log_header "Updating strings into iOS app source code with new translations"
fi
}
main "$@"
|