File: translators.sh

package info (click to toggle)
bazaar 0.7.8-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,396 kB
  • sloc: ansic: 49,466; sh: 685; xml: 327; python: 87; makefile: 6
file content (108 lines) | stat: -rwxr-xr-x 3,861 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
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
#!/usr/bin/env bash
# Helper script that automates the preparation steps to translate Bazaar.
#
# The script will add the passed language code to the LINGUAS file to avoid
# editing it manually.
# also:
# It will reorder the contents of the file alphabetically;
# It will check if the code is already in the file;
# It will show the contents of the LINGUAS file, allowing a visual check;
# It won't really check if the locale code is valid but will inform you
# that it is not in the list of codes inside /usr/share/locale;
# It will generate a .backup inside /tmp before proceeding and a .tmp file
# before overwriting LINGUAS.
#
translators_helper() {

    local lang_input
    local lang_f
    local po_d
    local build_d
    local system_langs
    local langs_in_file
    local temp_file

    lang_f="LINGUAS"
    po_d="po"
    build_d="build"
    mapfile -t system_langs < <(find /usr/share/locale/ -maxdepth 1 -type d -printf "%f\n")
    temp_file="$(mktemp --suffix=BAZAAR)"
    printf "Temporary file: %s\n" "${temp_file}"

    printf "Setting im_a_translator to true\n"
    meson setup build -Dim_a_translator=true || return 1

    pushd "${po_d}" >/dev/null || return 1

    langs_in_file="$(wc --lines "${lang_f}" | grep --only-matching --extended-regex "[0-9]{1,}")"
    printf "\nNumber of languages currently in file %s\n" "${langs_in_file}"
    unset langs_in_file

    printf "Language codes currently in %s file.\n" "${lang_f}"
    cat --squeeze-blank "${lang_f}"
    read -r -n 1 -p "Proceed? (Type y or Y to confirm)" YN
    case "$YN" in
    [Yy])
        printf "\n%s\n" "Proceeding..."
        ;;
    *)
        printf "\n%s\n" "Leaving..."
        exit 3
        ;;
    esac

    printf "\nCopying %s to /tmp/%s\n" "${lang_f}" "${lang_f}.backup"
    cp --verbose "${lang_f}" "/tmp/${lang_f}.backup"

    read -r -p "Type the language code you want to enable translation for. ex.: pt_BR or es: " lang_input

    if [[ "${system_langs[*]}" =~ ${lang_input} ]]; then
        printf "Found %s in the system's language code list.\n" "${lang_input}"
        sleep 2s
    else
        printf "Could not find \"%s\" in the system's language code list, but proceeding nonetheless.\n" "${lang_input}"
        sleep 2s
    fi

    if grep --only-matching "${lang_input}" "${lang_f}"; then
        printf "%s already in file\n" "${lang_input}"
        sleep 2s
    else
        printf "Language to be added: %s\n" "${lang_input}"
        printf "%s\n" "${lang_input}" | tee -p --append "${lang_f}" 2>&1
        sleep 2s
    fi
    cat --squeeze-blank "${lang_f}" | (
        sed --unbuffered 1q
        sort
    ) | tee -p "${temp_file}"
    cat --squeeze-blank "${temp_file}" >"${lang_f}"

    langs_in_file="$(wc --lines "${lang_f}" | grep --only-matching --extended-regex "[0-9]{1,}")"
    printf "Number of languages currently in file %s\n" "${langs_in_file}"
    unset langs_in_file

    cat --squeeze-blank "${temp_file}"
    cat --squeeze-blank "${lang_f}"
    # $EDITOR LINGUAS
    popd || return 1

    pushd "${build_d}" || return 1

    printf "Generating the main pot (Portable Object Template) file for lang %s...\n" "${lang_input}"
    meson compile bazaar-pot

    printf "Update and/or create the po (Portable Object) files for %s.\n" "${lang_input}"
    meson compile bazaar-update-po

    echo "--------------------------------"
    printf "\nConfiguration done. Now ready for you to open your \"po\" file in your text editor and begin translating.\n"
    printf "When you are done, commit your changes form your fork and submit a pull request on \n%s also, refer to TRANSLATORS.md if needed\e]8;;\e\\ \n\n" "https://github.com/kolunmi/bazaar/blob/master/TRANSLATORS.md"
    echo "--------------------------------"

    popd || return 1

    return 0
}

translators_helper || echo 'An error occurred; review the above output' 2>&1