Skip to content

Commit

Permalink
Replace naked apostrophe with escaped apostrophe
Browse files Browse the repository at this point in the history
  • Loading branch information
ashishb committed Apr 2, 2023
1 parent 42d0aa3 commit 0d70c84
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/translations.py
Expand Up @@ -57,6 +57,8 @@ def _normalize_response(text: str) -> str:
# than necessary
text = re.sub(r'\"\s*(.*?)\s*\"', r'"\1"', text)
text = re.sub(r'\(\s*(.*?)\s*\)', r'(\1)', text)
# Replace unescaped quotes
text = re.sub(r"([^\\])'", r"\1\'", text)

text = text.replace('" ', '"')
# text = text.replace(" \"", "\"")
Expand Down
2 changes: 2 additions & 0 deletions tests/test_translations.py
Expand Up @@ -45,3 +45,5 @@ def test_normalize_responses():
assert translations._normalize_response("...") == "…"
assert translations._normalize_response("“") == "\""
assert translations._normalize_response("”") == "\""

assert translations._normalize_response("l'artiste") == r"l\'artiste"

0 comments on commit 0d70c84

Please sign in to comment.