Skip to content

About

ICU MessageFormat 1 for Go, verified byte-for-byte against intl-messageformat (FormatJS) 12.1.5

Topics

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

11 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

intl-messageformat-go: the message {count, plural, one {# item} other {# items}} renders identically in react-intl, Angular, Crowdin and Go

intl-messageformat-go

Need your FormatJS / react-intl translations to render in Go without rewriting them? This package renders the same catalog, same output, in pure Go.

Your product already has its messages in MessageFormat: react-intl, FormatJS, Angular's i18n, Crowdin and Lokalise all speak it. When part of the stack runs Go (APIs, email renderers, notification workers, CLIs), those messages could not render there. Porting them to Go templates means rewriting every plural rule by hand and losing the translator-facing syntax your localization pipeline depends on.

This package renders the same messages in Go with the same output: plural categories from generated CLDR 48 data, locale-correct numbers, dates and rich text. "Same output" applies to the supported subset below, pinned byte-for-byte against the reference implementation on a differential corpus. Constructs outside that subset are not approximated: they fail with typed errors instead of silently wrong text.

go get github.com/ofershap/intl-messageformat-go

No cgo, no dependencies. The CLDR 48 locale data (766 locales) is generated Go source compiled into the package.

mf, _ := messageformat.New("he", "{count, plural, one {הודעה אחת} other {# הודעות}}")
out, _ := mf.Format(map[string]any{"count": 5})
// "5 הודעות"

Supported subset

  • Simple arguments: Hello {name}
  • select, plural, selectordinal with offset: and =N exact selectors
  • # inside plural bodies (formats value minus offset)
  • Nested messages (plural inside select, and so on, bounded to 100 levels)
  • Numbers: {n, number}, integer, percent, and currency through a named custom format: {n, number, currency} plus WithNumberFormats(map[string]NumberFormatSpec{"currency": {Style: "currency", Currency: "USD"}})
  • Dates and times: {d, date, full|long|medium|short} and the same for time, at UTC, with the exact style mapping FormatJS 12 uses (which is not Intl.DateTimeFormat's dateStyle/timeStyle)
  • Rich-text tags through TagFunc: Click <b>{what}</b>
  • FormatJS apostrophe quoting ('{', '', '#')

Deliberate exclusions (typed errors, never silent wrong text)

Valid MessageFormat that uses these returns a descriptive error instead of wrong output:

  • Number and date/time skeletons ({n, number, ::currency/USD}, {d, date, ::yyyyMMdd}). Note the difference from the supported custom-format currency above: the :: skeleton syntax is what is unsupported.
  • User-supplied date pattern strings ({d, date, yyyy-MM-dd}). FormatJS 12 silently ignores these and falls back to medium; this package tells you instead.
  • Date and time formatting for non-Gregorian calendars, whether the locale's default (9 locales: fa, fa-AF, ps, th, ckb-IR, lrc, mzn, shn-TH, and inherited subtags) or explicitly requested (en-u-ca-islamic). Requesting Gregorian explicitly (fa-u-ca-gregory) works. Plural and number formatting are calendar-independent and unaffected.
  • Time zones other than UTC: time.Time values are rendered at UTC. Convert before formatting for other zones.

Locale, calendar and time zone boundaries

Plural and number formatting resolve every CLDR 48 locale (766), following the usual ICU fallback chain (region to language to root), so an unknown or unsupported tag falls back rather than failing. Date and time formatting covers the same locales on the Gregorian calendar only, at UTC, as listed above.

Compatibility evidence: 5,505 differential checks against the reference runtime

Every supported behavior is pinned by golden fixtures generated from the reference implementation and compared exactly:

Corpus Checks Breakdown Reference
Messages (parser + formatter) 855 57 case/variant combinations x 15 locales intl-messageformat 12.1.5
Numbers 2,700 30 values x 15 locales x 6 styles Intl.NumberFormat
Dates and times 720 6 fixed UTC instants x 15 locales x 8 styles Intl.DateTimeFormat
Plural categories 1,230 41 values x 15 locales x cardinal + ordinal Intl.PluralRules

Reference environment: Node v22.23.4, ICU 78.3, Unicode 17.0, CLDR 48.0. The fixture generator, its pinned npm lockfile and all fixtures live in testdata/, so the corpus is reproducible. "Verified" means byte-identical output on this corpus across the 15 exercised locales (en, he, ar, ar-EG, ru, pl, cy, ja, zh, ko, fr, de, es, pt-BR, hi), not a claim of universal equivalence on every possible message.

The differential approach also documents where JavaScript itself is surprising: V8 plural-category behavior on exponent-form numbers, FormatJS 12 silently dropping user date patterns, and its use of timeZoneName: 'short' for both long and full time styles are covered by tests.

FAQ: ICU MessageFormat in Go, FormatJS on the server, react-intl message reuse

Can I use my react-intl / FormatJS messages from Go? Yes. That is the main use case. The same message catalog (simple args, select, plural, selectordinal, rich text) renders here with the output pinned against intl-messageformat 12.1.5 on the differential corpus.

Is this a port of @formatjs/icu-messageformat-parser? It implements the same MessageFormat 1 grammar (tags included) and is verified against the reference runtime's output, but it is independent Go code with no FormatJS source inside.

Does it support ICU skeletons like ::currency/USD? Not in v1. Skeleton styles return a typed error. Use {n, number, integer|percent} or a named custom format via WithNumberFormats for currency.

Which locales and calendars? Plural, number and Gregorian date/time data for 766 locales from CLDR 48.0. Date/time formatting for locales whose default calendar is not Gregorian returns a typed error rather than wrong dates.

What about time zones? Values render at UTC, matching a timeZone: 'UTC' reference setup. Convert your time.Time before formatting for other zones.

What else exists for MessageFormat in Go? As of 2026-11-14 searches: a small MessageFormat 2 draft port, a few early-stage MF1 parsers without CLDR-backed formatting, and file-format parsers. Nothing else rendering MF1 with generated CLDR 48 data verified against a FormatJS corpus was found.

Related projects

For the JavaScript side of your stack, use FormatJS itself. If you need the lunr.js search engine in Go: lunr-go. More Go ports verified against their JS originals: handlebars-go, json5, fuse-search.

Contributing

Issues and PRs welcome - see CONTRIBUTING.md. Please report security issues privately per SECURITY.md.


More projects: gitshow · real-browser-mcp · cursor-usage-tracker · mcp-server-markdown · readme-builder · grok-bot-skills · mashov-parent-brief · gailwind · lather


Author

Made by ofershap

LinkedIn GitHub Blog


README built with README Builder

License

MIT © Ofer Shapira. Generated locale data derives from Unicode CLDR 48.0 under the Unicode License v3; see NOTICE.

About

ICU MessageFormat 1 for Go, verified byte-for-byte against intl-messageformat (FormatJS) 12.1.5

Topics

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages