What it does
- Cardinal and ordinal plurals for the 227 CLDR locales
- 21 built-in locales, the rest on demand (<code>.etlloc</code>)
- Numbers, currencies, percentages, dates, lists, relative time, sizes, durations
- MessageFormat (plural, select, selectordinal, number, date)
- Mapped catalogs (<code>.etlcat</code>) with a fallback chain that never returns empty
- <code>etl-i18n</code>: extract, header, compile, check, pseudo, stats
Measured
- Message lookup: 1.5 to 1.6 ns on GCC 15.2 and 1.4 to 2.6 ns on MSVC (target 5 ns)
- Opening a 10,000-message catalog (631 KB): 0.046 ms on GCC and 0.28 to 0.33 ms on MSVC (target 1 ms)
- Plurals: 12,544 cardinal and 2,687 ordinal CLDR samples, 0 errors
- Whole module on GCC <code>-O2</code>: 139.5 KB (target 150 KB)
Known limits
- gettext <code>msgid_plural</code> is not supported
- No time zone names (GMT with the offset is printed)
The module that makes a product speak more than one language: the plural rules of every CLDR locale, the formatting of numbers, currencies, dates, lists, relative time, sizes and durations from CLDR data, messages in ICU MessageFormat syntax (the one translation platforms know) and the compiled catalogs that the etl-i18n tool produces from PO or TOML.
#include <ethereal/cpp/i18n/i18n_inc.hpp>
#include "messages_ids.h" // generated: etl-i18n header
using namespace Ethereal::I18n;
CCatalog Pedido, Origem;
CCatalog::Open( "locales/pt-BR.etlcat", &Pedido ); // mapped, checked, not read
CCatalog::Open( "locales/en.etlcat", &Origem );
CMessages M;
M.SetCatalogs( &Pedido, nullptr, &Origem ); // requested -> base -> source -> the key
CLocale L;
CLocale::Find( "pt-BR", &L );
M.SetLocale( L );
char b[ 256 ];
std::size_t n = 0;
const SArg aArgs[] = { SArg( "folder", "Documentos" ) };
M.Plural( ETL_TR( FILES, "{count, plural, one {# file} other {# files}} in {folder}" ), 1000000, b, &n, aArgs );
// "1.000.000 de ficheiros em Documentos"The CLDR version is 48.2 (third_party/cldr/48.2), and everything that comes from it is generated by tools/i18n_gen/gen_i18n.py, never written by hand.
---
What there is
| Piece | Header | What |
|---|---|---|
| Plurals | i18n_plural.hpp | CPluralRules: cardinals and ordinals for 227 CLDR locales, compiled into C++ functions (40 distinct cardinal rules and 25 distinct ordinal rules), for integers and for written numbers ("1.50", "1.2c6") |
| Locales | i18n_locale.hpp | CLocale: the formatting data of 21 bundled locales, with CLDR fallback (en-AU → en-001, es-MX → es-419, zh-TW → zh-Hant, pt-BR → pt). CLocaleData: the data of any other CLDR locale, from an .etlloc, on demand |
| Formatting | i18n_format.hpp | numbers (grouping, including the Indian lakh/crore and minimum grouping), percentages, currencies (symbol, code, position, spacing, digits per currency: JPY 0, KWD 3, USD/BRL 2), file sizes, durations, dates and times (the four lengths, eras, 12/24 h, day periods, GMT formats), hand-written date patterns, relative time, lists (and, or, units) |
| Messages | i18n_message.hpp | FormatMessageText (MessageFormat), InspectMessage (the placeholders, for validation), PseudoLocalize. CCatalog (the mapped .etlcat). CMessages (the fallback chain, the missing-message hook). ETL_TR |
| Tool | etl-i18n | extract, header, compile, check, pseudo, stats |
Every function that writes text writes into a caller's std::span<char> and reports the full size in *pWritten (eBufferTooSmall if it did not fit): nothing is allocated when formatting, looking up or opening. The two exceptions allocate and say so in their name: CMessages::FormatToString and BuildCatalog.
---
Messages
The syntax is a subset of ICU MessageFormat:
| Form | Example | |||
|---|---|---|---|---|
| named placeholder | {count} ficheiros em {folder}. The translator changes the order at will | |||
| plural | {n, plural, =0 {nenhum} one {# ficheiro} many {# de ficheiros} other {# ficheiros}} | |||
| offset | {n, plural, offset:1 =0 {ninguém} =1 {{quem}} one {{quem} e # outro} other {{quem} e # outros}} | |||
| ordinal | {n, selectordinal, one {#st} two {#nd} few {#rd} other {#th}} | |||
| select | {g, select, male {ele} female {ela} other {elu}} | |||
| number | {x, number}, {x, number, integer}, {x, number, percent} | |||
| date and time | `{d, date, short\ | medium\ | long\ | full}, {d, time, …}` |
| quotes | '' is a quote. '{…}' is text. A quote anywhere else is a quote |
The exact =N compares the value without the offset. The category and # use the value minus the offset, as in ICU. A missing argument is written visibly ({name}), never as empty. Nested messages have a limit of 16 levels.
The fallback (CMessages): the catalog of the requested locale, then that of the base language (pt-BR → pt), then that of the source language, and finally the key itself. An id that does not exist gives "?". Never an empty text: an empty text in a catalog is an untranslated message, as in gettext. Each fallback goes through the hook (SetMissingHook), so the missing messages show up in CI. The key and the locale the hook receives can be empty, but never a null pointer (since 2026-10-16). A translation that cannot be read (check should have blocked it) falls through to the next one.
Pseudolocalization (PseudoLocalize, etl-i18n pseudo): accents on the ASCII letters (Save → [Šávé~~]), the text 40% longer and in brackets, with placeholders and syntax intact. The test plants a layout error (a 12-column button where English fits) and pseudolocalization finds it.
---
The compiled catalog (.etlcat)
A 64-byte header (magic, version, message count, the hash of the source keys, the locale tag, the plural rules it was compiled with), a dense index (id → text, key) and the texts in UTF-8. Opening is mapping and checking: all offsets fit in the blob and the key table points to messages. After that, Get(id) is an index into a vector, inline. Find(key) is the slow path (a hash table in the catalog itself). Closing (or opening another one in the same object) unmaps: only the active locale stays resident, and the address becomes free again (the test checks this on Windows with VirtualQuery and on Linux in /proc/self/maps, and deletes the file afterwards).
An application's catalogs share the SourceHash and the message count. SetCatalogs rejects a mix (eBadCatalog). The header that etl-i18n header generates has kSourceHash and kCount, so the application can check the catalog it loaded.
The format is described in src/cpp/i18n/catalog.cpp.
---
The etl-i18n tool
etl-i18n extract --src src/ --out messages.pot # ETL_TR( ID, "text" ) in the code
etl-i18n header --in messages.pot --out messages_ids.h [--namespace EtlMsg]
etl-i18n compile --in pt-BR.po --base messages.pot --out pt-BR.etlcat [--locale pt-BR]
etl-i18n compile --in messages.pot --locale en --out en.etlcat # the source language
etl-i18n check --base en.po --translations locales/ # the CI gate
etl-i18n pseudo --in en.po --out pseudo.etlcat [--locale en-XA]
etl-i18n stats --base en.po --translations locales/It exits with 0 (success), 1 (defects) or 2 (usage, I/O). Defects are printed as file:line: error: KEY: detail [class] (warning instead of error for a warning). The messages and the class names are in English since the style conversion (phase 2), and the fixture folders keep their old names.
In PO, each message's id goes in msgctxt and the source text in msgid (that is what extract writes and what translation platforms display). Without msgctxt, the msgid itself is the key. An empty msgstr, or a fuzzy entry, is an untranslated message. File names with spaces in the references go between U+2068 and U+2069, as in gettext 0.22. In TOML, locale = "pt-BR" at the top and the messages in the [messages] table, with the four TOML string forms.
The ids are the keys sorted by bytes: the same in every translation compiled with the same base, and an id that the header does not have is a compile error (ETL_TR( SAVE_BUTON, … ) does not compile).
**What check finds**, one class per fixture (tests/i18n_fixtures/defects/<classe>/, the folder is named after the class), each one producing exactly its own defect and no other:
| Class | What |
|---|---|
missing-key | a base key that the translation does not have |
extra-key | a translation key that the base does not have |
duplicate-key | the same key twice in one file |
missing-placeholder | {name} in the base, but not in the translation |
extra-placeholder | {x} in the translation, but not in the base |
retyped-placeholder | {d, date} in the base, {d, number} in the translation (a plain {n} in place of a number or plural is accepted: it is formatted as a number) |
malformed-message | the MessageFormat syntax, with the byte |
incomplete-plural | a branch is missing for a category the locale uses (Polish needs few and many) |
unused-plural-branch | warning, which does not fail: a branch for a category the locale never selects |
file-syntax | badly written PO or TOML |
unsupported-format | msgid_plural (see the deviations), a TOML table that is not [messages] |
invalid-locale | a language tag that cannot be parsed |
compile runs the same checks and writes nothing if there are errors: a translation with a lost placeholder fails the build.
---
Locales
The plural rules come for all 227 CLDR locales. The formatting data comes for 21, selected:
| Locale | Alone (bytes) | Added (bytes) | Keys without a value |
|---|---|---|---|
en | 2,769 | 1,681 | 114 |
en-001 | 2,774 | 1,620 | 114 |
en-GB | 2,762 | 1,620 | 114 |
en-IN | 2,782 | 1,620 | 114 |
pt | 2,811 | 1,863 | 130 |
pt-PT | 2,901 | 1,755 | 130 |
es | 2,926 | 1,659 | 131 |
es-419 | 2,956 | 1,650 | 130 |
fr | 2,856 | 2,611 | 121 |
de | 2,796 | 2,526 | 124 |
it | 2,807 | 2,429 | 130 |
nl | 2,767 | 2,466 | 128 |
pl | 3,282 | 2,995 | 86 |
ru | 3,992 | 3,814 | 67 |
tr | 2,580 | 2,344 | 125 |
ar | 4,145 | 4,010 | 12 |
hi | 3,431 | 3,183 | 127 |
ja | 2,436 | 2,093 | 150 |
ko | 2,414 | 2,271 | 150 |
zh | 2,503 | 2,024 | 150 |
zh-Hant | 2,471 | 1,966 | 146 |
Alone is what the locale would cost if it came by itself (the 405 handles of 4 bytes and their texts). Added is what it adds to the set (the handles and the texts no other locale uses). The 405 keys include the six plural forms of each unit. The "without a value" ones are mostly the forms the language does not have (English has no few) and they fall back to other.
Other locales, on demand. tools/i18n_gen/gen_i18n.py --etlloc de_CH de-CH.etlloc writes the data of any CLDR locale (2.4 to 4.2 KB) into a file that CLocaleData::Open maps at run time, without rebuilding the library. The CLocale that comes out of it formats exactly like a bundled one (the test generates pt this way and compares everything with the bundled one). The file carries the hash of the key list: data generated for another version of the library is rejected. To add a locale to the bundled ones, put its name in the generator's LOCALES list and run the generator again.
The size
| What | Bytes |
|---|---|
| the data of the 21 locales (the 17,645-byte pool without duplicates + 21 × 1,620 of handles) | 51,665 (50.5 KB) |
the whole module on GCC 15.2, -O2 (code + data, size: .text + .data of the 8 objects) | 142,839 (139.5 KB) |
… of which locale.cpp (the data + the fallback) | 58,444 |
… number.cpp / date.cpp / plural.cpp (227 locales) / message.cpp / catalog.cpp / list.cpp | 22,052 / 15,075 / 19,130 / 13,529 / 9,711 / 4,898 |
The spec target (less than 150 KB for the default set) is met for the data (50.5 KB) and for the whole module (139.5 KB).
---
Performance
| Measurement | GCC 15.2 (WSL) | MSVC | Target |
|---|---|---|---|
CMessages::Get(id), the everyday path | 1.5 to 1.6 ns | 1.4 to 2.6 ns | < 5 ns ✅ |
| opening a catalog of 10,000 messages (631 KB), the best of 50 | 0.046 ms | 0.28 to 0.33 ms | < 1 ms ✅ |
| allocations when looking up, formatting, opening and closing | 0 | 0 | 0 ✅ |
Opening on Windows costs more (the section and the mapping view) and stays below the target. Get(id) is inline: a comparison with the message count, two index reads and the read of the text.
---
How it was tested
| Test | What |
|---|---|
i18n.plural | the rules against the CLDR's own samples (@integer and @decimal of each rule, in plurals.xml and ordinals.xml, read by a reader independent of the generator), in each locale of each rule: 12,544 cardinal samples and 2,687 ordinal samples, 0 errors. The tag fallback |
i18n.format | dates against the CLDR test data (testData/datetime/datetime.json, Gregorian English: 15 cases, 0 errors, 3 skipped because they require time zone names). Numbers, currencies, percentages, dates, lists, relative time, sizes and durations of the other locales against values written by hand from the CLDR 48.2 patterns and symbols (CLDR ships no number test data). Indian grouping and minimum grouping. The digits of JPY, KWD, USD and BRL. Round-half-even, NaN and infinity. Zero allocations. And the on-demand locales (the generated pt equal to the bundled one, sv and de-CH, and what is rejected) |
i18n.messages | MessageFormat case by case (the plural of en, pl and ar, =N and offset, ordinals, select, nested messages, quotes, #, missing arguments, each syntax error, the depth, the buffer contract). InspectMessage. Pseudolocalization and the planted layout error. The .etlcat (building, opening from memory and from disk, lookup, move, close unmaps, switching locale unmaps the previous one). The fallback with the hook. The targets (10,000 messages, Get < 5 ns). Zero allocations |
i18n.tool | each check defect class through its fixture, and the good ones (PO and TOML) with none. Reading PO and TOML, and the errors of each one with the line. Extraction (comments, strings, raw strings, #define, digit separators, concatenated literals, the same id with two texts). The header and kSourceHash. End to end through the command line (extract → header → compile → open and format, a compile with defects does not write, pseudo, stats, usage) |
i18n.fuzz | a deterministic driver with five targets: the corrupted .etlcat (from memory and, now and then, mapped from disk), the message (the buffer contract, pseudo reads the same as the formatter, InspectMessage never accepts what the formatter rejects, pseudo does not change the placeholders), the PO, the TOML and the corrupted .etlloc (the number and date pattern interpreters with hostile data) |
---
C layer
Header ethereal/c/i18n/i18n.h (source src/c/i18n/i18n.cpp), 53 ETLC_I18n* functions. The locale (ETLC_I18nLocale) and the plural rules (ETLC_I18nPlural) are small values in the caller's memory, with no release. The .etlloc data, the .etlcat catalogs and the messages are handles with Destroy. It covers resolving a tag to the bundled locale (with its canonical tag), the first day of the week, the list of bundled locales, the plural categories (cardinal of an integer and of a written number, ordinal, the categories the locale uses and their names), numbers, percentages, exact decimals, currencies, file sizes, durations, dates (styles and CLDR pattern, with the date from the Time C layer's ETLC_CivilTime), relative time, lists, the message as text with arguments, pseudolocalization, building an .etlcat in memory, opening a catalog (file or memory, without copying) and the message chain with the missing-message hook in C.
Left out are InspectMessage (a translation validation tool, whose output points into the message) and FormatToString, which allocates and which the buffer calls already cover.
Tests i18n.cabi.c11 and i18n.cabi.c17 (tests/i18n_c_abi.c): the values confirmed by the C++ tests, and an en and pt catalog built by the C layer itself, with the fallback to en and the hook. The .etlloc only has the rejections in the test, because building one requires the Python generator.
---
Status, against the spec (section 7)
| Criterion | Status |
|---|---|
| Lookup by id | ✅ an index, inline: 1.4 to 2.6 ns |
| Opening a catalog | ✅ mapped, checked, not read: 0.046 ms (GCC) and 0.28 to 0.33 ms (MSVC) for 10,000 messages |
| Allocations | ✅ zero when looking up and when formatting into spans, with ETL_EXPECT_NO_ALLOC (opening and closing included) |
| Data size | ✅ 50.5 KB for the 21 locales, published per locale (above). The whole module 139.5 KB |
| Plurals | ✅ 100% of the CLDR samples, in all 227 locales (beyond the bundled ones) |
| Placeholder validation | ✅ missing, extra, retyped: check and compile fail |
| Missing key | ✅ the fallback resolves it, never empty, never a crash, through the hook |
| Named placeholders | ✅ the order changed in the translation gives the correct text |
| Numbers | ✅ against CLDR values, with Indian grouping. Written by hand, because CLDR ships no number test data |
| Currencies | ✅ JPY 0, KWD 3, USD and BRL 2 digits |
| Dates | ✅ against the CLDR test data in English (15 cases, 0 errors). In the other locales against the CLDR patterns |
| Pseudolocalization | ✅ expands and adds accents. Finds the planted layout error |
check | ✅ each class it claims to find, with one fixture each |
| Switching locale | ✅ the old catalog unmapped, the address free again |
| Fuzzing | ✅ no breakage (MSVC and GCC, 3 seeds). The fuzzer found a real defect, fixed (an empty "present" text made Get return empty) |
| Sanitizers | ✅ ASan and UBSan clean on all I18n tests and on the fuzzer (3 seeds × 60,000) |
---
Deviations from the spec
- **gettext
msgid_pluralis not accepted.** The plural goes inside the message, in ICU syntax, which gives the six CLDR categories by name. gettext'smsgstr[n]depends on each file'sPlural-Formsformula and does not say which category each index is.checkrejects it with a message that explains this. - **
checkis strict about plurals:** an=1does not count as theonecategory.{n, plural, =1 {…} other {…}}in English fails (oneis missing), even though in English only 1 isone. - The data of the 21 bundled locales is always resident (50.5 KB in the image). "Only the active locale resident" applies to the catalogs and to the
.etllocfiles, which are mapped and unmapped. - The mapping belongs to I18n itself (
src/cpp/i18n/map.cpp). The File module now implements theetl_fs_*API (2026-09-28. Before, it was only declared), but I18n keeps its own: it needs to distinguish "the file does not exist" from "read error", andetl_fs_resultdoes not have that code. - **The name is
FormatMessageText** becauseFormatMessageis a macro from<windows.h>, and whoever included it would not be able to call the function. - The glue with Text is only the currency spacing (the Unicode general categories, with
ETHEREAL_TEXT). Case-insensitive key lookup and locale-aware sorting were not done: the keys are identifiers, and Text's collation is the root DUCET, without per-locale tailoring. A "locale-aware"Comparewould give the same result as Text's and would pretend to be something else. - **Dates use
Time::SCivilTimedirectly, without a seam: Time belongs to the core. There is noIAllocator**, because nothing allocates outside the two functions that say so in their name. - Time zone names are not included (the Time spec excludes the time zone database): the
z/zzzzformats give GMT with the offset. - The pseudolocale is
en-XAand uses the English plural rules.