Re: Question on Message Format 2

10 views
Skip to first unread message

Shane Carr

unread,
Jul 23, 2025, 4:53:46 PMJul 23
to David Rowe, Message Format Working Group
Hi, David!

Were you looking for an example in JavaScript, Android, iOS, Flutter, ... ?

@Message Format Working Group -- could someone share an example of the usage of MF2?

-Shane

On Wed, Jul 23, 2025 at 12:54 PM David Rowe <david...@sil.org> wrote:
Hi Shane,

Tex suggested I contact you regarding Message Format 2. I'm in
discussion with a developer who would like to use it, but has some
questions.

The biggest question is whether there's an example of a software project
using MF2 and also localizing those messages into languages other than
English.

Maybe this is outside the scope of MF itself, but having such an example
might lower the bar for adoption.

Even a "Hello, World" level app would be helpful. Suppose it showed a
dialog box containing a button and some example strings: "You have
clicked the button {0} times." and "That was the {0}th time you clicked
the button."

For the first string, English would need "one" and "other" forms ({0}
time and {0} times).
For the second string, English would need {0}st, {0}nd, {0}rd, and {0}th
forms.

Then what would be the process (or an example of one possible process)
of extracting those strings, determining the number of forms for each
target language, and localizing them (in French and Russian for example,
which have different numbers of forms)?

Ideally the app would be able to dynamically switch the UI language
(from English to French to Russian, etc).

Thanks,
David

Nebojša Ćirić

unread,
Jul 23, 2025, 6:17:49 PMJul 23
to Shane Carr, David Rowe, Message Format Working Group
Wrt localization support, I think it's supported in Okapi as filter - Mihai to confirm.

If am not mistaken, official ICU documentation has examples - https://unicode-org.github.io/icu/userguide/format_parse/messages/mf2.html#examples

--
You received this message because you are subscribed to the Google Groups "Message Format Working Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to message-format...@chromium.org.
To view this discussion visit https://groups.google.com/a/chromium.org/d/msgid/message-format-wg/CABxsp%3D%3D%2BhbrdRT%2BVcb5pLjTSF%3DDFPW58b-tE5UPywDm5GDAMLQ%40mail.gmail.com.

Mihai Niță Ⓤ

unread,
Jul 25, 2025, 2:28:24 AMJul 25
to Nebojša Ćirić, Shane Carr, David Rowe, Message Format Working Group
Hello David,

Integration, applications

MessageFormat2 (same as the ICU MessageFormat before it) does not provide any mechanism for storing or loading strings, rendering them, refresh the UI on language change, binding to data (so that it refreshes on data change), etc.

The only functionality is: take a string, and some parameters, get back a string with all parameters substituted, in a locale aware way.
This means it can be easily integrated with any existing resource formats, or framework.
Can store such strings in .po files, Windows resources, Android strings.xml, iOS .strings files, json, soy, freemarker, and so on.
The extraction and localization process is the same as for any other string.

Overall use (pseudocode):

String message = load string from localization store, OS / Framework dependent
String formattedMessage = new MF2(message, locale).format({"user": userName, "expDate": someExpirationDate})
Use the formattedMessage in UI

Only the red part is MF2 related, everything else is the same as for any older technology.

We have implementations for Java, C++, and JavaScript, and we (of course) hope for more to come. Rust in the works.

Any existing application being able to make calls to one of these languages can be adapted to use MF2.

There are instructions for how to create a "Hello world" application here (C++ and Java, with ICU):

If it helps I can change that Java hello world app to use resource bundles.

===

MF2 examples:

"You have clicked the button {0} times."
You have clicked the button {$clickCount} times.

"That was the {0}th time you clicked the button."
.input {$clickCount :number select=ordinal}
.match $clickCount
  0   {{You never clicked the button.}}
  1   {{Welcome, you just became a button clicker!}}
  one {{That was the {$clickCount}st time you clicked the button.}}
  two {{That was the {$clickCount}nd time you clicked the button.}}
  few {{That was the {$clickCount}rd time you clicked the button.}}
  *   {{That was the {$clickCount}th time you clicked the button.}}

It is very easy to play with this in our playground:

A lot more available as test units on the official site, provided by the working group:

And in the ICU implementations:

===

Localization

Since these are "just strings", they are stored in any existing resource format
They will be extracted / translated / leveraged / imported / etc like all the other (non-MF2) localizable strings.

The challenge is to present them in a meaningful way in translation tools: protecting the placeholders, rendering with example placeholders, etc.

At this point I am not aware of tooling doing that.

The Okapi Framework (a Java localization framework) can handle the old ICU MessageFormat.
Which has some of the same challenges (for example plurals changing from 2 forms to 4 forms, selections, etc)
But MF2 will need more than that.

We worked with OASIS and XLIFF 2.2 has a new module that can be used to represent selectors, gender, and plurals (cardinal and ordinal):

The Java implementation of MF2 has public APIs that provides access to a structured form of a parsed message (a data model).
It can do both parsting, and writing string messages in MF2 syntax.
That way anyone wanting to write filters, linters, any other tooling, can do so without having to implement a parser from scratch.
So writing a conversion between MF2 and XLIFF should not be a big task.
But it hasn't happened yet (that I'm aware of)

===

I'll be happy to add more examples / links / clarifications, as needed.

Thank you, 
Mihai


Reply all
Reply to author
Forward
0 new messages