Skip to content

Commit b0bca7d

Browse files
committed
Merge branch '4506-ghost-text' of github.com:ayshushus/pontoon into ayshushus-4506-ghost-text
2 parents e8c26f2 + d3c213f commit b0bca7d

25 files changed

Lines changed: 1281 additions & 26 deletions

File tree

‎documentation/docs/localizer/translation-workspace.md‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ In the lower-right side of the editing space, it’s possible to `COPY` the sour
167167

168168
In the lower-left side:
169169

170-
* Clicking the gear icon allows users to toggle `Translation Toolkit checks` and `Make suggestions`, select their editor theme, and navigate to the user settings. Note that access to some settings is restricted by [user permissions](users.md#user-roles).
170+
* Clicking the gear icon allows users to toggle `Translation Toolkit checks` and `Make suggestions`, choose how to [autocomplete from Machinery](#autocomplete-from-machinery), select their editor theme, and navigate to the user settings. Note that access to some settings is restricted by [user permissions](users.md#user-roles).
171171
* Clicking the keyboard icon displays a list of available shortcuts.
172172
* The numbers displayed to the right of the keyboard icon (e.g. `50|59`) are the number of characters in the target and source string.
173173

@@ -284,6 +284,8 @@ Machinery shows possible translations from a variety of sources. These sources i
284284
* [Caighdean](https://github.com/kscanne/caighdean).
285285
* [Bing Translator](https://www.bing.com/translator) (not currently enabled on pontoon.mozilla.org).
286286

287+
Machinery suggestions can be used to [complete translations as you type](#autocomplete-from-machinery) in the editor.
288+
287289
In addition, the user has the ability to search for translations containing words via [`Concordance search`](#concordance-search).
288290

289291
In the tab, the number of entries is visible alongside the `MACHINERY` title in white. If any of the machinery matches are from translation memory, the number of matches will appear separately in green. For example, the screenshot below shows `2+1`, where the green `2` represents the two matches from translation memory and the `1` represents a machinery entry from Google Translate.
@@ -298,6 +300,24 @@ The origin of the machinery entry is listed in gray above the source string. Cli
298300

299301
Be careful when using the machinery tab as suggestions may not match the source string for the project being translated. Even if the source strings match, the context in which strings are used may not be the same. This could lead to incorrect or unnatural translations. Always keep the meaning and purpose of the string being translated in mind when using the machinery tab.
300302

303+
#### Autocomplete from Machinery
304+
305+
As you type a translation, the editor can complete it from the current string's Machinery suggestions (translation memory, machine translation, and LLM suggestions). The completion appears in gray after the cursor. Press `Tab` to accept it or `Esc` to hide it.
306+
307+
Set how much is offered with the `AUTOCOMPLETE` option in the [Editor's gear icon](#editor) or the [settings page](users.md#editor):
308+
309+
* `Off`: no completions.
310+
* `Word` (default): one word at a time.
311+
* `Full`: the rest of the suggestion.
312+
313+
The editor uses the suggestion that best matches what you've typed so far. Nothing is offered until the match is long enough.
314+
315+
With `Word`, each `Tab` accepts the next word, along with its punctuation and trailing space. Placeholders and tags are completed as a whole. In languages without spaces, `Tab` accepts one word at a time.
316+
317+
With `Full`, the whole remainder is offered only when the cursor is at the end of the translation. Elsewhere, completion goes word by word so the text after the cursor isn't duplicated.
318+
319+
Autocomplete steps aside in two cases. While the placeholder list is open, `Tab` picks from that list. During a Concordance search, no completions are offered.
320+
301321
#### Large language model (LLM) integration
302322

303323
Pontoon will show a dropdown labeled `AI` for all locales that have Google Translate available as a translation source. This feature refines the Google Translate output using an LLM. Opening this dropdown will reveal three options:

‎documentation/docs/localizer/users.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ To change a theme, select the button corresponding to your preferred option. The
8686

8787
`Make suggestions` allows a translator or a team manager to submit suggestions instead of translations. This setting is also displayed to users with translator permissions.
8888

89+
`Autocomplete from Machinery` sets how the editor completes translations as the user types, using the Machinery suggestions for the current string: `Off`, `Word by word` (the default), or `Full continuation`. For more information, see [this document](translation-workspace.md#autocomplete-from-machinery).
90+
8991
### Default search options
9092

9193
Users can configure default search options to use when searching for strings in the translation workspace or the [Translation Search page](search.md). The following options can be enabled by default:
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Generated by Django 5.2.18 on 2026-10-26 21:37
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
dependencies = [
8+
("base", "0138_mark_anonymous_user_as_system_user"),
9+
]
10+
11+
operations = [
12+
migrations.AddField(
13+
model_name="userprofile",
14+
name="machinery_autocomplete",
15+
field=models.BooleanField(default=False),
16+
),
17+
]
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from django.db import migrations, models
2+
3+
4+
class Migration(migrations.Migration):
5+
dependencies = [
6+
("base", "0139_userprofile_machinery_autocomplete"),
7+
]
8+
9+
operations = [
10+
migrations.RemoveField(
11+
model_name="userprofile",
12+
name="machinery_autocomplete",
13+
),
14+
migrations.AddField(
15+
model_name="userprofile",
16+
name="machinery_autocomplete",
17+
field=models.CharField(
18+
choices=[
19+
("off", "Off"),
20+
("word", "Word by word"),
21+
("full", "Full continuation"),
22+
],
23+
max_length=20,
24+
null=True,
25+
blank=True,
26+
default=None,
27+
),
28+
),
29+
]

‎pontoon/base/models/user_profile.py‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,22 @@ class EmailFrequencies(models.TextChoices):
128128
quality_checks = models.BooleanField(default=True)
129129
force_suggestions = models.BooleanField(default=False)
130130

131+
class MachineryAutocomplete(models.TextChoices):
132+
OFF = "off", "Off"
133+
WORD = "word", "Word by word"
134+
FULL = "full", "Full continuation"
135+
136+
DEFAULT_MACHINERY_AUTOCOMPLETE = MachineryAutocomplete.WORD
137+
138+
# Null default like the editor theme, useful for later migrations while keeping user preferences.
139+
machinery_autocomplete = models.CharField(
140+
choices=MachineryAutocomplete.choices,
141+
max_length=20,
142+
null=True,
143+
blank=True,
144+
default=None,
145+
)
146+
131147
# Search settings
132148
search_exclude_source_strings = models.BooleanField(default=False)
133149
search_identifiers = models.BooleanField(default=False)
@@ -190,6 +206,10 @@ class SystemUserRole(models.TextChoices):
190206
def preferred_locales(self):
191207
return Locale.objects.filter(pk__in=self.locales_order)
192208

209+
@property
210+
def machinery_autocomplete_mode(self):
211+
return self.machinery_autocomplete or self.DEFAULT_MACHINERY_AUTOCOMPLETE
212+
193213
class Meta:
194214
constraints = [
195215
models.UniqueConstraint(

‎pontoon/base/views.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,6 +1178,7 @@ def user_data(request):
11781178
"settings": {
11791179
"quality_checks": user.profile.quality_checks,
11801180
"force_suggestions": user.profile.force_suggestions,
1181+
"machinery_autocomplete": user.profile.machinery_autocomplete_mode,
11811182
"search_exclude_source_strings": user.profile.search_exclude_source_strings,
11821183
"search_identifiers": user.profile.search_identifiers,
11831184
"search_match_case": user.profile.search_match_case,

‎pontoon/contributors/static/css/settings.css‎

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -233,32 +233,42 @@ form a:visited {
233233
margin-bottom: 0;
234234
}
235235

236-
#main .appearance .theme-field .theme-label {
236+
#main .machinery-autocomplete-field {
237+
margin-top: 18px;
238+
}
239+
240+
#main .appearance .theme-field .theme-label,
241+
#main .machinery-autocomplete-field .theme-label {
237242
color: var(--light-grey-2);
238243
font-size: 14px;
239244
font-style: italic;
240245
font-weight: 400;
241246
margin: 0 0 8px;
242247
}
243248

244-
#main .appearance .toggle-button {
249+
#main .appearance .toggle-button,
250+
#main .machinery-autocomplete-field .toggle-button {
245251
display: inline-flex;
246252
}
247253

248-
#main .appearance .toggle-button button {
254+
#main .appearance .toggle-button button,
255+
#main .machinery-autocomplete-field .toggle-button button {
249256
width: 207px;
250257
}
251258

252-
#main .appearance .toggle-button button:first-child {
259+
#main .appearance .toggle-button button:first-child,
260+
#main .machinery-autocomplete-field .toggle-button button:first-child {
253261
margin-right: -1px;
254262
}
255263

256-
#main .appearance .toggle-button button:nth-child(2) {
264+
#main .appearance .toggle-button button:nth-child(2),
265+
#main .machinery-autocomplete-field .toggle-button button:nth-child(2) {
257266
border-radius: 0;
258267
margin-right: -1px;
259268
}
260269

261-
#main .appearance .toggle-button button:last-child {
270+
#main .appearance .toggle-button button:last-child,
271+
#main .machinery-autocomplete-field .toggle-button button:last-child {
262272
border-left: 1px solid var(--main-border-1);
263273
}
264274

‎pontoon/contributors/static/js/settings.js‎

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ $(function () {
112112

113113
const self = $(this);
114114

115-
// Theme toggle is handled separately
116-
if (self.parents('.appearance').length) {
115+
// Theme and autocomplete toggles are handled separately
116+
if (self.parents('.appearance, .machinery-autocomplete-field').length) {
117117
return;
118118
}
119119

@@ -154,6 +154,33 @@ $(function () {
154154
});
155155
});
156156

157+
$('.machinery-autocomplete-field .toggle-button button').click(function (e) {
158+
e.preventDefault();
159+
160+
const self = $(this);
161+
162+
if (self.is('.active')) {
163+
return;
164+
}
165+
166+
$.ajax({
167+
url: '/user/machinery-autocomplete/',
168+
type: 'POST',
169+
data: {
170+
csrfmiddlewaretoken: $('body').data('csrf'),
171+
machinery_autocomplete: self.val(),
172+
},
173+
success() {
174+
self.addClass('active');
175+
self.siblings().removeClass('active');
176+
Pontoon.endLoader('Settings saved.');
177+
},
178+
error() {
179+
Pontoon.endLoader('Oops, something went wrong.', 'error');
180+
},
181+
});
182+
});
183+
157184
$('.generate-token-btn').click(function (e) {
158185
e.preventDefault();
159186

‎pontoon/contributors/templates/contributors/settings.html‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,36 @@ <h3>Editor</h3>
375375
}}
376376
{% endif %}
377377
</div>
378+
<div class="field machinery-autocomplete-field">
379+
{% set autocomplete = user.profile.machinery_autocomplete_mode %}
380+
<p class="theme-label">Autocomplete from Machinery</p>
381+
<span class="toggle-button">
382+
<button
383+
type="button"
384+
value="off"
385+
class="off {% if autocomplete == 'off' %}active{% endif %}"
386+
title="Do not autocomplete from Machinery"
387+
>
388+
Off
389+
</button>
390+
<button
391+
type="button"
392+
value="word"
393+
class="word {% if autocomplete == 'word' %}active{% endif %}"
394+
title="Autocomplete from Machinery one word at a time"
395+
>
396+
Word by word
397+
</button>
398+
<button
399+
type="button"
400+
value="full"
401+
class="full {% if autocomplete == 'full' %}active{% endif %}"
402+
title="Autocomplete the rest of a Machinery translation"
403+
>
404+
Full continuation
405+
</button>
406+
</span>
407+
</div>
378408
</section>
379409

380410
<section id="default-search-options">

‎pontoon/contributors/tests/test_views.py‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,42 @@ def test_toggle_user_profile_attribute(member):
269269
assert response.status_code == 200
270270

271271

272+
@pytest.mark.django_db
273+
def test_toggle_machinery_autocomplete(member):
274+
"""toggle_machinery_autocomplete accepts valid choices and rejects invalid ones."""
275+
url = "/user/machinery-autocomplete/"
276+
277+
def get_setting():
278+
response = member.client.get(
279+
"/user-data/", HTTP_X_REQUESTED_WITH="XMLHttpRequest"
280+
)
281+
return response.json()["settings"]["machinery_autocomplete"]
282+
283+
assert member.user.profile.machinery_autocomplete is None
284+
assert get_setting() == "word"
285+
286+
for value in ("off", "full", "word"):
287+
response = member.client.post(url, {"machinery_autocomplete": value})
288+
assert response.status_code == 200
289+
assert response.json() == {"status": True}
290+
member.user.profile.refresh_from_db()
291+
assert member.user.profile.machinery_autocomplete == value
292+
assert get_setting() == value
293+
294+
# reject invalid choice and unchange stored value
295+
response = member.client.post(url, {"machinery_autocomplete": "true"})
296+
assert response.status_code == 400
297+
member.user.profile.refresh_from_db()
298+
assert member.user.profile.machinery_autocomplete == "word"
299+
300+
response = member.client.post(url, {})
301+
assert response.status_code == 400
302+
303+
params = {"attribute": "machinery_autocomplete", "value": "true"}
304+
response = member.client.post("/user/attributes/toggle/", params)
305+
assert response.status_code == 403
306+
307+
272308
@pytest.mark.django_db
273309
def test_toggle_editor_theme(member):
274310
"""toggle_editor_theme accepts valid choices and rejects invalid ones."""

0 commit comments

Comments
 (0)