Debian Codegraph @

debian/rust-vendor/fluent/README.md

raw
1 # Fluent
2
3 [![crates.io](https://img.shields.io/crates/v/fluent.svg)](https://crates.io/crates/fluent)
4 [![docs.rs](https://img.shields.io/docsrs/fluent)](https://docs.rs/fluent)
5 [![Build](https://github.com/projectfluent/fluent-rs/actions/workflows/test.yaml/badge.svg)](https://github.com/projectfluent/fluent-rs/actions/workflows/test.yaml)
6 [![Coverage Status](https://coveralls.io/repos/github/projectfluent/fluent-rs/badge.svg?branch=main)](https://coveralls.io/github/projectfluent/fluent-rs?branch=main)
7
8 The `fluent-rs` workspace is a collection of Rust crates implementing [Project Fluent][],
9 a localization system designed to unleash the entire expressive power of natural language translations.
10
11 This is an umbrella crate exposing the combined features of `fluent-rs` crates with additional convenience macros.
12
13 [Project Fluent]: https://projectfluent.org
14
15 Usage
16 -----
17
18 ```rust
19 use fluent::{FluentBundle, FluentResource};
20 use unic_langid::langid;
21
22 fn main() {
23 let ftl_string = "hello-world = Hello, world!".to_owned();
24 let res = FluentResource::try_new(ftl_string)
25 .expect("Failed to parse an FTL string.");
26
27 let langid_en = langid!("en-US");
28 let mut bundle = FluentBundle::new(vec![langid_en]);
29
30 bundle.add_resource(&res)
31 .expect("Failed to add FTL resources to the bundle.");
32
33 let msg = bundle.get_message("hello-world")
34 .expect("Message doesn't exist.");
35 let mut errors = vec![];
36 let pattern = msg.value
37 .expect("Message has no value.");
38 let value = bundle.format_pattern(&pattern, None, &mut errors);
39
40 assert_eq!(&value, "Hello, world!");
41 }
42 ```
43
44 `FluentBundle`, which is the main struct at the moment, is intended to remain
45 a low level API.
46 There is a number of higher level APIs like [fluent-resmgr][] and
47 [fluent-fallback][] intended to wrap around it and provide better ergonomics
48 for bindings and direct usage.
49 Those higher level APIs are not mature yet enough to be included in this package,
50 but will get added once they are.
51
52 [fluent-resmgr]: https://crates.io/crates/fluent-resmgr
53 [fluent-fallback]: https://crates.io/crates/fluent-fallback
54
55
56 Learn the FTL syntax
57 --------------------
58
59 FTL is a localization file format used for describing translation resources.
60 FTL stands for _Fluent Translation List_.
61
62 FTL is designed to be simple to read, but at the same time allows to represent
63 complex concepts from natural languages like gender, plurals, conjugations, and
64 others.
65
66 ```fluent
67 hello-user = Hello, { $username }!
68 ```
69
70 [Read the Fluent Syntax Guide][] in order to learn more about the syntax. If
71 you're a tool author you may be interested in the formal [EBNF grammar][].
72
73 [Read the Fluent Syntax Guide]: http://projectfluent.org/fluent/guide/
74 [EBNF grammar]: https://github.com/projectfluent/fluent/tree/master/spec
75
76
77 Get Involved
78 ------------
79
80 `fluent-rs` is open-source, licensed under both the Apache 2.0 and MIT licenses. We
81 encourage everyone to take a look at our code and we'll listen to your
82 feedback.
83
84
85 Discuss
86 -------
87
88 We'd love to hear your thoughts on Project Fluent! Whether you're a localizer
89 looking for a better way to express yourself in your language, or a developer
90 trying to make your app localizable and multilingual, or a hacker looking for
91 a project to contribute to, please do get in touch on the mailing list and the
92 IRC channel.
93
94 - Discourse: https://discourse.mozilla.org/c/fluent
95 - Matrix channel: <a href="https://chat.mozilla.org/#/room/#fluent:mozilla.org">#fluent:mozilla.org</a>