Repository navigation
Add optional locale to collection metadata blocks API #12905 - #12906
thiagolepidus wants to merge 5 commits into
Conversation
|
@thiagolepidus thanks for the pull request! I just kicked off a topic here: #internationalization > metadata blocks locale #12905 @ 💬 You might be interested in joining this new working group: #internationalization > Internationalization WG meeting today! @ 💬 |
There was a problem hiding this comment.
The locale description should spell out what's accepted:
- The value is parsed as a BCP 47 language tag (e.g. fr, fr-CA, pt-BR). Underscores are converted to hyphens, which is the only reason fr_CA works too. Saying that would make clear the two examples aren't a fixed list.
- Which inputs return 400 (malformed tags like fr#CA, or tags without a language like und).
- That a well-formed tag with no installed bundle (e.g. de on an installation without German) returns 200 with the default text, not an error. The fallback order should be stated too (e.g. fr-CA → fr → default).
- Inputs like frCA and fr-CAN are currently accepted as languages frca and can and silently fall back to defaults. Should the API reject them, e.g. by requiring a 2–3 letter language subtag and a 2-letter or 3-digit region? If not, the docs should at least warn that the server doesn't check whether the language is real.
The documentation is a bit light on explaining these behaviors
| Locale locale = null; | ||
| if (localeTag != null) { | ||
| try { | ||
| locale = new Locale.Builder().setLanguageTag(localeTag.replace('_', '-')).build(); |
There was a problem hiding this comment.
This doesn't appear to match what we tend to use for locale parsing. Rather than a new query parameter with inline parsing, could this use the Accept-Language header and I18nUtil.parseAcceptLanguageHeader, as GET /api/datasets/datasetTypes already does?
Please refer
There was a problem hiding this comment.
This is a fairly small, low-risk PR. Requests without locale seem to behave pretty much exactly as before. The unit tests cover the logic well. I don't think an integration test is required here, checking real translations means adding language packs to CI, which I'm not ready to do yet.
After settling these comments and any others, this looks good to me otherwise, pending CI. Thank you so much for the work!
Reuse I18nUtil for weighted language preferences, preserve absent and empty headers, and return localized HTTP 400 responses for malformed ranges. Cover language and base-bundle fallback without validating language registry membership.
|
Thanks for the review! The endpoint now uses Documentation and tests now cover language priorities, malformed headers, fallback, and the parser’s lack of registry validation. Following the shared parser, |
ashmanda-cs
left a comment
There was a problem hiding this comment.
Looks fine to me, pending code owners. Thanks for making the changes so promptly!
|
Today we had a brief discussion of this PR at the frontend meeting. @qqmyers brought up that we should consider where we want translations to live in this case, in the backend or the frontend. We plan to discuss more at the next Triage Tuesday. |
What this PR does / why we need it:
Adds an optional
localeparameter toGET /api/dataverses/{identifier}/metadatablocks, allowing integrated applications to build metadata forms using the language bundles installed in Dataverse.The parameter translates metadata block display names and field titles, display names, descriptions, and watermarks, including compound child fields.
Requests without
localeretain their current behavior. Identifiers, field definitions, and controlled vocabulary values remain unchanged.Which issue(s) this PR closes:
localeparameter to the collection metadata blocks endpoint #12905Special notes for your reviewer:
Translations use the existing
BundleUtilinfrastructure and standard resource bundle fallback. If no bundle or key is available, the corresponding database value is retained.The locale is passed explicitly without changing the server's default locale. Empty or malformed values, and tags without a language, return HTTP 400. Error messages are defined in
Bundle.properties.Suggestions on how to test this:
With Canadian French language bundles installed, compare:
Verify translated block names, field labels, descriptions, watermarks, and compound child fields. Confirm that identifiers, field definitions, and controlled vocabulary values remain unchanged.
Also verify:
returnDatasetFieldTypes=false.zz-ZZ, uses fallback values.fr--CA, return HTTP 400.Does this PR introduce a user interface change? If mockups are available, please link/include them here:
No.
Is there a release notes update needed for this change?:
Yes. Included in
doc/release-notes/12905-metadata-blocks-locale.md.Additional documentation:
Updated the Native API Guide with the
localeparameter, usage example, fallback behavior, and validation rules.