Skip to content

Commit 6093a40

Browse files
authored
Merge pull request #29 from MozillaSecurity/translated-comments
Follow-up to #10 - Show translated comments.
2 parents 260374a + 31c4fbb commit 6093a40

8 files changed

Lines changed: 59 additions & 2 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ norecursedirs = [
9393
[tool.ruff]
9494
fix = true
9595
target-version = "py39"
96+
extend-exclude = ["**/migrations/*.py"]
9697

9798
[tool.ruff.lint]
9899
select = [

server/frontend/src/components/Buckets/ReportPreviewRow.vue

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<td class="wrap-anywhere">
55
<span class="two-line-limit">{{ report.url }}</span>
66
</td>
7-
<td class="wrap-normal">{{ report.comments }}</td>
7+
<td class="wrap-normal">{{ maybeTranslatedComments(report) }}</td>
88
<td>
99
<img
1010
v-if="report.os === 'Linux'"
@@ -78,6 +78,21 @@ export default {
7878
staticLogo(name) {
7979
return window.location.origin + "/static/img/os/" + name + ".png";
8080
},
81+
maybeTranslatedComments(report) {
82+
if (
83+
report.comments_original_language &&
84+
report.comments_original_language !== "en"
85+
) {
86+
// The translation pipeline does escape HTML, and the "easiest" way to
87+
// un-escape that is by just assignign it to an element and letting
88+
// the browser do the magic.. :/
89+
let el = document.createElement("span");
90+
el.innerHTML = `[${report.comments_original_language}] ${report.comments_translated}`;
91+
return el.innerText;
92+
}
93+
94+
return report.comments;
95+
},
8196
},
8297
};
8398
</script>

server/reportmanager/management/commands/import_reports_from_bigquery.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ def handle(self, *args, **options):
3434

3535
client = bigquery.Client(**params)
3636
result = client.query_and_wait(
37-
f"SELECT * FROM `{settings.BIGQUERY_TABLE}` WHERE reported_at >= @since;",
37+
f"""SELECT r.*, t.language_code, t.translated_text
38+
FROM `{settings.BIGQUERY_TABLE}` as r
39+
LEFT JOIN `{settings.BIGQUERY_TRANSLATIONS_TABLE}` t
40+
ON r.uuid = t.report_uuid
41+
WHERE r.reported_at >= @since;""",
3842
job_config=bigquery.QueryJobConfig(
3943
query_parameters=[
4044
bigquery.ScalarQueryParameter("since", "DATETIME", options["since"])
@@ -51,6 +55,8 @@ def handle(self, *args, **options):
5155
app_version=row.app_version,
5256
breakage_category=row.breakage_category,
5357
comments=row.comments,
58+
comments_translated=row.translated_text,
59+
comments_original_language=row.language_code,
5460
details=row.details,
5561
reported_at=row.reported_at.replace(tzinfo=timezone.utc),
5662
url=urlsplit(row.url),
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Generated by Django 4.2.17 on 2025-03-27 04:50
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
dependencies = [
8+
("reportmanager", "0008_bucket_reassign_in_progress"),
9+
]
10+
11+
operations = [
12+
migrations.AddField(
13+
model_name="reportentry",
14+
name="comments_original_language",
15+
field=models.TextField(null=True),
16+
),
17+
migrations.AddField(
18+
model_name="reportentry",
19+
name="comments_translated",
20+
field=models.TextField(null=True),
21+
),
22+
]

server/reportmanager/models.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,8 @@ def create_from_report(self, report):
449449
os=os,
450450
details=report.details,
451451
comments=report.comments,
452+
comments_translated=report.comments_translated,
453+
comments_original_language=report.comments_original_language,
452454
)
453455

454456

@@ -459,6 +461,8 @@ class ReportEntry(models.Model):
459461
)
460462
bucket = models.ForeignKey(Bucket, null=True, on_delete=models.deletion.CASCADE)
461463
comments = models.TextField()
464+
comments_translated = models.TextField(null=True)
465+
comments_original_language = models.TextField(null=True)
462466
details = models.JSONField()
463467
os = models.ForeignKey(OS, on_delete=models.deletion.CASCADE)
464468
reported_at = models.DateTimeField()
@@ -510,6 +514,8 @@ def get_report(self):
510514
app_name=self.app.name,
511515
app_version=self.app.version,
512516
comments=self.comments,
517+
comments_translated=self.comments_translated,
518+
comments_original_language=self.comments_original_language,
513519
details=self.details,
514520
os=self.os.name,
515521
reported_at=self.reported_at,

server/reportmanager/serializers.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ class Meta:
197197
"breakage_category",
198198
"bucket",
199199
"comments",
200+
"comments_translated",
201+
"comments_original_language",
200202
"details",
201203
"id",
202204
"os",

server/server/settings.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ def resolver_context_processor(request):
127127

128128
BIGQUERY_PROJECT = "moz-fx-dev-dschubert-wckb"
129129
BIGQUERY_TABLE = "moz-fx-dev-dschubert-wckb.webcompat_user_reports.user_reports_prod"
130+
BIGQUERY_TRANSLATIONS_TABLE = (
131+
"moz-fx-dev-dschubert-wckb.webcompat_user_reports.translations"
132+
)
130133
BIGQUERY_SERVICE_ACCOUNT = ""
131134

132135
# Modify the way we generate our usernames, based on the email address

src/webcompat/models.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ class Report:
4949
reported_at: datetime
5050
uuid: str
5151
url: SplitResult
52+
comments_translated: str | None = None
53+
comments_original_language: str | None = None
5254
app_channel: str | None = None
5355
breakage_category: str | None = None
5456

0 commit comments

Comments
 (0)