Skip to content

Fix mixed-direction text layout in translations (Resolves #34)#37

Open
Salah-Sal wants to merge 1 commit into
andrewyng:mainfrom
Salah-Sal:adding-RTL-support
Open

Fix mixed-direction text layout in translations (Resolves #34)#37
Salah-Sal wants to merge 1 commit into
andrewyng:mainfrom
Salah-Sal:adding-RTL-support

Conversation

@Salah-Sal

Copy link
Copy Markdown

Context

What is the purpose of this PR? Is it to

  • add a new feature
  • fix a bug
  • update tests and/or documentation
  • other (please add here)

Please link to any issues this PR addresses.
Fixes #34

Changelog

  • Removed a redundant line in utils.py where source_text was being replaced unnecessarily.
  • Added the tokenize_mixed_direction_text function in process.py to handle mixed-direction text (LTR within RTL).
  • Updated the translator and translator_sec functions in process.py to use tokenize_mixed_direction_text for processing the translations.

Test plan

Please make sure to do each of the following if applicable to your PR. (If you're not sure about any one of these just ask and we will happily help.)

  • run pre-commit hooks and linters (make sure you've first installed via pre-commit install)
  • add unit tests for any new functionality
  • update docstrings for any new or updated methods or classes
  • run unit tests via pytest tests
  • include relevant commands and any other artifacts in this summary (eval results, etc.)

* remove redundant line

the line removed was redundant - the `source_text` gets already replaced through the f"-string

* Update utils.py
@Salah-Sal Salah-Sal changed the title remove redundant line (#8) Fix mixed-direction text layout in translations (Resolves #34) (#8) Jul 12, 2024
@Salah-Sal Salah-Sal changed the title Fix mixed-direction text layout in translations (Resolves #34) (#8) Fix mixed-direction text layout in translations (Resolves #34) Jul 12, 2024

@abodacs abodacs left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Salah-Sal
Thanks for your contribution.
I added some comments

Comment thread app/process.py
words_and_delimiters = re.findall(r"\w+|[^\w\s]+|\s+", text)

new_text = []
ltr_pattern = re.compile(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Salah-Sal
Thanks for your contribution.
can we modify the ltr_pattern to include numerical digits?

ltr_pattern = re.compile("[A-Za-z0-9]+")

Comment thread app/process.py
is_rtl = language in rtl_languages

# Regex to capture words, non-word characters, and any whitespace
words_and_delimiters = re.findall(r"\w+|[^\w\s]+|\s+", text)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we pre-compile the regular expression outside for better performance?

tokenizer_pattern = re.compile(r"\w+|[^\w\s]+|\s+")
# ... Inside the function:
words_and_delimiters = tokenizer_pattern.findall(text)

Comment thread app/process.py
"Urdu",
}
is_rtl = language in rtl_languages

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest adding an appropriate normalization form, but it may lead to the removal of unimportant text, so you can neglect it.

# . , before tokenizaText:
text = unicodedata.normalize("NFC", text)  

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LTR to RTL Translation Layout Misalignment in Web UI

3 participants