projectfluent / fluent-rs

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

Custom functions with scope access #364

Open PPakalns opened 3 months ago

PPakalns commented 3 months ago

Tries to temporary solve complex translation cases mentioned in: https://github.com/projectfluent/fluent-rs/issues/268 https://github.com/projectfluent/fluent/issues/80

1) Support user implemented custom functions that can access current scope, can work as Message references. In future we could allow access in custom functions to additional information about current scope (developer arguments, local arguments, current errors) Message references are highly needed for more complex translation cases with a lot of possible message combinations.

2) Additionally allow using expressions inside named arguments.
(It looks like by default fluent doesn't allow it Playground ) This functionality can be placed under boolean flag if we do not want to enable it by default.

See examples included in added tests.

Would like to get feedback if these changes can be upstreamed to fluent-rs.

PPakalns commented 2 weeks ago

Ping.