summaryrefslogtreecommitdiffhomepage
path: root/scripts/ios-localization
blob: 6e83395d4a69d7f142e015c25422dfe1115e953a (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
#!/usr/bin/env bash

set -eu

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
iOS_LOCALIZATION_DIR="$(cd "$SCRIPT_DIR/../ios/translation" && pwd)"
cd "$SCRIPT_DIR"

# shellcheck disable=SC1091
source utils/log

# shellcheck disable=SC1091
source utils/localization_utils

function main {
  case ${1:-""} in
    upload) upload_to_crowdin ;;
    download) download_from_crowdin ;;
    "")
      echo "Available subcommands: upload and download"
      ;;
    *)
      echo "Unknown parameter: $1"
      exit 1
      ;;
  esac
}

function update_relay_locations {
  log_header "Retrieving relay locations from server list and updating RelayLocationList.Swift"
  pushd "$iOS_LOCALIZATION_DIR"
  ./scripts/fetch-relay-locations.sh
  ./scripts/relays-localization.sh
  popd
}

function prepare_localization_strings {
  update_relay_locations
  update_ios_strings export
  commit_changes "Export iOS strings"
}

function upload_to_crowdin {
  ensure_crowdin_api_key
  prepare_localization_strings
  log_header "Uploading iOS translations to Crowdin"
  pushd "$iOS_LOCALIZATION_DIR"
  crowdin upload sources
  crowdin upload translations
  popd
}

function download_from_crowdin {
  ensure_crowdin_api_key
  log_header "Downloading iOS translations from Crowdin"
  pushd "$iOS_LOCALIZATION_DIR"
  crowdin download translations
  popd
  update_ios_strings import
  commit_changes "Import iOS translations"
}

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 source code"
  else
    log_header "Updating strings into iOS source code with new translations"
  fi
  pushd "$iOS_LOCALIZATION_DIR"
  ./scripts/localizations.sh "$1"
  popd
}

main "$@"