fluent-static
Fluent-static is a Rust library designed to generate statically typed function bindings from Fluent localization bundles. This allows for compile-time validation of localization message usage, enhancing both reliability and maintainability of your internationalized code base.
Features
- Compile-Time Validation: Errors in localization message usage are caught at compile time, promoting reliability in multi-language projects.
- Automatic Function Generation: Converts Fluent messages into Rust functions dynamically, eliminating the need for manual updates when localization files change.
- Easy Integration: Works seamlessly within a standard Rust build environment with minimal configuration.
Prerequisites
Before you begin, ensure you have the latest stable version of Rust installed on your machine. This project uses features that require Rust 2021 edition or later.
Installation
Add the following to your Cargo.toml
file:
[]
= { = "0.2.4" }
[]
= { = "0.2.4" }
Usage
To integrate fluent-static
into your Rust project, follow these steps:
Step 1: Fluent Resources
Ensure your Fluent resources are placed under a specific directory, e.g., ./l10n/
, and include at least one localization, e.g., en_US.ftl
.
Step 2: Build Script Setup
Create a build.rs
file in your project root if it does not exist, and use the following template to generate Rust bindings for your Fluent files:
use ;
use ;
Step 3: Accessing Generated Functions
You can now use the generated functions in your main application or other modules:
[]
= { = "0.2.4", = [ "axum", "maud" ] }
[]
= { = "0.2.4" }
use ;
use RequestLanguage;
use ;
async
async
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.