Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiling fluent #345

Open
ecstrema opened this issue Feb 18, 2022 · 3 comments
Open

Compiling fluent #345

ecstrema opened this issue Feb 18, 2022 · 3 comments

Comments

@ecstrema
Copy link

I couldn't find any info regarding compiling fluent to the target languages.

Is it possible, for example, to transform this:

key = Hello, {$userName}!

Into this (javascript implementation here);

key(props) => "Hello, " + props.userName + "!"

This greatly helps reducing bundle size. It is done by messageFormat and a few others and would be great to have.

@spookylukey
Copy link
Contributor

spookylukey commented Feb 19, 2022

For Javascript, see https://github.com/eemeli/fluent-compiler - although I have significant doubts about the implementation, as I'm not convinced it is sufficiently checking input in for the case of potentially malicious ftl files.

For Python, there is my fluent-compiler package, although at the moment it doesn't output Python code to save for later use, it simply uses compilation as an implementation strategy.

@ecstrema
Copy link
Author

Good to know. I'll have a look at both of them.

@eemeli
Copy link
Member

eemeli commented Feb 20, 2022

I wrote the JS compiler a while ago, but haven't touched it in years. IIRC, it might be targeting an earlier version of the Fluent spec even. I wrote it largely following on from the JS messgeformat design, i.e. as a build-time tool, so I didn't really consider malicious FTL files at all in its design.

My current main focus around this is on the Unicode MessageFormat 2 (MF2) spec, and eventually getting that to be the basis for Intl.MessageFormat in JavaScript. This is relevant for compiling messages, as it'll include a data model representation of messages which will have native formatter support in JS as well as other languages. In other words, we'll be able to compile Fluent and other syntaxes into the MF2 data model during the application build, rather than executable JS source, and feed that to a formatter provided by the runtime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants