Fluent-Typed
When using translation keys, there is often no easy way to know if they are being used
correctly and if they are being used at all. This project generatesjkjj, using the fluent
ast,
the function definitions for the translation keys in a fluent file.
In order to guarantee the safeness, funtions are only generated for messages that are found in all the locales. For those only found for some locales or if the signature of the messages are different a warning is printed.
It is up to the user to load the translation resources, which gives him the liberty to choose how they are retreived (embedded in the binary, loaded from a file, downloaded etc).
There is no need to handle any fallback language since it is guaranteed that all messages are translated into all languages
Usage
# in Cargo.toml
[]
= 0.1
[]
= { = "0.1", = ["build"] }
// in build.rs
// in lib.rs or main.rs
use ;
Type deduction
Since the fluent syntax doesn't explicitly specify the type of the translation variables, this project uses the following rules to infer the type of the translation variables:
- String:
- If a variable's comment contains
(String)
, as in# $name (String) - The name.
- If a variable's comment contains
- Number:
- If a variable's comment contains
(Number)
, as in# $count (Number) - How many.
- If a NUMBER function is used, asin
dpi-ratio = Your DPI ratio is { NUMBER($ratio) }
- If a selector only contains numbers
and CLDR plural catagories:
zero
,one
,two
,few
,many
, andother
. Example:your-rank = { NUMBER($pos, type: "ordinal") -> [1] You finished first! [one] You finished {$pos}st [two] You finished {$pos}nd [few] You finished {$pos}rd *[other] You finished {$pos}th }
- If a variable's comment contains