Skip to content

About

Machine translation for block-based pages in plone.app.multilingual, in the background

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

collective.blockpagetranslator

Machine translation for block-based pages (Volto blocks) in a site that uses plone.app.multilingual.

When the page a translation is made from changes, its translations follow in the background: the blocks whose text changed are translated, for every language, and written back into each translation, field by field. plone.app.multilingual translates one field at a time while an editor waits; this translates whole pages, and keeps them translated.

How it works

  • The text to translate is each block's searchableText, written as HTML. An editor that knows the blocks' schemas writes it on save: each readable field is an element marked with data-field (its path within the block), and rich text keeps its inline markup. So this package needs no block schemas: it reads the HTML, and writes each translated piece back by its path.
  • Search reads the same value as text. Until plone.restapi passes a block's searchableText through an HTML-to-text transform itself, this package does, before the value reaches any index (the catalog or an external one such as Elasticsearch).
  • A fingerprint per block (a hash of its source HTML) says what changed since a translation was made. A result is written only if the source still has that fingerprint, so a job never overwrites an edit made while it ran. A block corrected by hand on a translation is marked for review rather than overwritten.
  • Translation is never inside the editor's save. After a save commits, the page is translated in the same request, every language at once, and the results written in one short transaction of their own; what isn't done in a few seconds is left for the sweep, an endpoint called on a schedule (Setup, below).
  • Translators are named utilities: plone.app.multilingual's IExternalTranslationService where it is available (Google, and the services collective.translators adds), and a pseudo-localising translator for trying a site in a language before paying for one.

Also

  • Turning an existing site into a multilingual one: plone.app.multilingual's setup with the site's languages, the content moved into the default language's folder and pages already in another language into theirs, and every item's language kept.

Setup

Install the profile (collective.blockpagetranslator:default) on the site. Its settings are in the site's registry:

  • collective.blockpagetranslator.translator: the translator, which turns machine translation on. stub marks each field [<language>] , to try a site in a language before paying for one. Empty: off.
  • collective.blockpagetranslator.machine_languages: the languages pages are machine-translated into, from the site's default language. A language not listed is translated by people, or not at all.

Translation happens in the web servers, with no background queue:

  • On save. Once a save of a page in the site's default language commits, the page is translated in the same request: every machine language at once, each in one call to the translator, the results written in one short transaction of their own. The request waits at most a few seconds; a translator that fails or is slow never fails the save, and what isn't done is left stale for the sweep.
  • The sweep. A timer in each web server translates stale pages, one at a time, every BLOCKPAGETRANSLATOR_SWEEP_SECONDS. A claim on the site keeps it to one web server at a time; a page changed in the last 30 seconds is left to its save. translate-all <zope.conf> <site path> runs the same sweep from a shell, to fill a new language.

Set BLOCKPAGETRANSLATOR_SWEEP_SECONDS on the web server's start command only, never in the app's environment: the release, an import and every zconsole script start Zope too. In a process without it, nothing is translated on save either: a script's saves are left to the web servers' timers.

Writes happen one at a time on purpose: every page's write touches the catalog's shared indexes, so writers side by side conflict. A write that meets a conflict runs again after a short random wait.

Trying it locally

make dev-instance, make dev-run, make dev-check, make dev-stop: two web servers on one database (ZEO) with an English and French site, checked end to end (the timers, saves on both servers at once, sweeps never side by side). See dev/check.py.

Machine and manual translations

Translation starts from a page in the site's default language. A translation it makes is marked machine, and only machine translations are written to:

  • a translation a person made is manual, and never written to;
  • an editor can take a machine translation over (it becomes manual), and hand it back (every block is translated afresh), or hand back one block they corrected;
  • a block an editor corrected in a machine translation is kept, and flagged for review.

@machine-translation on any page of a translation group answers each language's status (machine, manual or missing; the blocks to review; whether machine translation has changes to make), and takes a POST {"action": "take-over" | "hand-back" | "hand-back-block", "language": …, "block": …}.

Status

Under development: nothing here is released yet.

About

Machine translation for block-based pages in plone.app.multilingual, in the background

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages