Skip to content

Commit d340e87

Browse files
authored
Revert translations for now. Increase build size to much, Heroku has a 500 MB max (#4199)
1 parent 7510fa5 commit d340e87

32 files changed

+11
-1561
lines changed

hypha/apply/funds/fields.py

-39
This file was deleted.

hypha/apply/funds/forms.py

-28
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@
1111
from wagtail.signal_handlers import disable_reference_index_auto_update
1212

1313
from hypha.apply.categories.models import MetaTerm
14-
from hypha.apply.translate.utils import get_available_translations
1514
from hypha.apply.users.models import User
1615

17-
from .fields import LanguageChoiceField
1816
from .models import (
1917
ApplicationSubmission,
2018
AssignedReviewers,
@@ -379,32 +377,6 @@ def submissions_cant_have_external_reviewers(self, submissions):
379377
return False
380378

381379

382-
class TranslateSubmissionForm(forms.Form):
383-
available_packages = get_available_translations()
384-
385-
from_lang = LanguageChoiceField("from", available_packages)
386-
to_lang = LanguageChoiceField("to", available_packages)
387-
388-
def clean(self):
389-
form_data = self.cleaned_data
390-
try:
391-
from_code = form_data["from_lang"]
392-
to_code = form_data["to_lang"]
393-
394-
to_packages = get_available_translations([from_code])
395-
396-
if to_code not in [package.to_code for package in to_packages]:
397-
self.add_error(
398-
"to_lang",
399-
"The specified language is either invalid or not installed",
400-
)
401-
402-
return form_data
403-
except KeyError as err:
404-
# If one of the fields could not be parsed, there is likely bad input being given
405-
raise forms.ValidationError("Invalid input selected") from err
406-
407-
408380
def make_role_reviewer_fields():
409381
role_fields = []
410382
staff_reviewers = User.objects.staff().only("full_name", "pk")

hypha/apply/funds/services.py

+1-61
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import re
2-
3-
from bs4 import BeautifulSoup, element
1+
from bs4 import element
42
from django.apps import apps
53
from django.conf import settings
64
from django.core.exceptions import PermissionDenied
@@ -23,7 +21,6 @@
2321
from hypha.apply.funds.models.assigned_reviewers import AssignedReviewers
2422
from hypha.apply.funds.workflow import INITIAL_STATE
2523
from hypha.apply.review.options import DISAGREE, MAYBE
26-
from hypha.apply.translate import translate
2724

2825

2926
def bulk_archive_submissions(
@@ -266,63 +263,6 @@ def annotate_review_recommendation_and_count(submissions: QuerySet) -> QuerySet:
266263
return submissions
267264

268265

269-
def translate_application_form_data(application, from_code: str, to_code: str) -> dict:
270-
"""Translate the content of an application's live revision `form_data`.
271-
Will parse fields that contain both plaintext & HTML, extracting & replacing strings.
272-
273-
NOTE: Mixed formatting like `<p>Hey from <strong>Hypha</strong></p>` will result in a
274-
string that is stripped of text formatting (untranslated: `<p>Hey from Hypha</p>`). On
275-
the other hand, unmixed strings like `<p><strong>Hey from Hypha</strong></p>` will be
276-
replaced within formatting tags.
277-
278-
Args:
279-
application: the application to translate
280-
from_code: the ISO 639 code of the original language
281-
to_code: the ISO 639 code of the language to translate to
282-
283-
Returns:
284-
The `form_data` with values translated (including nested HTML strings)
285-
286-
Raises:
287-
ValueError if an invalid `from_code` or `to_code` is requested
288-
"""
289-
form_data: dict = application.live_revision.form_data
290-
291-
translated_form_data = form_data.copy()
292-
293-
# Only translate content fields or the title - don't with name, email, etc.
294-
translated_form_data["title"] = translate.translate(
295-
form_data["title"], from_code, to_code
296-
)
297-
298-
# RegEx to match wagtail's generated field UIDs - ie. "97c51cea-ab47-4a64-a64a-15d893788ef2"
299-
uid_regex = re.compile(r"([a-z]|\d){8}(-([a-z]|\d){4}){3}-([a-z]|\d){12}")
300-
fields_to_translate = [
301-
key
302-
for key in form_data
303-
if uid_regex.match(key) and isinstance(form_data[key], str)
304-
]
305-
306-
for key in fields_to_translate:
307-
field_html = BeautifulSoup(form_data[key], "html.parser")
308-
if field_html.find(): # Check if BS detected any HTML
309-
for field in field_html.find_all(has_valid_str):
310-
# Removes formatting if mixed into the tag to prioritize context in translation
311-
# ie. `<p>Hey <strong>y'all</strong></p>` -> `<p>Hey y'all</p>` (but translated)
312-
to_translate = field.string if field.string else field.text
313-
field.clear()
314-
field.string = translate.translate(to_translate, from_code, to_code)
315-
316-
translated_form_data[key] = str(field_html)
317-
# Ensure the field value isn't empty & translate as is
318-
elif form_data[key].strip():
319-
translated_form_data[key] = translate.translate(
320-
form_data[key], from_code, to_code
321-
)
322-
323-
return translated_form_data
324-
325-
326266
def has_valid_str(tag: element.Tag) -> bool:
327267
"""Checks that an Tag contains a valid text element and/or string.
328268

hypha/apply/funds/templates/funds/applicationsubmission_admin_detail.html

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{% extends "funds/applicationsubmission_detail.html" %}
2-
{% load i18n static workflow_tags review_tags determination_tags translate_tags heroicons %}
2+
{% load i18n static workflow_tags review_tags determination_tags heroicons %}
33

44
{% block extra_css %}
55
<link rel="stylesheet" href="{% static 'css/fancybox.css' %}">
@@ -98,7 +98,4 @@ <h5 class="m-0">{% trans "Reminders" %}</h5>
9898
<script src="{% static 'js/jquery.fancybox.min.js' %}"></script>
9999
<script src="{% static 'js/fancybox-global.js' %}"></script>
100100
<script src="{% static 'js/behaviours/collapse.js' %}"></script>
101-
{% if request.user|can_translate_submission %}
102-
<script src="{% static 'js/translate-application.js' %}"></script>
103-
{% endif %}
104101
{% endblock %}

hypha/apply/funds/templates/funds/applicationsubmission_detail.html

+3-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{% extends "base-apply.html" %}
2-
{% load i18n static workflow_tags wagtailcore_tags statusbar_tags archive_tags submission_tags translate_tags %}
2+
{% load i18n static workflow_tags wagtailcore_tags statusbar_tags archive_tags submission_tags %}
33
{% load heroicons %}
44

55
{% block title %}{{ object.title_text_display }}{% endblock %}
@@ -146,15 +146,8 @@ <h5>{% blocktrans with stage=object.previous.stage %}Your {{ stage }} applicatio
146146
{% endif %}
147147
</div>
148148
</header>
149-
{% if request.user|can_translate_submission %}
150-
<div class="wrapper" 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}'>
151-
{% include "funds/includes/rendered_answers.html" %}
152-
</div>
153-
{% else %}
154-
<div class="wrapper">
155-
{% include "funds/includes/rendered_answers.html" %}
156-
</div>
157-
{% endif %}
149+
150+
{% include "funds/includes/rendered_answers.html" %}
158151

159152
</article>
160153
{% endif %}

hypha/apply/funds/templates/funds/includes/admin_primary_actions.html

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{% load i18n %}
2-
{% load heroicons primaryactions_tags translate_tags %}
2+
{% load heroicons primaryactions_tags %}
33

44
<h5>{% trans "Actions to take" %}</h5>
55

@@ -84,13 +84,6 @@ <h5>{% trans "Actions to take" %}</h5>
8484
<summary class="sidebar__separator sidebar__separator--medium">{% trans "More actions" %}</summary>
8585
<a class="button button--white button--full-width button--bottom-space" href="{% url 'funds:submissions:revisions:list' submission_pk=object.id %}">{% trans "Revisions" %}</a>
8686

87-
{% if request.user|can_translate_submission %}
88-
<button class="button button--white button--full-width button--bottom-space" hx-get="{% url 'funds:submissions:translate' pk=object.pk %}" hx-target="#htmx-modal">
89-
{% heroicon_outline "language" aria_hidden="true" size=15 stroke_width=2 class="inline align-baseline me-1" %}
90-
{% trans "Translate" %}
91-
</button>
92-
{% endif %}
93-
9487
<button
9588
class="button button--white button--full-width button--bottom-space"
9689
hx-get="{% url 'funds:submissions:metaterms_update' pk=object.pk %}"
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,5 @@
1-
{% load i18n wagtailusers_tags workflow_tags translate_tags heroicons %}
2-
{% if request.user|can_translate_submission and from_lang_name and to_lang_name %}
3-
<div class="w-full text-center my-2 py-5 border rounded-lg shadow-md">
4-
<span>
5-
{% heroicon_outline "language" aria_hidden="true" size=15 stroke_width=2 class="inline align-baseline me-1" %}
6-
{% blocktrans %} This application is translated from {{from_lang_name}} to {{to_lang_name}}. {% endblocktrans %}
7-
<a href="{% url 'funds:submissions:detail' object.id %}">
8-
{% trans "See original" %}
9-
</a>
10-
</span>
11-
</div>
12-
{% else %}
13-
<div id="translate-card-loading" class="w-full text-center my-2 py-5 border rounded-lg shadow-md animate-pulse htmx-indicator">
14-
<span class="w-full bg-gray-200 rounded-lg"></span>
15-
</div>
16-
{% endif %}
1+
{% load i18n wagtailusers_tags workflow_tags %}
2+
173
<h3 class="text-xl border-b pb-2 font-bold">{% trans "Proposal Information" %}</h3>
184
<div class="hypha-grid hypha-grid--proposal-info">
195
{% if object.get_value_display != "-" %}
@@ -58,30 +44,3 @@ <h5 class="text-base">{% trans "Organization name" %}</h5>
5844
<div class="rich-text rich-text--answers">
5945
{{ object.output_answers }}
6046
</div>
61-
62-
<style type="text/css">
63-
#translate-card-loading span {
64-
width: 490px;
65-
}
66-
67-
#translate-card-loading.htmx-indicator{
68-
height: 0;
69-
margin: 0;
70-
padding: 0;
71-
overflow: hidden;
72-
align-content: center;
73-
border-width: 0px;
74-
}
75-
#translate-card-loading.htmx-request.htmx-indicator{
76-
height: 64px;
77-
transition: height 0.25s ease-in;
78-
margin-top: 0.5rem;
79-
margin-bottom: 0.5rem;
80-
border-width: 1px;
81-
}
82-
83-
#translate-card-loading.htmx-request.htmx-indicator span {
84-
display: inline-block;
85-
height: 1rem;
86-
}
87-
</style>

0 commit comments

Comments
 (0)