localize_it - Simple and fast localization library
A tiny, zero-allocation localization system for Rust designed with #![no_std] support.
This crate provides a macro-based API for defining compile-time locales and localized expressions
without using dynamic memory, hash maps, or runtime lookups. All localized expressions are stored in fixed-size arrays.
You can manually control (via init_locale!) the locale state or use the built-in locale storage
(via init_locale_with_storage!).
Cargo Features
serde— enablesserde::Serializeandserde::Deserializederives forenum Localeminiserde— enablesminiserde::Serializeandminiserde::Deserializederives forenum Localeborsh— enablesborsh::BorshSerializeandborsh::BorshDeserializederives forenum Locale
Example
A program that asks the user to choose a language, enter their name, and then greets them in the selected language:
use ;
use ;
// Define available locales
init_locale_with_storage!;
// Expressions can be any type allowed in compile-time context
expressions!;
Recommended Project Structure
A recommended way to organize your project is to create a dedicated locale module that handles locale
initialization and contains grouped expression modules. For example:
src/
├─ main.rs
└─ locale/
├─ mod.rs # Initialization locale here
├─ error.rs # First module with expressions
└─ ui.rs # Second module with expressions
Advantages
- O(1) localization lookup
- Zero allocations
- Macro-based API
- No external dependencies without optional features
no_stdcompatible
Design Constraints
- Not possible to update or add the translations without recompiling
- No plans to add automatic gender agreement, numeral declension, etc
How It Works
- Locales are defined as an
enumwith#[repr(usize)] - Expressions as an array
- Built-in locale storage implemented as
AtomicUsizewithRelaxedordering - Localization resolves to a simple array index operation
Usage
Add the following to your Cargo.toml:
[]
= "1.4.0"
License
This project is licensed under either of
at your option.