-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve problematic source string removal (#98)
* Rename remove-ilegal-strings.sh to remove-msgid.sh * remove-msgid: make flexible, remove more msgids
- Loading branch information
1 parent
502c1ca
commit f882a29
Showing
3 changed files
with
57 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.$' |