Skip to content

Commit

Permalink
Improve translations for Arabic text
Browse files Browse the repository at this point in the history
  • Loading branch information
ashishb committed Apr 7, 2023
1 parent a1416c3 commit f47f89a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/translations.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ def _get_target_languages(res_dir: str) -> typing.Dict[str, str]:
def _normalize_response(text: str) -> str:
text = text.replace("$、d", "$d")
text = text.replace("$、s", "$s")
# Replace Chinese % sign with standard English one or "%d" and "%s" won't work
text = text.replace("%", "%")
# Replace Arabic % sign with standard English one or "%d" and "%s" won't work
text = text.replace("٪", "%")
# Fix responses like \ "%1 $ S \" -> \"%1$s\"
pattern = r'%\s*([\d*])\s*\$(,?)\s*([sdfSDF])'
text = re.sub(pattern, r'%\1$\2\3', text)
Expand Down Expand Up @@ -75,8 +79,6 @@ def _normalize_response(text: str) -> str:
text = text.replace("$,S", "$,s")
text = text.replace("$,D", "$,d")
text = text.replace("f/ %", "f/%")
# Replace Chinese % sign with standard English one or "%d" and "%s" won't work
text = text.replace("%", "%")
text = text.replace("...", "…")
text = text.replace(" …", "…")
text = text.replace("“", "\"")
Expand Down
2 changes: 2 additions & 0 deletions tests/test_translations.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ def test_normalize_responses():

# percentage sign that shows up in Chinese translations
assert translations._normalize_response("%") == "%"
# percentage sign from Arabic translations
assert translations._normalize_response("٪") == "%"
assert translations._normalize_response("...") == "…"
assert translations._normalize_response("“") == "\""
assert translations._normalize_response("”") == "\""
Expand Down

0 comments on commit f47f89a

Please sign in to comment.