Project

rhoella

0.0
There's a lot of open issues
Rhoella — from the Greek rhoia, the flow — the localization engine for normative publishing: a Fluent (FTL) engine (messages, placeables, a function registry, isolation, bounded resolution) plus the sealed locale layer for standards rendering — CLDR spellout/ordinals/calendar symbols/list patterns/plural categories via the optional rhoella-cldr gem, and the number profile system: the audited Metanorma number formatting vocabulary (ISO/IEC Directives, SI Brochure, ITU) as declarative YAML profiles rendered by ONE Rust core, bound natively for every runtime (rhoella#31) with byte-identity across languages as publication integrity. Ships CODE only: data is the OPTIONAL rhoella-cldr / rhoella-dictionaries gems, resolved by explicit path, installed gem, or environment.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Runtime

 Project Readme

rhoella

Rhoella — a minimal Fluent (FTL) engine for Metanorma.

From the Greek ῥοία (rhoia, flow, stream): the ideal of fluency in its oldest root — a stream of well-formed labels. Single implementation semantic, four runtimes:

  • reference/ruby — the Ruby reference; the arbiter that generates the conformance vectors, and the published rhoella gem
  • sibling libraries, each vendoring this testsuite at a pinned ref and running their own parity + conformance CI: rhoella/rhoella-py (Python), rhoella/rhoella-rs (Rust), rhoella/rhoella-ts (TypeScript, wasm-deployable pure core)

Supported syntax (the Fluent subset Metanorma needs)

  • messages id = pattern; ids [A-Za-z][A-Za-z0-9_-]*; terms carry a leading -; message attributes id.attr = pattern (indented .attr = value lines)
  • multiline patterns: indented continuation lines, common indent stripped, lines joined with "\n"
  • placeables: { $var }, message references { id }, member references { id.attr }, term references { -term } with named parameters { -term(key: $v) }, term member references { -term.attr }, function references { FN($v) } (uppercase callee, arguments may nest calls and member references), selectors { expr -> [key] pattern ... *[other] pattern } with a mandatory default arm
  • string literals {"text"} with \", \\, \uXXXX and \UXXXXXX escapes, decoded as UTF-16 code units (surrogate pairs may straddle adjacent literals); text has no escape sequences — backslash is literal, per the Fluent grammar

The function registry

Functions resolve through a per-bundle registry — the resolver has no hard-coded builtins. A bundle starts with the default registry, which carries:

  • NUMBER — fluent NUMBER semantics for the default locale: three-digit grouping, half-up rounding to maximumFractionDigits (default 3), zero-padding to minimumFractionDigits and minimumIntegerDigits, useGrouping: "false" to disable separators; decimal-string math, no Float artifacts
  • SPELLOUT — RBNF-backed number spelling over the sealed CLDR package: { SPELLOUT($n, locale: "ja", ruleset: "spellout-cardinal") }; the ruleset defaults to the locale's citation cardinal (the artifact's role — masculine/sinokorean where CLDR genders the forms)
  • ORDINAL — the spellout-ordinal surface (1st → "first", ja "第…"), defaulting to the locale's citation ordinal role
  • LIST — the fluent list-conjunction builtin over the baked CLDR listPatterns: { LIST($items, conj: "and"/"or"/"unit") } joins already-localized items with the locale's start/middle/end/"2" pairs; array variables render ", "-joined (fluent semantics), and a locale the package lacks falls back to the bare ", " join

Hosts add their own with bundle.register(name, callable); the callable receives the rendered positional arguments and named options (strings) and returns the rendered string, raising Rhoella::FunctionError for invalid arguments (rendered as the FN() argument-error fallback). An unregistered name renders the {FN()} unknown-function fallback, per upstream.

The sealed CLDR package (the optional rhoella-cldr data gem)

The locale data is a sealed package baked offline from unicode-org/cldr-json at a pinned release (CLDR 49 as shipped — the pin is the CLDR_RELEASE constant in tools/bake_cldr.rb, env-overridable for the owner's final call): plural rule strings, gregorian calendar symbols, RBNF spellout/ordinal rule sets and list patterns for en, ja, zh, zh-Hant, fr, de, es, ru, ar, ko, it, pt. The bake writes manifest.json with a sha256 per artifact — the seal — and every engine read is lazy and checksum-verified against it; a corrupted package raises Rhoella::CldrError instead of serving wrong locale data. Renders NEVER generate data: the artifacts are committed, CI verifies the seal (ruby tools/verify_cldr.rb), and re-baking is a deliberate, release-pinned act. The twitter_cldr equivalence sweep (ruby tools/verify_cldr.rb --twitter, local — twitter_cldr is not a dependency) pins the retirement evidence: en/ja/zh spellout, ordinals, calendars and plurals byte-identical against twitter_cldr 6.14.

The engine ships CODE only (the owner's architecture decision, #24): the data is the OPTIONAL rhoella/rhoella-cldr package. The loader resolves it in a fixed order:

  1. the explicit path (Rhoella::Cldr.data_path = dir),
  2. the installed rhoella-cldr gem (lazy require "rhoella/cldr/data" — silently skipped when absent, then Rhoella::Cldr::Data::PATH),
  3. ENV["RHOELLA_CLDR_DATA"],
  4. otherwise the locale functions raise Rhoella::CldrError naming the remedy: install the rhoella-cldr gem (or set RHOELLA_CLDR_DATA, or pass Rhoella::Cldr.data_path = ...).

Install both when the locale surfaces are needed:

gem "rhoella"
gem "rhoella-cldr"

Pattern resolution without the locale surfaces — messages, variables, NUMBER, exact-string selects — never reads the package. The monorepo's committed vendor/cldr/ remains the dev/test fixture (the sealed bytes); CI diffs it against the published rhoella-cldr tag so the fixture and the package can never drift.

The engine API (Kaleidl-style module functions): Rhoella.spellout(n, locale:, ruleset:), Rhoella.ordinal(n, locale:, ruleset:), Rhoella.calendar_symbols(locale), Rhoella.plural_category(n, locale:, type:) and Rhoella.list(items, locale:, conj:, style:). Rule syntax the RBNF evaluator does not implement raises Rhoella::Rbnf::UnsupportedRuleError — the evaluator renders the baked rule shapes (base values, <</>>, ruleset references, decimal formats, [optional] and the TR35 [left|right] alternative, $(cardinal,…)$ agreement; integers) and fails loudly on anything else, never silently wrong.

Selectors, plurals and isolation

  • selector matching is exact string equality first; a numeric selector value with no exact match falls back to the CLDR plural category for the bundle locale ([one]/[other]-style keys). The plural rules are the compact CLDR rule strings, package-fed from the sealed data (no ICU dependency; Rhoella::PluralRules, cardinal + ordinal tables, RULES as the locale-keyed override table)
  • isolation is on by default, like fluent.js and fluent-rs (Bundle.new(use_isolating: false) to switch off): a placeable in a multi-element pattern is wrapped in U+2068/U+2069 — except bare message references, bare term references and string literals, per the fluent-rs rule

The number config (the one number surface the engine keeps)

Numbers render in plurimath — the STEM algorithm (radix conversion, hex capitalization, padding, digit budgets, notation coefficients) is plurimath's, and so are the publication conventions (ISO 80000-1, ITU, SI Brochure) as plurimath data. rhoella owns the l10n number config: what CLDR says about a locale, handed to the renderer.

Rhoella.number_format("hi")
#=> { "cldr_release" => "49.0.0", "locale" => "hi",
#     "default_numbering_system" => "latn",
#     "symbols" => { "decimal" => ".", "group" => ",", "plusSign" => "+",
#                    "minusSign" => "-", "percentSign" => "%" },
#     "minimum_grouping_digits" => 1,
#     "patterns" => { "decimal" => "#,##,##0.###" },
#     "grouping" => { "primary" => 3, "secondary" => 2 } }

Rhoella.number_symbols("de")
#=> the raw sealed record: the symbols, "minimum_grouping_digits" ("1"),
#    "decimal_pattern" ("#,##0.###") — unchanged (rhoella#25)

grouping is read off the decimal pattern — primary is the rightmost group, secondary the fixed size before it (hi/en-IN 3 / 2; null everywhere else) — and minimum_grouping_digits is the CLDR rule that keeps four-digit numbers ungrouped in es/it/pl/… (2). Locales the package lacks resolve to nil through the subtag ladder, like every other locale function; the data is the optional rhoella-cldr gem.

Deprecated: the number-profile renderer (#36)

Rhoella.render_number, Rhoella::Profiles (resolve, data_path=, data_dir) and the napi/Python equivalents are deprecated and removed in a later release: they implement a second number renderer that has no customer — the publication conventions they carried live in plurimath now (plurimath#657) and the rhoella-dictionaries package is deprecated. Every entry point warns; docs/number-profiles/SPEC.md stays for the deprecation cycle only.

Fluent semantics preserved

  • a missing variable renders as {$name}
  • a reference to an unknown message or attribute renders the literal source {id} / {id.attr}; a function call resolves through the bundle's registry, and an unregistered name renders {FN()} (name only, per upstream)
  • a direct format of a message with no value returns nil — the null value, like fluent.js and fluent-rs (the ruling is recorded in tools/run_behavior.rb); unknown messages, unknown attributes and resolution errors still raise
  • term parameters bind as variables inside the term; outer variables are NOT inherited into term resolution — only the call arguments are
  • cyclic references fall back to their source form and resolution continues; the number of placeable resolutions per format is bounded (ResolutionError); there is no depth cap — deep acyclic chains resolve
  • a selector without a default arm is a parse error

Contract

testsuite/ holds the conformance layers: upstream/ (the cross-implementation parser fixtures of the Fluent spec, classified in manifest.json, and the fluent-rs resolution fixtures under upstream/behavior/, run by tools/run_behavior.rb — every skip carries a class, and the summary prints per-class counts: whole-suite (bomb, context, transform, with named reasons) plus the upstream fixture skip flags) and semantics/ (resolution vectors: FTL resources plus the expected resolutions generated by the Ruby reference, tools/gen_vectors.rb, at the engine defaults — isolation on, en plurals, the default function registry). Every runtime must reproduce the parse classification and every resolution vector exactly. Each runtime runs both layers in CI.

Regenerating the vectors after an intentional semantic change:

ruby tools/gen_vectors.rb

Runtimes

ruby -I reference/ruby -e 'require "rhoella"; puts Rhoella::Bundle.new.add_resource(File.read("testsuite/semantics/resources/core.ftl")).format("hello", "name" => "TSE")'
# and in the sibling repositories:
#   rhoella-py: python3 test_parity.py
#   rhoella-rs: cargo test
#   rhoella-ts: npm test