projectfluent / fluent-rs

Rust implementation of Project Fluent
https://projectfluent.org
Apache License 2.0
1.08k stars 97 forks source link

Add C interface #211

Open cireu opened 3 years ago

cireu commented 3 years ago

Fluent is a wonderful project for localization.

Somebody is talking about use fluent to power the localization of Emacs. Emacs is written in C and Elisp, a C interface of Fluent can help us to reuse fluent-rs and we don't need to reinvent wheels like fluent-c.

As Stallman says(https://lists.gnu.org/archive/html/emacs-devel/2020-12/msg01875.html), a C interface can also help a lot of GNU project to use fluent(instead of gettext) to power their localization. Would you like to provide a set of C interfaces?

Pike commented 3 years ago

I've dug into that thread a bit, and can't say that I'm fully understanding all the context yet.

To the question, I think this is an ask for localization-level API, and I guess Zibi's still finding out more stuff about that as he's working on converting the full Fluent stack in Firefox to Rust. We should probably wait for that to succeed before thinking about C APIs. Firefox talks to Fluent through FFI, and the code we currently ship has parts in JavaScript still.

Whether that implementation would be good for the FSF is also a question about licensing. Fluent-rs is APL/MIT, and while APL is usable from GPLv3 code. I haven't found indications on whether that's a problem for adoption or not.

I'd also add that the folks that are or used to be involved in Fluent are no C folks, and couldn't advice on how to map concepts to C (and in particular GNU) best practices. This would likely require a collaborative effort between folks knowing fluent-rs and potential consumers of the API on the C level.

zbraniecki commented 3 years ago

Hi! Thanks for reaching out!

We do use fluent-rs in Gecko via C FFI. Here's the relevant file - https://searchfox.org/mozilla-central/source/intl/l10n/rust/fluent-ffi/src/bundle.rs#67

It's not yet super trivial to package it and, as Axel said, I'm currently working on a "higher level" API for Fluent that wraps around FluentBundle to provide more complete experience of fallbacking and manage resource loading.

Since e use Fluent via C FFI in Gecko, I believe our experience may be of help here, and I'd be happy to work with you on extracting the bits of fluent-ffi out of Gecko and into a standalone crate for you to use.

Would that help?

cireu commented 3 years ago

Thanks!

I think I can model an POC demo after Zibi's code to help people in emacs-devel see the power of Fluent.

I'm also waiting for your good news about fluent-bundle ;)

zbraniecki commented 3 years ago

fluent-bundle is quite stable. I'm waiting with 1.0 release till I validate higher level in production, but so far it looks like the API holds well.

The higher level (fluent-fallback and some resource and lifecycle managment) are more in flux. I'm looking into stabilizing them to a more pre 1.0 level over the next month or two.

gregtatum commented 1 year ago

fluent-rs is already validated on Firefox as we've been using it in our release population. We haven't discussed officially bumping to 1.0 here. On the Firefox side the FFI hooks into ICU4C for some of the date time and number format operations. It seems like a C FFI should have these integrated as well.

I'd like to file an issue for hooking into ICU4X for the examples here, and then from there it would be possible to put together a C API I think.

ICU4X is using Diplomat for its FFI, but there is also uniffi which seems to have some nice ergonomics. It could be possible to put together the C APIs this way.

gregtatum commented 1 year ago

This does seem in scope, but is probably a large undertaking for a contributor to take on. Mozilla doesn't have a specific need for this feature at this time.