Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/hypha-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ jobs:
DATABASE_URL: postgres://hypha:hypha@localhost/hypha?sslmode=disable
DJANGO_SETTINGS_MODULE: hypha.settings.test
SEND_MESSAGES: false
APPLICATION_TRANSLATIONS_ENABLED: 1 # Run tests for machine translation logic

services:
postgres:
Expand Down Expand Up @@ -126,7 +125,7 @@ jobs:
- name: Install python dependencies
run: |
uv venv
uv sync --frozen --group translate
uv sync --frozen

- name: Create static_compiled dir
run: mkdir hypha/static_compiled
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,6 @@ GitHub.sublime-settings
# Keys and certs
*.key
*.crt

# Plugin checkouts, e.g. https://github.com/HyphaApp/hypha-plugins
/plugins/
11 changes: 0 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,6 @@ repos:
args:
["--frozen", "--only-group", "docs", "-o", "requirements/docs.txt"]

- id: uv-export
name: uv-export requirements/translate.txt
args:
[
"--frozen",
"--only-group",
"translate",
"-o",
"requirements/translate.txt",
]

- repo: https://github.com/asottile/pyupgrade
rev: v3.22.0
hooks:
Expand Down
29 changes: 29 additions & 0 deletions docs/references/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ You can set the `DJP_PLUGINS_DIR` environment variable to point to a directory w

Since DJP allow a plugin to override any setting you can tell Hypha to look for templates in a directory inside your plugin. This allows the plugin to override any template in Hypha.

## Template hook points

Plugins can add content to these places in Hypha's templates by registering a callback with `hypha.core.templatehook.hook`, see [TemplateHook](template-hooks.md). The callback gets the template context, e.g. `context["request"]` and `context["object"]`.

| Hook | Where | Context |
|------|-------|---------|
| `user_account_profile` | The profile column of the account page | `request` |
| `submission_admin_actions` | The staff actions in the submission sidebar | `request`, `object` (the submission) |
| `submission_answers_before` | Before the submission answers, which are in the `#rendered-answers` element | `request`, `object` (the submission) |

See `hypha_translate` in [hypha-plugins](https://github.com/HyphaApp/hypha-plugins) for a plugin using these hooks, djp entry points and its own urls, templates and management commands.

## URL ordering

URLs contributed through the DJP `urlpatterns()` hook are added to the root urlconf **after** Hypha's own routes but **before** Wagtail's page-serving catch-all (`path("", include(wagtail_urls))`). This means:
Expand All @@ -17,3 +29,20 @@ URLs contributed through the DJP `urlpatterns()` hook are added to the root urlc
- A plugin URL takes precedence over a Wagtail page at the same path.

Prefer the `urlpatterns()` hook for adding routes. Only manipulate the root urlconf directly (e.g. from `AppConfig.ready()`) if you need finer control than the hook provides.

## Developing a plugin

Hypha is not an installable package, so plugins are developed and tested inside a Hypha checkout. The `plugins/` directory is git ignored by Hypha and meant for plugin checkouts, e.g. the [hypha-plugins](https://github.com/HyphaApp/hypha-plugins) repo:

```bash
git clone git@github.com:HyphaApp/hypha-plugins.git plugins/hypha-plugins
uv pip install -e plugins/hypha-plugins/hypha_translate
```

Run a plugin's tests from the Hypha root, so Hypha's pytest settings and `conftest.py` are used:

```bash
uv run pytest plugins/hypha-plugins/hypha_translate
```

`uv sync` removes packages that are not in Hypha's lock file, including plugins installed with `uv pip install`. Install them again after it, or use `uv sync --inexact`. `uv run` does not remove them.
8 changes: 0 additions & 8 deletions docs/setup/administrators/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -319,14 +319,6 @@ On Heroku, set to true if deploying to Heroku.

----

Machine translation settings for applications

See [here](machine-translations.md) for more information on setting up machine translations

APPLICATION_TRANSLATIONS_ENABLED = env.bool("APPLICATION_TRANSLATIONS_ENABLED", False)

----

Should submission anonymization be enabled. Allows for both manual anonymization and utilization of cleanup commands to anonymize by time thresholds.

SUBMISSION_ANONYMIZATION_ENABLED = env.bool("SUBMISSION_ANONYMIZATION_ENABLED", False)
Expand Down
62 changes: 7 additions & 55 deletions docs/setup/administrators/machine-translations.md
Original file line number Diff line number Diff line change
@@ -1,64 +1,16 @@
# Machine translations

Hypha has the ability to utilize [argostranslate](https://github.com/argosopentech/argos-translate) for machine translations of submitted application content. This is disabled by default and the dependencies are not installed to prevent unneeded bloat due to [PyTorch](https://pytorch.org/)'s large language models.
Machine translation of submissions is available as the `hypha_translate` plugin in [hypha-plugins](https://github.com/HyphaApp/hypha-plugins), using [Argos Translate](https://github.com/argosopentech/argos-translate). Translations run locally on the server, no application content is sent to a third party.

Install it into Hypha's Python environment, e.g. by adding this to your deployment's requirements file:

## Installing dependencies

As referenced in the [production deployment guide](../deployment/production/stand-alone.md), it is required to install the dependencies needed for machine translation dependencies via

```bash
python3 -m pip install -r requirements/translate.txt
```

or, if you are on a platform that does not support GPU processing:

```bash
python3 -m pip install -r requirements/translate-cpu.txt
--extra-index-url https://download.pytorch.org/whl/cpu
hypha-translate @ git+https://github.com/HyphaApp/hypha-plugins@hypha_translate-v1.0.0#subdirectory=hypha_translate
```

The PyTorch CPU index avoids installing the several GB larger CUDA build of PyTorch, which is not needed.

This requirements file will specifically attempt to install the CPU version of [PyTorch](https://pytorch.org/) if available on the detected platform to play better with heroku (doesn't support GPU processing) and to minimize package bloat (CPU package is ~300MB less than the normal GPU). Depending on your use case, you may want to adjust this.


## Installing languages

Argostranslate handles translations via its own packages—e.g., Arabic → English translation is one package, while English → Arabic is another.

You can install/uninstall these packages using the management commands `install_languages` and `uninstall_languages`, respectively. The format for specifying a package is `<from language code>_<to language code>`. For example, to install the Arabic → English and French → English packages:

```bash
python3 manage.py install_languages ar_en fr_en
```

### Additional options

The `install_languages` command supports several options for flexibility:

- **Install all available packages:**
```bash
python3 manage.py install_languages --all
```
> ⚠️ This may install many packages and consume significant disk space.

- **Interactively select packages:**
```bash
python3 manage.py install_languages --select
```
This will present a numbered list of available language packages for you to choose from.

- **Skip confirmation prompts:**
```bash
python3 manage.py install_languages ar_en --noinput
```
This will install the specified packages without asking for confirmation.

You can combine these options as needed. For example, to interactively select packages and skip confirmation:

```bash
python3 manage.py install_languages --select --noinput
```

## Enabling on the system
See the [hypha_translate README](https://github.com/HyphaApp/hypha-plugins/blob/main/hypha_translate/README.md) for installing with uv, installing language packages and more.

To enable machine translations on an instance, the proper configuration variables need to be set. These can be found in the [configuration options](configuration.md#hypha-custom-settings)
Earlier versions of Hypha had this feature built in, enabled with the `APPLICATION_TRANSLATIONS_ENABLED` setting. That setting is no longer used, the feature is enabled when the plugin is installed.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends "funds/applicationsubmission_detail.html" %}
{% load i18n static workflow_tags review_tags determination_tags translate_tags heroicons %}
{% load i18n static workflow_tags review_tags determination_tags heroicons %}

{% block sidebar_top %}
<section
Expand Down Expand Up @@ -116,7 +116,4 @@ <h2 class="card-title">{% trans "Reminders" %}</h2>
{% block extra_js %}
{{ block.super }}
<script src="{% static 'js/behaviours/collapse.js' %}"></script>
{% if request.user|can_translate_submission %}
<script src="{% static 'js/translate-application.js' %}"></script>
{% endif %}
{% endblock %}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends "base-apply.html" %}
{% load i18n static workflow_tags wagtailcore_tags statusbar_tags archive_tags submission_tags translate_tags primaryactions_tags project_tags %}
{% load i18n static workflow_tags wagtailcore_tags statusbar_tags archive_tags submission_tags primaryactions_tags hooks_tags project_tags %}
{% load heroicons %}
{% load can from permission_tags %}

Expand Down Expand Up @@ -123,21 +123,11 @@ <h5>
</div>
</header>

{% if request.user|can_translate_submission %}
<div
class="mt-4 w-full"
hx-get="{% url 'funds:submissions:partial-translate-answers' object.id %}"
hx-trigger="translateSubmission from:body"
hx-indicator="#translate-card-loading"
hx-vals='js:{fl: event.detail.from_lang, tl: event.detail.to_lang}'
>
{% include "funds/includes/rendered_answers.html" %}
</div>
{% else %}
<div class="w-full">
{% include "funds/includes/rendered_answers.html" %}
</div>
{% endif %}
{# Extension point for plugins to add content before the answers, which are in #rendered-answers. #}
{% hook "submission_answers_before" %}
<div id="rendered-answers" class="mt-4 w-full">
{% include "funds/includes/rendered_answers.html" %}
</div>

</article>
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% load i18n %}
{% load heroicons primaryactions_tags translate_tags %}
{% load heroicons hooks_tags primaryactions_tags %}
{% load can from permission_tags %}

<h2 class="mb-2 card-title">{% trans "Actions to take" %}</h2>
Expand Down Expand Up @@ -106,16 +106,8 @@ <h2 class="mb-2 card-title">{% trans "Actions to take" %}</h2>
{% trans "Revisions" %}
</a>

{% if request.user|can_translate_submission %}
<button
class="w-full btn btn-outline"
hx-get="{% url 'funds:submissions:translate' pk=object.pk %}"
hx-target="#htmx-modal"
>
{% heroicon_outline "language" aria_hidden="true" size=16 stroke_width=2 class="size-4" %}
{% trans "Translate" %}
</button>
{% endif %}
{# Extension point for plugins to add buttons to the staff submission actions. #}
{% hook "submission_admin_actions" %}

<button
class="w-full btn btn-outline"
Expand Down
41 changes: 1 addition & 40 deletions hypha/apply/funds/templates/funds/includes/rendered_answers.html
Original file line number Diff line number Diff line change
@@ -1,28 +1,4 @@
{% load i18n wagtailusers_tags workflow_tags translate_tags heroicons %}

{% if request.user|can_translate_submission %}
{% if from_lang_name and to_lang_name %}
{# For active translations #}
<div role="alert" class="mb-2 alert alert-info">
{% heroicon_mini "language" aria_hidden="true" stroke_width=2 class="opacity-80 size-5" %}
{% blocktrans trimmed %}
This application is translated from {{from_lang_name}} to {{to_lang_name}}.
{% endblocktrans %}
<a href="{% url 'funds:submissions:detail' object.id %}" class="btn btn-sm btn-outline">
{% trans "See original" %}
</a>
</div>
{% else %}
{# For a translation loading indicator #}
<div
role="alert"
id="translate-card-loading"
class="overflow-hidden content-center p-0 m-0 w-full h-0 text-center rounded-lg shadow-md"
>
<span class="loading loading-dots"></span>
</div>
{% endif %}
{% endif %}
{% load i18n wagtailusers_tags workflow_tags heroicons %}

<section class="@container">
<h3 class="pb-2 mb-2 font-medium border-b text-h3">
Expand Down Expand Up @@ -81,18 +57,3 @@ <h3 class="pb-2 mb-2 font-medium border-b text-h3">
</div>

</section>

<style type="text/css">
#translate-card-loading.htmx-request.htmx-indicator{
height: 3rem;
transition: height 0.25s ease-in;
margin-top: 0.5rem;
margin-bottom: 0.5rem;
border-width: 1px;
}

#translate-card-loading.htmx-request.htmx-indicator span {
display: inline-block;
height: 1rem;
}
</style>
Loading