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

WIP: Add the ability to translate submissions #4134

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

wes-otf
Copy link
Contributor

@wes-otf wes-otf commented Sep 13, 2024

Pertaining to discussions had in #4037. This integrates the argostranslate library to allow for translation of applications. The current functionality allows staff users to translate the written answers of an application.

This feature utilizes htmx to translate the application without requiring a reload of the page, while also updating the URL so a user can have a sharable link (using the query parameters fl [from language] & tl [to language]) when collaborating with others on the application.

This feature is disabled by default & can be enabled via the ALLOW_SUBMISSION_TRANSLATIONS setting

Demos

Translating an application

Screen.Recording.2024-09-13.at.14.33.16.mp4

Clearing a translation via the form

Screen.Recording.2024-09-13.at.14.52.45.mp4

Test Steps

@wes-otf wes-otf added Type: Feature This is something new (not an enhancement of an existing thing). Type: Minor Minor change, used in release drafter labels Sep 13, 2024
@wes-otf
Copy link
Contributor Author

wes-otf commented Sep 13, 2024

Lots of work needed before this is ready, like:

  • Better code documentation
  • Cleaning/organizing initial PoC code (ie. the JS form validation/choice population in translate_application_form.html)
  • Server side form validation for translate_application_form.html
  • Lots & lots of unit tests
  • Management command (or migration?) to install new language packages
  • Better feedback to the user via htmx triggers showMessage & message (ie. when a failure takes place)
  • Perfecting formatting on language form

So far happy with the initial pass though! OTF is on board already as this is something they really hate having to keep using an external AI type service for.

@wes-otf
Copy link
Contributor Author

wes-otf commented Sep 13, 2024

if anyone wants to play around with this, to install language packages you can use the following script (will install the Arabic -> English package but from_code & to_code can be changed to whatever)

import argostranslate.package
import argostranslate.translate

from_code = "ar"
to_code = "en"

# Download and install Argos Translate package
argostranslate.package.update_package_index()
available_packages = argostranslate.package.get_available_packages()
package_to_install = next(
    filter(
        lambda x: x.from_code == from_code and x.to_code == to_code, available_packages
    )
)
argostranslate.package.install_from_path(package_to_install.download())

@frjo
Copy link
Contributor

frjo commented Sep 14, 2024

I think the UI looks really nice. Neat to make the to/from lang a query string so it can be shared.

How would downloading the language package work on production?

@wes-otf
Copy link
Contributor Author

wes-otf commented Sep 16, 2024

I was thinking via a management command that way the instance could add languages as needed. Still thinking through what that syntax would look like but maybe something like:

python3 manage.py install_language from_to ...

ie. to install the arabic -> english & french -> english package it'd look like:

python3 manage.py install_language ar_en fr_en

@wes-otf
Copy link
Contributor Author

wes-otf commented Sep 18, 2024

The previously mentioned management commands were added - had a long layover today so went a little overboard w/ verbosities and messages (ie. packages{'s were' if len(existing_packages) > 1 else ' was'}) bull overall seems to work pretty well!

Installing English -> Arabic & English -> Spanish:

python3 manage.py install_languages ar_en fr_en

Uninstalling said languages:

python3 manage.py uninstall_languages ar_en fr_en

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Feature This is something new (not an enhancement of an existing thing). Type: Minor Minor change, used in release drafter
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants