Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add tui interactive interface to work with llm translation #1007

Draft
wants to merge 1 commit into
base: 3.13
Choose a base branch
from

Conversation

josix
Copy link
Collaborator

@josix josix commented Dec 16, 2024

This pull request introduces a new interactive translation application using the textual framework and integrates Google Generative AI for translation tasks. It also includes updates to the dependencies in the pyproject.toml file.

New interactive translation application:

  • .scripts/interactive_translate/main.py: Added a new TranslationApp class using the textual framework to provide an interactive UI for translating PO files. The application supports navigation through entries, accepting translations, generating translations using Google Generative AI, and saving changes.

Dependency updates:

  • .scripts/pyproject.toml: Added new dependencies textual, powrap, and google-generativeai to support the new translation application.

image

Comment on lines +215 to +224
def main(po_file_path: str):
app = TranslationApp(Path(po_file_path))
app.run()

if __name__ == "__main__":
import sys
if len(sys.argv) > 1:
main(sys.argv[1])
else:
print("Please provide a PO file path")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
def main(po_file_path: str):
app = TranslationApp(Path(po_file_path))
app.run()
if __name__ == "__main__":
import sys
if len(sys.argv) > 1:
main(sys.argv[1])
else:
print("Please provide a PO file path")
def main(po_file_path: str):
app = TranslationApp(po_file_path)
app.run()
if __name__ == "__main__":
import argparse
desc = 'TUI for LLM translations'
parser = argparse.ArgumentParser(description=desc)
parser.add_argument('po_file_path', type=Path,
help='Path to the PO file to translate')
args = parser.parse_args()
main(args.po_file_path)

What about using argparse instead of sys.argv?

Comment on lines +199 to +205
prompt = ("Translate the following Python documentation into Traditional Chinese"
f"for {self.po_file_path}:{entry.occurrences} with message {entry.msgid[1]}. Ensure "
"that the translation is accurate and uses appropriate technical terminology. The"
" output must be in Traditional Chinese. Pay careful attention to context, idiomatic"
" expressions, and any specialized vocabulary related to Python programming. Maintain "
"the structure and format of the original documentation as much as possible to ensure"
" clarity and usability for readers.")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
prompt = ("Translate the following Python documentation into Traditional Chinese"
f"for {self.po_file_path}:{entry.occurrences} with message {entry.msgid[1]}. Ensure "
"that the translation is accurate and uses appropriate technical terminology. The"
" output must be in Traditional Chinese. Pay careful attention to context, idiomatic"
" expressions, and any specialized vocabulary related to Python programming. Maintain "
"the structure and format of the original documentation as much as possible to ensure"
" clarity and usability for readers.")
prompt = ("Translate the following Python documentation into Traditional Chinese "
f"for {self.po_file_path}:{entry.occurrences} with message {entry.msgid[1]}. Ensure "
"that the translation is accurate and uses appropriate technical terminology. The "
"output must be in Traditional Chinese. Pay careful attention to context, idiomatic "
"expressions, and any specialized vocabulary related to Python programming. Maintain "
"the structure and format of the original documentation as much as possible to ensure "
"clarity and usability for readers.")

There's a missing space at the end of the first line that causes Chinesefor to be merged together. While I was at it I made the spacing of the other lines consistent, by moving all the spaces at the end of the sentences.

else:
self.notify("Failed to generate translation", severity="error")
except Exception as e:
self.notify(f"Error: {str(e)}", severity="error")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
self.notify(f"Error: {str(e)}", severity="error")
self.notify(f"Error: {e}", severity="error")

The str() is not necessary here.

Comment on lines +142 to +148
prompt = ("Translate the following Python documentation into Traditional Chinese"
f"for {self.po_file_path}:{entry.occurrences} with message {entry.msgid}. Ensure "
"that the translation is accurate and uses appropriate technical terminology. The"
" output must be in Traditional Chinese. Pay careful attention to context, idiomatic"
" expressions, and any specialized vocabulary related to Python programming. Maintain "
"the structure and format of the original documentation as much as possible to ensure"
" clarity and usability for readers.")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
prompt = ("Translate the following Python documentation into Traditional Chinese"
f"for {self.po_file_path}:{entry.occurrences} with message {entry.msgid}. Ensure "
"that the translation is accurate and uses appropriate technical terminology. The"
" output must be in Traditional Chinese. Pay careful attention to context, idiomatic"
" expressions, and any specialized vocabulary related to Python programming. Maintain "
"the structure and format of the original documentation as much as possible to ensure"
" clarity and usability for readers.")
prompt = ("Translate the following Python documentation into Traditional Chinese "
f"for {self.po_file_path}:{entry.occurrences} with message {entry.msgid}. Ensure "
"that the translation is accurate and uses appropriate technical terminology. The "
"output must be in Traditional Chinese. Pay careful attention to context, idiomatic "
"expressions, and any specialized vocabulary related to Python programming. Maintain "
"the structure and format of the original documentation as much as possible to ensure "
"clarity and usability for readers.")

This has the same bug (Chinesefor) as the other prompt. Since it looks duplicated, it might be better to factor it out, and reusing it in both places instead.

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.

2 participants