A enum/struct derive macro for Project Fluent.
given Project Fluent's first example
# Simple things are simple.
hello-user = Hello, {$userName}!
# Complex things are possible.
shared-photos =
{$userName} {$photoCount ->
[one] added a new photo
*[other] added {$photoCount} new photos
} to {$userGender ->
[male] his stream
[female] her stream
*[other] their stream
}.
This could be represented as
use ;
// optional, defaults to "fluent" if not specified
using any of the prototyping tools for building the .ftl resources, we'd get
## Gender
gender-Female = Female
gender-Helicopter = Helicopter
gender-Male = Male
gender-Other = Other
## Hello
hello-User = User { $user_name }
## Shared
shared-Photos = Photos { $user_name } { $photo_count } { $user_gender }
which we would modify to our needs:
## Gender
gender-Female = Female
gender-Helicopter = Helicopter
gender-Male = Male
gender-Other = Other
## Hello
hello-User = Hello, {$user_name}!
## Shared
shared-Photos = {$user_name} {$photo_count ->
[one] added a new photo
*[other] added {$photo_count} new photos
} to {$user_gender ->
[male] his stream
[female] her stream
*[other] their stream
}.
see the output with
Generics
all generics need to impl for<'a> &'a {type parameter}: Into<FluentValue<'a>>, like
// optional, defaults to "fluent" if not specified
Display Trait
By default, the macro will only implement the es_fluent::FluentDisplay trait.
Its also possible for it to only implement the std::fmt::Display trait. By manually adding #[fluent(display = "std")], such as
This can also be implemented for strum::EnumDiscriminants, such as
// doesn't need to be condensed into a single block, using multiple block is fine.
On Structs
given
// set display impl to `std::fmt::Display`
// generates specialized names
// custom derives you'd define
// describes the item ident (name) as a fn, `{}::this_ftl()`
this will expand to
if no keys are provided, this will expand to
Simple examples
see the examples dir to see a bunch of ways to use this crate. where i18n ressources are placed in the i18n dir.
Gpui example
https://github.com/stayhydated/gpui-form/tree/master/examples
Prototyping tools
Notes
es-fluentexpects you to provide afl!macro, accessible viacrate::fl- This macro was designed around i18n-embed-fl and i18n-embed. Decoupling from it is planned in the future. For now, this satisfies my use case with gpui. Feel free to contribute to the project!
Derive Macro Supported kinds
Enums
- enum_unit
- enum_named
- enum_tuple
Structs
- struct_named