Interly
Internalization in Rust
Usage
# locales/en.ftl
hello = Hello, { name }!
// main.rs
use localize;
pub ;
// other/module.rs
use cratetr;
Notes and current limitations
- Default folder is
locales. -in filenames are converted to_, sohello-worldandhello_worldwould be considered equivalent, and it would be an error.- Variables types not detected (I don't know how), only strings.
- Only supported files structure is
- Languages accepted in form
"en","en_US", etc. Case insensitive,_required. - Languages will always fallback to global fallback. For example, if you have languages
["en", "ru"]and calltr!(name, "ru_RU"), it will fallback to"en". - Macros should be called at crate top.
Roadmap
- Default generation with simple .ftl files.
- Support selectors (docs.rs)
- Support attributes.
- Support terms as static methods.
- Macros parameters:
-
path- path to folder with localizations. -
resolver- how files are stored:files-{path}/*.ftl(current behaviour).folder-{path}/{locale}/*.ftl.
-
set_locale- how to specify current locale:init- set locale on startup.state- store locale as state.call- specify locale on each function call (current behaviour).
-
fallback- global fallback locale. -
sources- how to load locales sources. Probably this could be solved by providing macro for embedding, and regular struct for manual initialization.embed- embed sources to binary (current behaviour).load- load sources at startup from file system.
-
errors- how to handle errors (probably not required):ignorelogpanic(current behaviour)
-
- Fallback with respect to region (e.g.
"ru_RU"->"ru").- Probably calculate fallbacks on compile time?
- Support defining not at crate top (now just not tested, probably this already works).
- Probably this just required generating correct
#visidentifier insidetr!().
- Probably this just required generating correct
- More translation formats support (long-term).
Q&A
Interly doesn't fit your use-case, but do you want to use this library?
Open an issue, probably interly wants this too!
What's generated
For source files
# locales/en.ftl
hello-world = Hello, { $name }!
# locales/ru.ftl
hello-world = Привет, { $name }!
use localize;
pub ;
Generated (unrelated parts removed):
// main.rs
pub
pub
Output:
Hello, world!
Привет, мир!
Hello, мир!