fluent-static-codegen
Part of fluent-static library responsible for generating Rust code from Fluent resources.
The project is heavily relying on fluent-rs for parsing and processing Fluent resources.
Usage
Fluent resources
The code generator requires that Fluent resources adhere to the naming convention: <l10n_root>/<language_id>/<bundle_name>
.
language_id
must be a valid Unicode Language Identifierbundle_name
must be a valid Rust identifier
Cargo dependencies
Add fluent-static-codegen
to project's build-dependencies
section
[]
= "*"
Build script
The fluent-static-codegen requires Cargo Build Script to operate.
use ;
use ;
Code generation
Generated code naming conventions
- Fluent message names converted to Rust snake_cased identifiers
my-message
->my_message
msgTest
->msg_test
msg1
->msg_1
- Fluent message variables mapped to snake_cased indentifiers also
- Fluent message attributes mapped to
<message_name>_<attribute_name>
my-button.title
->my_button_title
Fluent message mapped to a function
The fluent_static_codegen::FunctionPerMessageCodeGenerator
generates module per each message_bundle
and maps messages to a functions
pub mod <bundle_name>
Fluent message mapped to a method
fluent_static_codegen::FunctionPerMessageCodeGenerator
generates struct per each message_bundle
and maps messages to the struct's public methods
pub mod <bundle_name>
use ;
use Message;
<
Setting FluentBundle options
let generator = new_with_options;
generate!;
Compile-time validation
The following conditions are validated at compilation time to ensure that each message in a bundle_name
is correctly defined:
- The message must be defined across all supported languages.
- All instances of the message must share the identical set of variables (if any variables exist).
- Message attributes must remain consistent across all languages.
A compile-time error will be raised if any of these conditions are not met, guaranteeing consistency and correctness across different language implementations.
Contributing
Contributions are welcome! Please feel free to submit pull requests, report bugs, and suggest features via the issue tracker.
License
This project is licensed under MIT license. Feel free to use, modify, and distribute it as per the license conditions.