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

Add transform to FluentBundle #131

Merged
merged 3 commits into from
Jul 30, 2019
Merged

Conversation

zbraniecki
Copy link
Collaborator

Fixes #97

@zbraniecki
Copy link
Collaborator Author

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.

Copy link
Collaborator

@Manishearth Manishearth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a good design. Yeah, there's no nice way to do trait aliases right now.

@@ -238,6 +240,17 @@ impl<R> FluentBundle<R> {
self.use_isolating = value;
}

pub fn set_transform<F>(&mut self, func: Option<F>)
where
F: 'static + Fn(&str) -> String + Send + Sync
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

usually you write 'static at the end

where
F: for<'a> Fn(&[FluentValue<'a>], &FluentArgs) -> FluentValue<'a> + Sync + Send,
F: 'static + for<'a> Fn(&[FluentValue<'a>], &FluentArgs) -> FluentValue<'a> + Sync + Send,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
F: 'static + for<'a> Fn(&[FluentValue<'a>], &FluentArgs) -> FluentValue<'a> + Sync + Send,
F: for<'a> Fn(&[FluentValue<'a>], &FluentArgs) -> FluentValue<'a> + Sync + Send + 'static,

@@ -238,6 +240,17 @@ impl<R> FluentBundle<R> {
self.use_isolating = value;
}

pub fn set_transform<F>(&mut self, func: Option<F>)
where
F: 'static + Fn(&str) -> Cow<str> + Send + Sync
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
F: 'static + Fn(&str) -> Cow<str> + Send + Sync
F: Fn(&str) -> Cow<str> + Send + Sync + 'static

categories = ["localization", "internationalization"]

[dependencies]
regex = "1.2"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newline at eof

@Pike
Copy link
Contributor

Pike commented Jul 30, 2019

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
Copy link
Collaborator Author

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

@zbraniecki zbraniecki merged commit 92d9fba into projectfluent:master Jul 30, 2019
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

Successfully merging this pull request may close these issues.

Add pseudolocales
3 participants