logoalt Hacker News

MessageFormat: Unicode standard for localizable message strings

146 pointsby todsacerdotitoday at 10:26 AM59 commentsview on HN

Comments

jp1016today at 11:30 AM

One practical thing I appreciated about MessageFormat is how it eliminates a bunch of conditional UI logic.

I used to write switch/if blocks for:

• 0 rows → “No results” • 1 row → “1 result” • n rows → “{n} results”

Which seems trivial in English, but gets messy once you support languages with multiple plural categories.

I wasn’t really aware of how nuanced plural rules are until I dug into ICU. The syntax looked intimidating at first, but it actually removes a lot of branching from application code.

I’ve been using an online ICU message editor (https://intlpull.com/tools/icu-message-editor) to experiment with plural/select cases and different locales helped me understand edge cases much faster than reading the spec alone.

show 6 replies
ddevnyctoday at 5:35 PM

One thing I would really appreciate in this repository (and many like it) would be a simple, short, snippet of code that shows a typical use case of whatever the repo is selling me. Life's too short to dig around in the guts of the repository to find stuff like this out, it should be front and center. I want to know about the ergonomics and hackability of what I'm about to delve into.

show 1 reply
BoppreHtoday at 10:57 AM

The meeting notes in the repo was a nice surprise. Overall looked great, striking a good balance.

  .input {$var :number maximumFractionDigits=0}
  .local $var2 = {$var :number maximumFractionDigits=2}
  .match $var2
  0 {{The selector can apply a different function to {$var} for the purposes of selection}}
  * {{A placeholder in a pattern can apply a different function to {$var :number maximumFractionDigits=3}}}
Oof, that's a programming language already. And new syntax to be inevitably iterated on. I feel like we have too many of those already, from Python f-strings to template engines.

I wish it'll at least stay small: no nesting, no plugins, no looping, no operators, no side effects or calls to external functions (see Log4J).

show 2 replies
1116574today at 11:22 AM

Looks alot like mozilla's project fluent, atleast in the basic use case.

https://projectfluent.org/

I wonder why it hasn't been adopted more widely.

show 5 replies
revetkntoday at 11:50 AM

My project Lokalized attempts to solve many of these complex plural/gender/ordinal/etc. rules with a tiny expression language:

https://lokalized.com

show 2 replies
strogonofftoday at 11:36 AM

Does anyone know the ETA of MessageFormat 2.0? I am aware of the effort since pre-COVID times. I recall that some of the developers behind Mozilla Fluent have been among the people working on MF 2.0, and it’d be great to know whether Fluent and ICU MF are going to be interoperable in foreseeable future.

show 2 replies
Brospertoday at 12:40 PM

I discovered it working in https://tolgee.io but I am kind of surprised it boomed today :D

What I can say that it's a well-maintained format but also kinda hard to learn.

rocquatoday at 10:50 AM

This seems great in concept, and totally infeasible. But if anyone can do it, unicode seems like a great candidate.

Does anyone have reason for more optimism?

show 3 replies
bmn__today at 11:30 AM

Looking for an expert who knows both libintl/Gettext and MessageFormat.

What is the equivalent of xgettext.pl, the file extension for the main catalog file `.po`, the __ function?

How does gender work (small example)? How does layering pt_BR on pt_PT work?

What is a compelling reason to switch?

show 1 reply
hackingonemptytoday at 3:18 PM

I know these libs are primarily for devs to localize their apps but can they be used also with untrusted inputs, both message strings and vars?

alexchamberlaintoday at 1:13 PM

Apologies if this is obvious and I missed it. Does this define a way to store the strings in various languages?

show 2 replies