projectfluent / fluent-rs

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

Add transform to FluentBundle #131

Closed zbraniecki closed 5 years ago

zbraniecki commented 5 years ago

Fixes #97

zbraniecki commented 5 years ago

This is just the scaffolding. I will later add more features from https://searchfox.org/mozilla-central/source/intl/l10n/L10nRegistry.jsm#494 like elongating, wrapping etc.

For now, I added the transform to FluentBundle, ported reference test for it, and added fluent-pseudo which exposes a simple transform function that can be fed into FluentBundle::set_transform.

@Manishearth - can you verify that I'm using Rust well here? I'd love to use type/trait alias for TransformFn (and for FluentFunction) so that people can just reference it when writing theirs, but it seems that those features are not yet available, to for now I have to manually put the signature and trait combination everywhere.

Pike commented 5 years ago

Can we implement this in a way that the gecko wrapper can forward transform functions written in js?

This would be important for fluent-rs being a drop-in replacement for fluent.js.

zbraniecki commented 5 years ago

We could try to produce an equivalent of fluent-pseudo in gecko and feed it to set_transform but it may be hard or impossible yet.

The rust side that this PR provides can be fed with anything so we can explore that