Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REST API: Add locale suggestion endpoint & helpers for plugins and themes #609

Merged
merged 6 commits into from
May 15, 2024

Conversation

ryelle
Copy link
Contributor

@ryelle ryelle commented May 13, 2024

See WordPress/wporg-theme-directory#52 — I've moved rest-api-locale.php to mu-plugins/helpers/locale.php, and the endpoint to rest-api/endpoints/. In fact, I've updated the code to handle both theme and plugin requests, so that all this locale-banner-related code can stay in one place (this isn't exactly what was requested on the other PR, but once I started building it out as two similar endpoints, it made sense to share a base class & live here).

The endpoints:

These can also be used from Rosetta URLs

The routes should only appear on the relevant sites, so you can't request wordpress.org/themes/wp-json/wporg-plugins/v1/locale-banner/.

This leaves open the possibility to add a patterns variation later, if we wanted to.

To test

Same instructions as WordPress/wporg-theme-directory#52

Try out various combinations of header locale (Accept-Language header), theme, rosetta origin site, etc. This needs a sandbox to test for the locale database.

You can also try with the try/mu-plugins-locale-api branch on wporg-theme-directory, which should show the banner if your browser is set up to send alternate language suggestions.

There is also a debug parameter you can add to the endpoints to show more information about the request. For example,

$ curl 'https://es.wordpress.org/themes/wp-json/wporg-themes/v1/locale-banner/?debug=1' -H 'Accept-Language: en,ko-KR,es-ES,fr,eo,it,ru'

{
	"currentLocale": "es_ES",
	"suggestions": [
		"ko_KR",
		"es_ES",
		"fr_FR",
		"eo",
		"it_IT",
		"ru_RU"
	],
	"message": "The theme directory is also available in <a href=\"https:\/\/ko.wordpress.org\/themes\/\">한국어<\/a>, <a href=\"https:\/\/fr.wordpress.org\/themes\/\">Français<\/a>, <a href=\"https:\/\/eo.wordpress.org\/themes\/\">Esperanto<\/a>, <a href=\"https:\/\/it.wordpress.org\/themes\/\">Italiano<\/a>, 그리고 <a href=\"https:\/\/ru.wordpress.org\/themes\/\">Русский<\/a>."
}

@ryelle ryelle self-assigned this May 13, 2024
@StevenDufresne
Copy link
Contributor

I've taken a look at the code and left some minor suggestions. I don't know how much is moved code versus new so I'll let you determine what needs to be updated in regards to that. Otherwise, I feel comfortable merging this.

@ryelle
Copy link
Contributor Author

ryelle commented May 14, 2024

I've made the requested updates and I think it's good to merge now, but I'll wait until tomorrow in case there's any more feedback or comment replies.

@ryelle ryelle merged commit c299529 into trunk May 15, 2024
2 checks passed
@ryelle ryelle deleted the add/language-suggest-api branch May 15, 2024 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants