| Crates.io | personnel-locale |
| lib.rs | personnel-locale |
| version | 0.1.1 |
| created_at | 2023-01-13 08:06:33.118714+00 |
| updated_at | 2023-05-03 17:30:07.452149+00 |
| description | Simple wrapper for fluent crate. |
| homepage | |
| repository | |
| max_upload_size | |
| id | 757757 |
| size | 8,240 |
Simple wrapper for fluent-rs. The goal of this project is to encapsulate a fluent crate boilerplate, so it will be easy to use in smaller projects.
It's initially written for my Personnel Manager project, which you can check on my GitHub page, but you are free to use it any way you like it.
To understand anything below ou need to know what is Fluent in the first place. You can check it here: https://projectfluent.org/
use personnel::Locale;
let locale = Locale::new(include_str!("../test.ftl")).unwrap();
println!(locale.get_message("hello-world", None::<String>, &[]).unwrap());
In the second line, we create our Locale struct. This will encapsulate all Fluent boilerplate for you.
In the third line, you can see a get_message function. You will refer to it every time you want
to get a localized string from your Locale. It takes Fluent message, attribute and
args. If you don't understand what is it, you should go back to Fluent documentation and
finish it before reading further. Also, as you can see attribute and args are optional
if you don't need or have them, you can pass None for the attribute and an empty array like this
&[] for the args.
If you are still confused about args and attribute examples are below.
let locale = Locale::new(include_str!("../test.ftl")).unwrap();
locale
.get_message("hello-world", Some("special"), &[])
.unwrap()
let locale = Locale::new(include_str!("../test.ftl")).unwrap();
locale
.get_message("hello-world", Some("arg"), &[("world-type", "Custom")])
.unwrap()
NOTE: When you use Fluent args an actual message will be "Hello, \u{2068}Custom\u{2069} World!".
That is one of FLuent's features. Not a bug.
Here is fluent file used in all examples:
hello-world = Hello, World!
.special = Hello, Special World!
.arg = Hello, {$world-type} World!