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 string expressions without using dynamic memory, hash maps, or runtime lookups. All localized strings are stored in fixed-size arrays, and the active locale is stored in an atomic variable, making access extremely fast and thread-safe.
Quick Example
use ;
init_locale!;
expression!;
Features
- O(1) localization lookup
- Zero allocations
no_stdcompatible- Thread-safe global locale (
AtomicUsize) - Macro-based API
- No external dependencies
Design Constraints
- Locales are defined at compile time
- Expressions must be
&'static str
Example With Recommended Project Structure
The recommended usage pattern is to create a dedicated locale module that contains locale initialization and grouped expression modules. For example:
src/
├─ main.rs
└─ locale/
├─ mod.rs # Locale initialization
├─ error.rs # Expression module for error messages
└─ ui.rs # Expression module for UI elements
// mod.rs
use init_locale;
// Initialize locale with two languages
init_locale!;
// error.rs
use crateExpression;
// Expressions can be created manually without the macro
pub const COOKIE_BUTTON: Expression = ;
// ui.rs
use crateLocale;
use expression;
// Recommended way to create expressions using the macro
expression!;
// main.rs (or wherever you want to use the localized strings)
use crate;
use localize;
Usage
Add the following to your Cargo.toml:
[]
= "1.1.0"
How It Works
- Locales are defined as an
enumwith#[repr(usize)] - Each localized string is compiled into a fixed-size
&'static strarray - The active locale is stored as an atomic integer
- Localization resolves to a simple array index operation
License
This project is licensed under either of
at your option.