Page MenuHomePhabricator

REST: Make OpenAPI spec info strings translatable
Closed, ResolvedPublic5 Estimated Story Points

Description

MediaWiki REST API includes several strings that appear in the info section of OpenAPI specs. These strings are currently either hard-coded, or taken from module definition .json files. We should make these strings translatable.

Descriptions

Module definition .json files can appear in either core or in extensions. For example:

Either way, SpecBasedModule is used to load the module file, and related code can be found there.

The module definition .json files may include an optional description (per the OpenAPI schema). Right now, these descriptions are inserted verbatim into the generated OpenAPI spec.

Add support for x-i18n-description keys, similar to the approach we used for response bodies in T379706: [Research Spike] Create response body translation mechanism. Code similar to ResolveResponseDescription will resolve these into translated strings. Opportunities for sharing code between those usages should be considered.

If no x-i18-description key is present, but a description key is, then the description key should continue to be used, as it is now. This will maintain backwards compatibility, and also allow simpler code for extensions (including third-party ones not hosted at WMF) that do not require translated descriptions.

If both a x-i18n-description key and and description key are present, then the x-i18n-description key should be used.

Default Module

Legacy methods of registering endpoints are still supported:

In these cases, the endpoints are grouped into a "default module".

The legacy formats did not support titles or descriptions. Instead, placeholder strings are hard-coded in ExtraRoutesModule::getOpenApiInfo(). We should replace these hard-coded strings with MessageValue instances that use new message keys (and add these keys to the qqq.json and en.json files, per our normal translation approach).

Other Strings

There are two additional hard-coded strings in ModuleSpecHandler ("Default Module" and "Module") that should also be made translatable.

Completion Criteria:

  • module definition files support x-i18n-description keys (with testing, if possible)
  • the "default module" strings are translatable (manual testing sufficient)
  • the miscellaneous other strings are translatable (manual testing sufficient)

Event Timeline

HCoplin-WMF triaged this task as Medium priority.
HCoplin-WMF set the point value for this task to 5.

Change #1127608 had a related patch set uploaded (by BPirkle; author: BPirkle):

[mediawiki/core@master] REST: Make OpenAPI spec info strings translatable

https://gerrit.wikimedia.org/r/1127608

Change #1127608 merged by jenkins-bot:

[mediawiki/core@master] REST: Make OpenAPI spec info strings translatable

https://gerrit.wikimedia.org/r/1127608

Change #1131459 had a related patch set uploaded (by BPirkle; author: BPirkle):

[mediawiki/core@master] REST: fix extra routes module localization strings

https://gerrit.wikimedia.org/r/1131459

Change #1131459 merged by jenkins-bot:

[mediawiki/core@master] REST: fix extra routes module localization strings

https://gerrit.wikimedia.org/r/1131459

Change #1131784 had a related patch set uploaded (by BPirkle; author: BPirkle):

[mediawiki/core@wmf/1.44.0-wmf.22] REST: fix extra routes module localization strings

https://gerrit.wikimedia.org/r/1131784

Change #1131784 merged by jenkins-bot:

[mediawiki/core@wmf/1.44.0-wmf.22] REST: fix extra routes module localization strings

https://gerrit.wikimedia.org/r/1131784

Mentioned in SAL (#wikimedia-operations) [2025-03-27T22:43:46Z] <thcipriani@deploy1003> Started scap sync-world: Backport for [[gerrit:1131784|REST: fix extra routes module localization strings (T385855)]]

Mentioned in SAL (#wikimedia-operations) [2025-03-27T22:48:23Z] <thcipriani@deploy1003> bpirkle, thcipriani: Backport for [[gerrit:1131784|REST: fix extra routes module localization strings (T385855)]] synced to the testservers (https://wikitech.wikimedia.org/wiki/Mwdebug)

Mentioned in SAL (#wikimedia-operations) [2025-03-27T22:57:52Z] <thcipriani@deploy1003> Finished scap sync-world: Backport for [[gerrit:1131784|REST: fix extra routes module localization strings (T385855)]] (duration: 14m 06s)