|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +set -e |
| 4 | + |
| 5 | + |
| 6 | +usage() { |
| 7 | + cat <<EOM |
| 8 | +usage: $0 [-P|-h] <branch> <locales_dir> |
| 9 | +
|
| 10 | +Update existing PO files in <locales_dir> based |
| 11 | +on the current state of Python documentation |
| 12 | +version <branch>. |
| 13 | +
|
| 14 | +<locales_dir> is expected to have language directories |
| 15 | +in the structure <lang>/LC_MESSAGES/subdirs_and_files.po |
| 16 | +
|
| 17 | +Options: |
| 18 | + -t Skip POT files regenaration. This assumes locales_dir |
| 19 | + is already have updated POT files and will go ahead |
| 20 | + updating the PO files. |
| 21 | + -p Skip PO files update with POT file. Useful when you |
| 22 | + what the POT files but without changing PO files. |
| 23 | +
|
| 24 | +Example: |
| 25 | + $(basename $0) 3.14 . |
| 26 | + $(basename $0) 3.14 ../transifex-automations |
| 27 | + $(basename $0) -t 3.14 ../transifex-automations |
| 28 | + $(basename $0) -p 3.14 ../transifex-automations |
| 29 | +EOM |
| 30 | +} |
| 31 | + |
| 32 | + |
| 33 | +SKIP_POT_UPDATE=0 |
| 34 | +SKIP_TRANSLATIONS_UPDATE=0 |
| 35 | +while getopts "tph" o; do |
| 36 | + case "${o}" in |
| 37 | + t) |
| 38 | + SKIP_POT_UPDATE=1 |
| 39 | + ;; |
| 40 | + p) |
| 41 | + SKIP_TRANSLATIONS_UPDATE=1 |
| 42 | + ;; |
| 43 | + h) |
| 44 | + usage |
| 45 | + exit 0 |
| 46 | + ;; |
| 47 | + *) |
| 48 | + usage |
| 49 | + exit 1 |
| 50 | + ;; |
| 51 | + esac |
| 52 | +done |
| 53 | +shift $((OPTIND-1)) |
| 54 | + |
| 55 | + |
| 56 | +branch=$1 |
| 57 | +locales_dir=$2 |
| 58 | + |
| 59 | +if [ -z "$branch" ] || [ -z "$locales_dir" ]; then |
| 60 | + echo "Error: Both branch and locales_dir are required" |
| 61 | + usage |
| 62 | + exit 1 |
| 63 | +fi |
| 64 | + |
| 65 | +locales_dir=$(realpath $locales_dir) |
| 66 | + |
| 67 | +echo "Using branch: $branch" |
| 68 | +echo "Using locale directory: $locales_dir" |
| 69 | +cd "$locales_dir" |
| 70 | + |
| 71 | +if [ $SKIP_POT_UPDATE -eq 0 ]; then |
| 72 | + cpython_dir=../cpython |
| 73 | + rm -rf $cpython_dir |
| 74 | + git clone --depth 1 --branch "$branch" https://github.com/python/cpython "$cpython_dir" |
| 75 | + |
| 76 | + echo "Generating pot files" |
| 77 | + cd "$cpython_dir/Doc" |
| 78 | + ln -sr "$locales_dir" locales |
| 79 | + make clean venv |
| 80 | + opts='-E -b gettext -D gettext_compact=0 -d build/doctrees-gettext . build/gettext' |
| 81 | + make build ALLSPHINXOPTS="$opts" |
| 82 | + |
| 83 | + echo "Moving pot files into locales directory" |
| 84 | + rm -rf locales/pot/* |
| 85 | + (cd build/gettext; cp -a ./* ../../locales/pot/) |
| 86 | + |
| 87 | + cd locales |
| 88 | +fi |
| 89 | + |
| 90 | +if [ $SKIP_TRANSLATIONS_UPDATE -eq 0 ]; then |
| 91 | + langs=$(ls -1 | grep -Ev '(pot|venv|.tx)') |
| 92 | + pot_files=$(find pot/ -name '*.pot' | sort) |
| 93 | + |
| 94 | + echo "Updating existing PO files using the new POT files" |
| 95 | + |
| 96 | + for pot in $pot_files; do |
| 97 | + po=$(echo "$pot" | sed 's|^pot/||;s|\.pot|.po|') |
| 98 | + for lang in $langs; do |
| 99 | + if [ -f "$lang/LC_MESSAGES/$po" ]; then |
| 100 | + msgmerge -U -N --backup=off "$lang/LC_MESSAGES/$po" "$pot" |
| 101 | + fi |
| 102 | + done |
| 103 | + done |
| 104 | + powrap $(find . -name '*.po' | sort) |
| 105 | +fi |
0 commit comments