Skip to content

Commit

Permalink
Improve problematic source string removal (#98)
Browse files Browse the repository at this point in the history
* Rename remove-ilegal-strings.sh to remove-msgid.sh

* remove-msgid: make flexible, remove more msgids
  • Loading branch information
rffontenelle authored Nov 12, 2024
1 parent 502c1ca commit f882a29
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 48 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ jobs:
deleted_files=$(git status -s | grep ^' D' | cut -d' ' -f3)
if [ -n "$deleted_files" ]; then git rm -v $deleted_files; else echo "no POT files to remove"; fi
# See issue #15
- name: Patch POT files
- name: Remove problematic source messages from POT files
run: |
scripts/remove-ilegal-strings.sh cpython/Doc/locales/pot
scripts/remove-msgid.sh cpython/Doc/locales/pot
- name: Generate Transifex configuration file (.tx/config)
working-directory: cpython/Doc/locales
Expand Down
45 changes: 0 additions & 45 deletions scripts/remove-ilegal-strings.sh

This file was deleted.

54 changes: 54 additions & 0 deletions scripts/remove-msgid.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/bash
# Patch POT to solve issues with source messages

set -euo pipefail
IFS=$'\n\t'

# Check if a valid POT directory was passed in command-line interface.
# If no argument is passed, use current working directory .
if [ $# -lt 1 ]; then
if [[ "$(basename $PWD)" != "pot" ]]; then
echo "Error: Not in 'pot' directory and no path to pot directory passed."
exit 1
fi
else
if [ $# -gt 1 ]; then
echo "Ignoring extra arguments, sticking with '$1' ..."
fi
if [[ ! -d $1 || "$(basename $1)" != "pot" ]]; then
echo "'$1' is not a valid directory. Expected a directory named 'pot'."
fi

# Enter the given directory
cd $1
fi

# Create temporary files and set up exit trap
tmp=$(mktemp --suffix='.po')
tmp2=$(mktemp --suffix='.po')
trap 'rm -f $tmp $tmp2' EXIT


# Usage: remove_msgid </path/to/pot> <source message text>
remove_msgid() {
pot=$1
shift
msgid=$@
msggrep -Ke "$msgid" $pot > $tmp
msgcomm --no-wrap --less-than=2 $pot $tmp > $tmp2
mv $tmp2 $pot
echo "Stripping from '$pot': $msgid"
powrap -q $pot
}


# \\N is treated as new line in Transifex, so it is an illegal source string
# https://github.com/rffontenelle/python-docs-tx-translations/issues/15
remove_msgid library/codecs.pot '^\\N$'
remove_msgid library/re.pot '^\\N$'
remove_msgid reference/lexical_analysis.pot '^\\N$'

# This string should not be translated, otherwise sphinx-build give warnings
# Fixed via https://github.com/python/cpython/pull/19470
remove_msgid c-api/sys.pot '^Raises an :ref:`auditing event <auditing>` ``sys.addaudithook`` with no arguments.$'
remove_msgid library/sys.pot '^Raises an :ref:`auditing event <auditing>` ``sys.addaudithook`` with no arguments.$'

0 comments on commit f882a29

Please sign in to comment.