fluent icon indicating copy to clipboard operation
fluent copied to clipboard

Cooperation with LinguiJS project

Open tricoder42 opened this issue 5 years ago • 1 comments

Hello 👋

I came over this project few weeks ago and I really like it. I'm working on LinguiJS and after reading Integration Fluent article it seems we have a very similar goals.

As far as I understand, you're mostly working on a new message syntax, Fluent. In LinguiJS, on the other hand, the message syntax is one of the few things which is external. Currently I'm using ICU MessageFormat, but I already have a few ideas how to integrate Fluent with minimum changes in private or public API.

The one of LinguiJS ideas are compiled message catalog - messages are parsed at build time and converted to plain functions. The message parser is removed from production bundle and as a side-effect, it's possible to use any message syntax. So far it's just a theory, but there're only few places (one?) in core which depends on message syntax. This would be perfect to integrate Fluent even at early stages, because it would be optional.

LinguiJS also extracts messages from source code. That's something that we could share as you're planning to work on it.


I also share the motivation that the library should be minimalist, modular and composable

I have an idea that the core should be minimal and completely message syntax agnostic. The only responsibility is managing active language, active message catalog and passing data to message formatter. Loading of catalogs is managed by users.

react package has just React wrappers around core to leverage JSX and context.

cli is used for extracting/compiling messages.

Babel transform plugins (soon to be babel macros) are optional, but allow further abstraction on top of MessageFormat:

// in React, JSX is converted to MessageFormat
<Trans>Hello {world}</Trans>
//      ↓ ↓ ↓ ↓ ↓ ↓
<Trans id="Hello {world}" />

// in plain JavaScript, template literals are used (this is in RFC stage)
i18n(t`Hello ${world}`)
//      ↓ ↓ ↓ ↓ ↓ ↓
i18n({
  id: "Hello {world}"
})
// in Fluent it would become
//      ↓ ↓ ↓ ↓ ↓ ↓
i18n({
  id: "Hello { $world }"
})

These transformations also work for plurals and other formatters. I can imagine how easily it would be to define message attributes in Fluent with such macros.


So, my question is: Can these two projects coexist together as a message syntax and localization framework or is it better to merge LinguiJS into Fluent in any way? What's your opinion?

Thank you for your time and a great project!

tricoder42 avatar Sep 07 '18 11:09 tricoder42

Hi @tricoder42 , thanks for the thoughtful question! The lead dev for the project is on PTO this week, and I'm at Unicode Conference. We'll look into it and try to respond as soon as possible :)

zbraniecki avatar Sep 12 '18 04:09 zbraniecki