From 5853559d8e96cecc363e6f65100de7dd4192439e Mon Sep 17 00:00:00 2001 From: Eemeli Aro Date: Mon, 8 Jul 2024 15:28:33 +0300 Subject: [PATCH 1/3] Add exploration/registry-xml/ --- exploration/registry-xml/README.md | 931 ++++++++++++++++++ .../registry-xml}/registry.dtd | 6 +- .../registry-xml}/registry.xml | 9 +- spec/README.md | 1 - 4 files changed, 936 insertions(+), 11 deletions(-) create mode 100644 exploration/registry-xml/README.md rename {spec => exploration/registry-xml}/registry.dtd (93%) rename {spec => exploration/registry-xml}/registry.xml (98%) diff --git a/exploration/registry-xml/README.md b/exploration/registry-xml/README.md new file mode 100644 index 000000000..9772ce637 --- /dev/null +++ b/exploration/registry-xml/README.md @@ -0,0 +1,931 @@ +# MessageFormat 2.0 Registry + +Implementations and tooling can greatly benefit from a +structured definition of formatting and matching functions available to messages at runtime. +This specification is intended to provide a mechanism for storing such declarations in a portable manner. + +## Goals + +_This section is non-normative._ + +The registry provides a description of MessageFormat 2 functions, +in order to support the following goals and use-cases: + +- Validate semantic properties of messages. For example: + - Type-check values passed into functions. + - Validate that matching functions are only called in selectors. + - Validate that formatting functions are only called in placeholders. + - Verify the exhaustiveness of variant keys given a selector. +- Support the localization roundtrip. For example: + - Generate variant keys for a given locale during XLIFF extraction. +- Improve the authoring experience. For example: + - Forbid edits to certain function options (e.g. currency options). + - Autocomplete function and option names. + - Display on-hover tooltips for function signatures with documentation. + - Display/edit known message metadata. + - Restrict input in GUI by providing a dropdown with all viable option values. + +## Conformance and Use + +_This section is normative._ + +To be conformant with MessageFormat 2.0, an implementation MUST implement +the _functions_, _options_ and _option_ values, _operands_ and outputs +described in the section [Default Registry](#default-registry) below. + +Implementations MAY implement additional _functions_ or additional _options_. +In particular, implementations are encouraged to provide feedback on proposed +_options_ and their values. + +> [!IMPORTANT] +> In the Tech Preview, the [registry data model](#registry-data-model) should +> be regarded as experimental. +> Changes to the format are expected during this period. +> Feedback on the registry's format and implementation is encouraged! + +Implementations are not required to provide a machine-readable registry +nor to read or interpret the registry data model in order to be conformant. + +The MessageFormat 2.0 Registry was created to describe +the core set of formatting and selection _functions_, +including _operands_, _options_, and _option_ values. +This is the minimum set of functionality needed for conformance. +By using the same names and values, _messages_ can be used interchangeably +by different implementations, +regardless of programming language or runtime environment. +This ensures that developers do not have to relearn core MessageFormat syntax +and functionality when moving between platforms +and that translators do not need to know about the runtime environment for most +selection or formatting operations. + +The registry provides a machine-readable description of _functions_ +suitable for tools, such as those used in translation automation, so that +variant expansion and information about available _options_ and their effects +are available in the translation ecosystem. +To that end, implementations are strongly encouraged to provide appropriately +tailored versions of the registry for consumption by tools +(even if not included in software distributions) +and to encourage any add-on or plug-in functionality to provide +a registry to support localization tooling. + +## Registry Data Model + +_This section is non-normative._ + +> [!IMPORTANT] +> This part of the specification is not part of the Tech Preview. + +MessageFormat 2 functions can be invoked in two contexts: + +- inside placeholders, to produce a part of the message's formatted output; + for example, a raw value of `|1.5|` may be formatted to `1,5` in a language which uses commas as decimal separators, +- inside selectors, to contribute to selecting the appropriate variant among all given variants. + +A single _function name_ may be used in both contexts, +regardless of whether it's implemented as one or multiple functions. + +A _signature_ defines one particular set of at most one argument and any number of named options +that can be used together in a single call to the function. +`` corresponds to a function call inside a placeholder inside translatable text. +`` corresponds to a function call inside a selector. + +A signature may define the positional argument of the function with the `` element. +If the `` element is not present, the function is defined as a nullary function. +A signature may also define one or more `