backdrop-ops / localize.backdropcms.org

Host translation files for Backdrop CMS.
2 stars 4 forks source link

Provide an endpoint to serve a list of available languages #51

Open docwilmot opened 1 month ago

docwilmot commented 1 month ago

Working on https://github.com/backdrop/backdrop/pull/4834 to allow sites to download language files automatically during installing Backdrop, it would be great for those sites to query localize.backdropcms.org to get a list of all available translations, so we could build a select list for the user to choose from.

We've noted that there doesn't seem to exist any method to determine this remotely. It would be great if we could provide an endpoint with just that.

For now we would either have to list every available language during installs, and throw an error if the user chooses a language that isn't yet translated (poor UX), or, as the latest PR chose to do, manually list the available translations (27 of them as of today) and plan to update the list with every Backdrop release (poor DX).

argiepiano commented 1 month ago

@docwilmot this should be easy to provide by adding a menu item to l10n_community and using l10n_community_get_languages(). Would you like this served as a json response?

docwilmot commented 1 month ago

JSON should be fine I suppose. We use JSON for other endpoints in Backdrop so go with that.

argiepiano commented 1 month ago

@docwilmot I've made a new release of l10n_server that contains the end point. Very simple: just request /translate/available-languages and you'll get a json string of available languages in this format, or [] if none.

{
  "es": {
    "langcode": "es",
    "name": "Spanish",
    "direction": 0,
    "native": "Español",
    "enabled": true,
    "weight": 0,
    "default": false
  },
  "fr": {
    "langcode": "fr",
    "name": "French",
    "direction": 0,
    "native": "Français",
    "enabled": true,
    "weight": 0,
    "default": false
  }
}

Now, someone needs to update localize.backdropcms.org with the latest release (also with the latest core). Pinging @jenlampton to see if she can do that. I did this last year, but it's a complex process and I'm a bit short on time (plus I don't want to mess up).

klonos commented 1 month ago

Thank you for the very prompt turnaround @argiepiano 🙏🏼 ❤️

If not @jenlampton, then perhaps @bugfolder(?) can help with updating the module on the site and making sure that the endpoint is publicly accessible.

bugfolder commented 1 month ago

I'll update the other *.b.org sites in the next few days (currently traveling, so don't know my exact time availability, but I'm sure I can find an appropriate chunk of time in the next few days). I just turned on Update Manager on localize.b.org, so that should turn up modules that have new versions (which I'll also update).

argiepiano commented 1 month ago

Another new release of l10n_server. I fixed an issue that was generating tons of warnings in the localize site, mostly because bot crawlers were trying to access the history of translations with invalid translation IDs.

docwilmot commented 1 month ago

@argiepiano @bugfolder I think things should be working, but https://localize.backdropcms.org/translate/available-languages doesnt give the expected response.

bugfolder commented 1 month ago

Pro tip: enabling a module usually enhances its performance. 😉 Better?

docwilmot commented 1 month ago

Pro tip: enabling a module usually enhances its performance. 😉 Better?

I'm learning so much today. 🙂

bugfolder commented 1 month ago

Watching the testing going on at https://github.com/backdrop/backdrop-issues/issues/6660, it looks like this is now doing its proper thing. OK to close?