-
-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathpull_translations.sh
executable file
·49 lines (43 loc) · 1.59 KB
/
pull_translations.sh
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
#!/bin/sh
# Pull translations files from Transifex for the given language code
#
# SPDX-License-Identifier: CC0-1.0
#
# Usage examples:
#
# Pull all translations for the given language.
#
# ./scripts/pull_translations.sh
#
# Pull translations for "library/os.po" and "faq/library.po"
# for the Transifex project set in PYDOC_TX_PROJECT. For instance,
# for PYDOC_TX_PROJECT=python-newest, that means pulling the resources
# "python-newest.library--os" and "python-newest.faq--library".
#
# ./scripts/pull_translations.sh library/os.po faq/library.po
#
set -xeu
test -n ${PYDOC_TX_PROJECT+x}
cd "$(dirname $0)/../cpython/Doc/locales/${PYDOC_LANGUAGE}/LC_MESSAGES/"
# If a PO file is provided as input, convert it into Transifex resource
# and add it be pulled (instead of pulling all translations files).
resources_to_pull=""
if [ $# -gt 0 ]; then
resources_to_pull="-r"
for po_input in $@; do
# trim possible filepath part not used for Transifex resources
po=$(echo $po_input | sed 's|.*LC_MESSAGES/||')
# fail if PO file doesn't exist
[ ! -f "$po" ] && (echo "'$po_input' not found."; exit 1;)
# convert po filename into transifex resource
tx_res=$(echo $po | sed 's|\.po||;s|/|--|g;s|\.|_|g')
# append to a list of resources to be pulled
resources_to_pull="$resources_to_pull ${PYDOC_TX_PROJECT}.${tx_res}"
done
fi
tx pull -f -l "${PYDOC_LANGUAGE}" ${resources_to_pull}
# Drop translation of Python's changelog in python 3.12 or older.
minor_version=$(git branch --show-current | sed 's|^3\.||')
if [ $minor_version -le 12 ]; then
git checkout whatsnew/changelog.po
fi