File: poedit.sh

package info (click to toggle)
pympress 1.5.3%2Bdfsg-1
  • links: PTS
  • area: main
  • in suites: bullseye
  • size: 876 kB
  • sloc: python: 3,526; sh: 84; makefile: 17
file content (76 lines) | stat: -rwxr-xr-x 2,428 bytes parent folder | download
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
#!/usr/bin/env bash

cd `git rev-parse --show-toplevel || readlink -f "$0" | xargs dirname | xargs dirname`
pot=pympress/share/locale/pympress.pot

upload() {
    printf 'Uploading new strings to poeditor: '
    curl -sX POST https://api.poeditor.com/v2/projects/upload \
          -F api_token="$poeditor_api_token" \
          -F id="301055" -F updating="terms" -F file=@"$pot" \
          | jq -r '.response.message'
}

languages() {
    curl -sX POST https://api.poeditor.com/v2/languages/list \
          -F api_token="$poeditor_api_token" \
          -F id="301055" | jq -r 'select(.response.code == "200") | .result.languages[].code'
}

contributors() {
    curl -sX POST https://api.poeditor.com/v2/contributors/list \
          -F api_token="$poeditor_api_token" \
          -F id="301055" | jq -r 'select(.response.code == "200") | .result.contributors[].name' |
        while read name; do
            # hold "name,", hold & delete any line matching name, at the last translator insert the hold space
            sed -e "1{h;s/.*/${name},/;x}" -e "/\<${name}\>/{h;d}" -e '/<!-- last translator -->/{x;G}' -i README.md
        done
}

download() {
    lang=$1
    printf "Updating %s:\n" "$lang"

    url=`curl -sX POST https://api.poeditor.com/v2/projects/export \
          -F api_token="$poeditor_api_token" \
          -F id="301055" -F language="$lang" -F type="po" \
        | jq -r 'select(.response.code == "200") | .result.url'`

    test -n "$url" && curl -so "pympress/share/locale/${lang}/LC_MESSAGES/pympress.po" "$url"
}

getpass() {
    if test -z "$poeditor_api_token"; then
        poeditor_api_token=`$SSH_ASKPASS "Password for 'https://api.poeditor.com/projects/v2/': "`
    fi
}


if [ $# -eq 0 ]; then
    echo "Usage: $0 <command>"
    echo "Where command is one of: upload, languages, download, progress, contributors"
    echo "requires curl and jq"
fi

while [ $# -gt 0 ]; do
    if test "$1" = "upload"; then
        getpass
        upload
    elif test "$1" = "languages"; then
        getpass
        languages
    elif test "$1" = "download"; then
        getpass
        for lang in `languages`; do
            download $lang
        done
        contributors
    elif test "$1" = "contributors"; then
        getpass
        contributors
    else
        echo "Unrecognised command $1 use one of: upload, languages, download, progress, contributors"
        exit 1
    fi
    shift
done