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

Refactor translation functions #1

Open
fastfinge opened this issue Mar 11, 2024 · 2 comments
Open

Refactor translation functions #1

fastfinge opened this issue Mar 11, 2024 · 2 comments

Comments

@fastfinge
Copy link
Owner

In order to make it possible to add multiple translation services, a code refactor is needed. We need to create a class to wrap the various API's, expose a universal translate method, and a standard set of config getters and setters. Once that's done, we can add google, yandex, and Libre translate.

@yplassiard
Copy link

Hi,
Congratulations and many thanks for this work on Deepl. I totally aggree with your point and once done, I'll be very happy if you aggree to it too, to merge it into the "official" NVDA translate add-on, giving the user the ability to choose which engine to use.
Thanks again!

@fastfinge
Copy link
Owner Author

Thanks for your kind words! I'd be happy for you to merge once done.

However, I'm a self-taught programmer, and I've never done any work on NVDA addons before. I'm also more comfortable in C#, and this is my first real work in Python. So it might take me longer than expected to do this refactor. That's why the code is a mess right now. :-) I needed something that worked, because Google blocked me from the translate service for making too many calls.

My current plan is:

  1. Make a "translator" class that exports the following public properties: APIKey (string), ServerURL (string), SupportedLanguages (dict of ISO language codes and names), and a translate function
  2. Make classes for Google, LibreTranslate, and DeepL that inherit from the translator class, set appropriate default properties, and overload the translate function. Note: I plan to use the googletranse API for google translate (https://pypi.org/project/googletrans/), because it supports HTTP2, meaning we can reuse connections and it should be faster.
  3. Detect if source and target languages are supported when translating text, and give appropriate errors if not.

Questions I'm not sure about:

  1. I don't understand config.conf and confspecs at all, and I can't find documentation. If someone picks a different translation service (switching from google to DeepL for example), how do I correctly update the values in the GUI?
  2. What do I do for properties that are not required? Google does not require an API key, but DeepL and LibreTranslate both do. How do I handle this, both in confspec and the GUI?
  3. How do we handle unsupported languages? For example, DeepL does not support Tagalog, but Google does. How can we let the user configure to fall back to a different translation service if the default one doesn't support the source or target language?
  4. How do I make language names translatable? Right now I just display the language code in the combo box, because I just couldn't figure this out.

If you have any advice or feedback, I would appreciate it!

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

No branches or pull requests

2 participants