Metadata-Version: 2.5
Name: trytond_etude_i18n
Version: 8.0.0.1
Summary: Etude Form Server — Multilingual Labels, Options and Help Text
Author: Clemens Hupka
Maintainer-email: Clemens Hupka <clemens.hupka@backend.at>
License-Expression: GPL-3.0-or-later
License-File: COPYRIGHT
License-File: LICENSE
Keywords: form,i18n,language,survey,translation,tryton
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: Environment :: Plugins
Classifier: Framework :: Tryton
Classifier: Topic :: Office/Business
Requires-Python: >=3.10
Requires-Dist: trytond-etude<8.1,>=8.0
Requires-Dist: trytond<8.1,>=8.0
Provides-Extra: test
Requires-Dist: trytond-etude-collect<8.1,>=8.0; extra == 'test'
Description-Content-Type: text/x-rst

Etude I18n Module
=================

The ``etude_i18n`` module serves one form in several languages: the labels of
its pages, its groups, its questions and its options, the help text beside a
question and the name, the description and the menu label of the form itself
are written per language, and the language a request is served in is resolved
when the form is served rather than declared by the form.

It is a companion of the definition of a form - it depends on ``etude`` and
extends it - and it captures the language a response is answered in on
``etude.response`` when ``etude_collect`` is installed beside it, so a
deployment which translates its forms without storing responses serves them in
the language of a participant and captures nothing.

What is written per language
----------------------------

A translation is a row of ``etude.translation``: the form it belongs to, the
language it is written in, the element it is about, the field of that element
and the text.  The element is named by a reference - a form, a page, a group, a
question or an option of that form - because a translation is written beside
the definition it translates and a designer picks the question it belongs to,
and the field is checked against the element: a page and a group carry a name,
a question a label and a help text, an option the label it is offered under and
a form its own identity.

The value an option stores is deliberately not translatable.  It is what an
answer of a choice is stored as and what the logic, the assessment and the
bindings of a form read, so translating it would change the answer of a
participant rather than what the participant reads.

The language a form is served in
--------------------------------

The language of a request is resolved by a deterministic fallback: the language
of the participant who answers - the ``res.user`` a portal account or an API
token acts as - then the locale a caller resolved for itself, then the
languages an ``Accept-Language`` header asks for, best first, then the language
the form declares as its own (``etude.form.default_language``), then the
language of the deployment, and finally the language of the deployment which
reads first.

A candidate the deployment does not hold is skipped rather than guessed at, and
a code which carries a territory falls back to the language it belongs to, so a
browser which asks for ``de_AT`` is served ``de`` where the deployment holds no
Austrian German of its own.  A form which declares a language of its own is
served in it whatever the deployment runs in, because a form is translated from
the language it was authored in.

A missing translation falls back to the label of the definition and never to
the translation of another language: a definition payload is read in the
language it is asked for, and a field no translation of that language holds is
left exactly as the definition wrote it.

The translation a version freezes
---------------------------------

The language of a form and its translations are part of its definition, so
editing either opens the draft version of a published form.  A translation is
frozen addressed by its path in the definition - the rank of a page, the rank
of a group, the code of a question and the code of an option - because the rows
of a definition are recreated by a restore and a rank and a code are what stay;
restoring a version writes the translations back with the pages of the form.

A response is therefore rendered in the language it was answered in against the
definition it pinned: the language is captured on ``etude.response`` when the
response is created, and ``Response.get_rendered_definition`` reads the payload
of the pinned version with the translations of that version.  A translation
edited after the version was published changes the version being prepared
rather than the one a participant already answered.

What the form server serves
---------------------------

The REST API and the server-rendered pages of the group read the localisation
through the pool rather than depend on it.  ``etude_api`` fetches the
definition of a form in the language a request asks for and passes the resolved
language to the response it starts, and ``etude_web`` renders a page, submits
it and captures the language of the participant in the same resolution.  A
deployment which installs ``etude_i18n`` gets the translations of its forms,
and one which does not serves the definitions it holds and resolves the
language of a response exactly as it did before.

See ``doc/index.rst`` for the module documentation and ``ETUDE.md`` in
``modules-cch/`` for the architecture of the whole group.
