Skip to content

Write resources without fetch, using data model fields - #4391

Open
eemeli wants to merge 7 commits into
mozilla:mainfrom
eemeli:write-from-db
Open

Write resources without fetch, using data model fields#4391
eemeli wants to merge 7 commits into
mozilla:mainfrom
eemeli:write-from-db

Conversation

@eemeli

@eemeli eemeli commented Aug 11, 2026

Copy link
Copy Markdown
Member

After merging this, mozilla/webservices-infra#9295 should be reverted.

The serialization is changed to rely on data we store during the sync, and on the data model representations of translations, rather than on re-parsing the source resource and patching it with strings.

This will mean that the serialization will change for rather many files, as e.g. standalone comments are getting dropped.

The three commits here could also be filed each as separate stacked PRs; please let me know if that would be preferable.

Direct downloads of translated resources are re-enabled. Their UX is essentially unchanged from the current one, i.e. only single file downloads are offered. We could and should iterate on this to address other pre-existing issues, but as later work.

@codecov-commenter

codecov-commenter commented Aug 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.42268% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.67%. Comparing base (157b622) to head (ac12f8d).
⚠️ Report is 9 commits behind head on main.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@eemeli
eemeli marked this pull request as ready for review August 13, 2026 16:03
@eemeli
eemeli requested a review from mathjazz August 13, 2026 16:36

@mathjazz mathjazz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few high-level notes and a coupe inline.

.exclude(approved_date__gt=now) # includes approved_date = None
.select_related("entity")
)
res = build_moz_l10n_resource(db_res)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously, res = parse_resource(ref_path) was inside a try - catch, so the sync carried on in case of an error. Now it seems like it fails for the whole project.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's appropriate? The only reasons this should throw are indicators of something being seriously wrong, and we probably should not continue with a sync in that case.

Comment thread pontoon/sync/core/translations_to_repo.py Outdated
Comment thread pontoon/base/views.py Outdated
response = HttpResponse()
response.content = bytes_io.getvalue()
response["Content-Type"] = "application/zip"
zip_name = re.sub(r"[^.]+$", "zip", filename)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is broken if filename has a dot in the middle?

Why not just add the extension?

zip_name = f"{filename}.zip"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is completely fine with filenames that contain dots; it's only replacing the extension, which is always preceded by a dot. Essentially, it's replicating the default behaviour of gz.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to get better at reading regular expressions :-(

On the naming: would it make more sense to have the extension included though? Currently it produces it_firefox_browser_browser_aboutLogins.zip, maybe it_firefox_browser_browser_aboutLogins_ftl.zip.

Comment thread pontoon/sync/core/translations_to_repo.py
Comment thread pontoon/sync/utils.py
@flodolo

flodolo commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator

Tested with my locale instance, this is Firefox
mozilla-l10n/firefox-l10n@5a077eb

  • I'm a bit surprised by the reordering of parameters in the DATETIME() functions or parameterized terms. What's the logic?
  • I understand some of the closing group-level comments being removed, since they were never open. But there are entire group-level comments removed (e.g. it/browser/browser/aiFeatures.ftl, it/browser/browser/fxviewTabList.ftl) that looks incorrect.

@flodolo

flodolo commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator

Can't reproduce with my local instance. Could it be a problem with MF2-related data migrations?

@eemeli

eemeli commented Aug 18, 2026

Copy link
Copy Markdown
Member Author

I got ValueError: A @fluent-fn attribute is required for :platform when trying to download http://localhost:8000/sl/firefox/browser/browser/aboutLogins.ftl?string=200689

This does not replicate for me.

Does the patch also fix #4107?

No, downloading source/template files is a separate issue.

Why do we download single files as ZIP?

No good reason; that's what the now-removed download_translations_zip() was doing. Now sending them as text/plain.

We should also allow for download (of all project resources) from the All Resources view (or is that #2134)?

Yeah, let's address that in a separate PR.

@eemeli

eemeli commented Aug 18, 2026

Copy link
Copy Markdown
Member Author

I'm a bit surprised by the reordering of parameters in the DATETIME() functions or parameterized terms. What's the logic?

mozilla/moz-l10n#193

I understand some of the closing group-level comments being removed, since they were never open. But there are entire group-level comments removed (e.g. it/browser/browser/aiFeatures.ftl, it/browser/browser/fxviewTabList.ftl) that looks incorrect.

I'm not seeing that. Have you run a force-sync for firefox on your server after #4374 was merged?

@flodolo

flodolo commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator

mozilla/moz-l10n#193

It doesn't match? It serialized day/year/month, I'd expect day/month/year.

I'm not seeing that. Have you run a force-sync for firefox on your server after #4374 was merged?

I'm positive I did several times, but unfortunately I can't tell from Docker's logs 🤔

I do it frequently to remove empty trailing lines that I add to trigger the production instance sync
mozilla-l10n/firefox-l10n@eb2771d

@eemeli

eemeli commented Aug 18, 2026

Copy link
Copy Markdown
Member Author

mozilla/moz-l10n#193

It doesn't match? It serialized day/year/month, I'd expect day/month/year.

Locally, I'm seeing day/month/year when serialising /it/firefox/browser/browser/aboutLogins.ftl. Are you using moz-l10n 0.14.0 or 0.14.1?

@flodolo

flodolo commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator

Locally, I'm seeing day/month/year when serialising /it/firefox/browser/browser/aboutLogins.ftl. Are you using moz-l10n 0.14.0 or 0.14.1?

That's dumb, I missed the dependency update in this PR 🤦🏼

Saw this comment only after I started rebuilding the image, and the image is now using 0.14.1.

The variable order is fixed mozilla-l10n/firefox-l10n@8a5fb3a

But it doesn't look like it restored those group-level comments.

EDIT: I reverted the last 2 commits, and added a new forced sync, so the diff against the output of this branch is clearer
mozilla-l10n/firefox-l10n@7e7c2ea

@eemeli

eemeli commented Aug 18, 2026

Copy link
Copy Markdown
Member Author

it doesn't look like it restored those group-level comments.

Does the group-level comment show up on your instance for e.g. this string?

https://pontoon.mozilla.org/it/firefox/browser/browser/aiFeatures.ftl/?string=337021

@flodolo

flodolo commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator

Does the group-level comment show up on your instance for e.g. this string?

Yes.

Screenshot 2026-08-18 alle 13 33 09

@flodolo

flodolo commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator

For both aiFeatures.flt  and  browser.ftl  the comment is currently duplicated.

Example:
https://github.com/mozilla-l10n/firefox-l10n/blob/ff33c118d557c7aa89be33e92a40cabae61c826f/it/browser/browser/aiFeatures.ftl#L37-L40

https://github.com/mozilla-l10n/firefox-l10n/blob/ff33c118d557c7aa89be33e92a40cabae61c826f/it/browser/browser/aiFeatures.ftl#L99-L102

This is likely a side-effect of the merge from cross-channel. So, this patch is doing the right thing, what's confusing is why these changes don't show up on your side if you test it.

@eemeli

eemeli commented Aug 19, 2026

Copy link
Copy Markdown
Member Author

So, this patch is doing the right thing, what's confusing is why these changes don't show up on your side if you test it.

I think I was seeing a group comment matching the one that was being removed as being included in my local results, and not noticing that the source had two comments with the same contents.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

4 participants