[SOLVED] [plone.restapi] Endpoint for message catalogs?

Is there an endpoint in plone.restapi ( or as an extension) for fetching data from the message catalogs aka locales aka .po files?

Short answer: no.

plone.restapi uses locales to localize the serialized responses. A frontend (like Volto) usually has its own localization. May I ask what your use case for this is?

The question is basically where you want to maintain translations, in particular for a multi-lingual UI - in the frontend or in the backend. Side question: do I need to involve the frontend team for making textual changes or can I do them (as a project manager) directly myself. So I want to maintain the translations for most case in the backend.

The answer for Volto is that you need translation both in the frontend and the backend. It would be way too much work and way too many requests (or caching magic) to just keep all translations in the backend.

Volto has a locales directory with po files that is similar to the Plone backend, so you can just edit them as you can edit the backend translations.

Not sure if I fully get your questions though. :slight_smile:

I solved it partly this way:

Frontend:

i18n/project.js

 /* i18n integration.
 * Copy from https://github.com/plone/mockup/blob/es6/src/core/i18n-wrapper.js
 * And changed i18n catalog/MessageFactory
 */

import I18N from '++resource++mockupjs/i18n';

let _t = null;
const translate = function (msgid, keywords) {
    if (_t === null) {
        var i18n = new I18N();
        i18n.loadCatalog("namespace.Projekte");
        _t = i18n.MessageFactory("namespace.Projekte");
    }
    return _t(msgid, keywords);
};

export default translate;

And in the js files i do

import _t from "../../i18n/project"
...
  <h4>{_t("favorites_headline")}</h4>
...

It fetches this URL https://www.domain.de/plonejsi18n?domain=namespace.Projekte&language=de and saves it into localstorage. The rest is vanilla translation machinery from plone.

Only problem: On a cold client it needs a full load to populate the localstorage cache, so there are situations where the js translations are not there or up-to-date. Maybe @thet or @MrTango can help?

1 Like

Using /plonejsi18n?domain=my.policy is what I looking for.