☕ Comfy I18n
Comfy I18n aims to be a source format and target language agnostic transpiler. Currently, only the comfy-format and rust is implemented.
It translates your i18n sources to usable structures in your source code at compile time.
These structures are component based by design and are as such nestable and composable.
The API design is very opinionated and aims to use the language specific features to provide the most ergonomic API possible, while being feature rich and blazingly fast. Compared to the common dictionary based approach, it comes with an overhead in compile time and binary size.
Core features
✅ Ergonomic, intuitive and extendable API
Comfy I18n aims to have the most ergnomical and intuitive API design possible. This is a small showcase of the API. Please refer to the examples in the documentation for a more detailed overview.
// TODO: Improve Readme. Make it easy and concise. Add playgrounds where examples are.
// Must be used in the crate root
// Define the available contexts
i18n_init!;
i18n!
i18n!
✅ Blazingly fast
Comfy I18n trades speed for binary size and compile time.
It creates specialized structures and functions, which may or may not be optimized away by the compiler.
Nevertheless, the binary size and compile time would be bigger compared to a dictionary based approach.
For formatted strings dfmt is used under the hood, which performance is very close the the original core::fmt machinery, as it uses this machinery under the hood. This means for very simple cases it is slightly slower, as it does not take shortcuts (yet). However, this library will benefit from any future performance improvements of the core::fmt machinery.
| Benchmark | Comfy-i18n | Rust-i18n |
|---|---|---|
| Lookup of constant | 0.4 ns | 18.96 ns |
| Interpolation 2 args (strings only) | 50.18 ns | 47.15 ns |
| Interpolation 2 args (f64 only) | 129.49 ns | 149.10 ns |
| Interpolation 2 args (f64 only) + dynamic args | 128.72 ns | 148.25 ns |
| Interpolation 2 args (f64 only) + dynamic args + specifier | 130.03 ns | 336.88 ns |
| Interpolation 7 args (strings only) | 136.20 ns | 85.55 ns |
| Interpolation 7 args (f64 only) | 413.65 ns | 457.87 ns |
| Interpolation 7 args (f64 only) + dynamic args | 412.05 ns | 449.03 ns |
| Interpolation 7 args (f64 only) + dynamic args + specifier | 412.40 ns | 1,084.64 ns |
🚧 #16: Compile time validation
Be warned if there are missing translations. Warnings during development and errors during production builds.
🚧 #5: Different source file formats
Load localizations from different kind of source file formats other than the comfy format, e.g. TOML, JSON, Fluent or Gettext
🚧 #18: Hot reload translations from source files
Source files are watched for changes during development and hot reloaded if changes occur.
🚧 #2: Remote source files support
Load source files from a remote source on the fly. During compilation these source files are loaded to create the specification for the structure.
🚧 #2: No-std support
This library already largely supports no-std environments. However, this will not be a hard requirement for the releases until all core features have been implemented.
License
This project is licensed under either
at your option.