Skip to content

Add endpoint to fetch fluent reference variants - #4517

Merged
mathjazz merged 8 commits into
mozilla:mainfrom
julen:ftl-variants-autocomplete-backend
Oct 7, 2026
Merged

mathjazz merged 8 commits into
mozilla:mainfrom
julen:ftl-variants-autocomplete-backend

Conversation

@julen

@julen julen commented Sep 11, 2026 •

Copy link
Copy Markdown
Collaborator

Refs. #2363

In this changeset we introduce the /get-fluent-terms/ endpoint that allows
consumers to retrieve any term selectors and their variants for a locale within
a project.

This endpoint requires a project slug and a locale code.

The view:

  • Produces 400/404 for invalid input.
  • Returns a mapping from a fluent term to its source and translation values and
    properties.

Terms are determined by listing Fluent resource entities that are part of the
provided project and start with the - character. When translations for the
specified locale are missing, these come back as None.

Note this is the building block for the Fluent term variants autocomplete
feature that will be implemented separately, so the endpoint is not being used
yet.

This will be incorporated to utilities s.t. we can directly pass
strings instead of manually parsing at call-sites.
This optionally moves the parsing to the utility bodies, which allows us
to simplify tests and eventually call-sites.
@julen

julen commented Sep 11, 2026

Copy link
Copy Markdown
Collaborator Author

The diffstat is rather large for my taste, but it's mostly tests.

I have attempted to follow the existing project conventions, if there's something that I missed that needs adjusting, just let me know. Also if I misinterpreted any terminology around Fluent strings I'd be happy to be corrected -- this was the first time for me fiddling with the format as well as with its AST.

Comment thread pontoon/base/fluent_utils.py Outdated
eemeli
eemeli previously requested changes Sep 11, 2026

@eemeli eemeli left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Took a quick peek at this before I head off to PTO, so please dismiss my review if it gets stale:

As @mathjazz mentions in #2363 (comment), this API should be fetching all available terms in a project+locale, not just the ones referenced in a single entity. Terms are Fluent-only, and identifiable by their identifier starting with a hyphen-minus - character.

There also should be no need to do any parsing as a part of the work here.

@julen

julen commented Sep 11, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks for the quick check before the PTO @eemeli!

I definitely misread the intent in #2363 (comment), but I now see the assumption and the trade-off makes sense.

re.

There also should be no need to do any parsing as a part of the work here.

I'm not super familiar with the data model, so correct me if I'm wrong, but as I see now Entity.value (as well as Translation.value) contain a JSON-serialized representation which should include the parsed parts, and this should be readable by the frontend already. Is this what you mean here?

@eemeli

eemeli commented Sep 11, 2026

Copy link
Copy Markdown
Member

I'm not super familiar with the data model, so correct me if I'm wrong, but as I see now Entity.value (as well as Translation.value) contain a JSON-serialized representation which should include the parsed parts, and this should be readable by the frontend already. Is this what you mean here?

Yes. For Fluent terms, you'll also need to account for Entity.properties and Translation.properties. There are also some utilities here that may be useful, if you need to do more on the server than pass the JSON to the frontend.

This has been superseded by the get_fluent_terms view, which fetches
term translations at the project level instead, and requires no Fluent
format parsing in the view.
The `get_references` and `get_selector_variants` Fluent format helpers
were only used by the removed view.
@julen

julen commented Sep 24, 2026

Copy link
Copy Markdown
Collaborator Author

Sorry for the delay here, life happened in the middle… the code has now been updated to fetch all available terms for a project+locale combination. The PR description has been updated accordingly, too.

@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.

Apologies for the slow turnaround here — we were at the Mozilla engineering summit.

This looks good to me, nice work!

The payload is keyed on the bare term identifier, so two .ftl files in a project defining the same term would overwrite each other. Given the way we use terms at Mozilla, we should be good. If it turns out to be a problem in practice, let's address it separately.

@mathjazz
mathjazz dismissed eemeli’s stale review October 7, 2026 16:40

"...please dismiss my review if it gets stale:"

@mathjazz
mathjazz merged commit d9b6bdf into mozilla:main Oct 7, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants