| Crates.io | anLocales |
| lib.rs | anLocales |
| version | 0.1.5 |
| created_at | 2025-09-24 17:45:04.603398+00 |
| updated_at | 2025-09-26 14:28:52.120085+00 |
| description | library for translating your projects in rust. |
| homepage | |
| repository | https://github.com/akaruinekooff/anLocales |
| max_upload_size | |
| id | 1853474 |
| size | 61,228 |
anLocales β a cross-platform Rust library for working with locales, similar to glibc-locales, but simpler and with C API support.
data_format.jsonlocale.tomltemp/.so/.dll)Linux/macOS:
/usr/share/anlocales/
ββ locales/
β ββ ru_RU/
β β ββ data_format.json
β β ββ locale.toml
β ββ en_US/
ββ temp/ # cache
ββ settings.json # default_locale, fallback_locale
Windows:
C:\ProgramData\anlocales\
ββ locales\
β ββ ru_RU\
β β ββ data_format.json
β β ββ locale.toml
β ββ en_US\
ββ temp\ # cache
ββ settings.json # default_locale, fallback_locale
Example data_format.json:
{
"LC_TIME": {
"days": ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
"months": ["January", "February", "..."],
"date_fmt": "%Y-%m-%d"
},
"LC_NUMERIC": {
"decimal_point": ".",
"thousands_sep": ",",
"grouping": [3]
},
"LC_MONETARY": {
"currency_symbol": "$",
"int_curr_symbol": "USD",
"mon_decimal_point": ".",
"mon_thousands_sep": ",",
"positive_sign": "",
"negative_sign": "-",
"frac_digits": 2,
"p_cs_precedes": true,
"n_cs_precedes": true,
"p_sep_by_space": false,
"n_sep_by_space": false,
"p_sign_posn": 1,
"n_sign_posn": 1
},
"LC_COLLATE": {
"sort_order": "unicode"
},
"PLURAL_RULES": "n != 1"
}
Example locale.toml:
settings = ["Settings"]
exit = ["Exit"]
hello = ["Hello"]
use anlocales::AnLocales;
use chrono::NaiveDate;
fn main() {
let mut anlocales = AnLocales::new();
let ru = anlocales.load_locale("ru_RU");
println!("{}", ru.t("settings")); // Settings in Russian
let today = NaiveDate::from_ymd(2025, 9, 21);
println!("{}", ru.format_date(today)); // 21.09.2025
println!("{}", ru.format_money(1234.56)); // β½1234.56
}
#include "anlocales.h"
#include <stdio.h>
int main() {
AnLocales* al = anlocales_new();
Locale* ru = locale_load(al, "ru_RU");
const char* s = locale_t(ru, "settings");
printf("%s\n", s);
locale_free_str((char*)s);
const char* date = locale_format_date(ru, 2025, 9, 21);
printf("%s\n", date);
locale_free_str((char*)date);
const char* money = locale_format_money(ru, 1234.56);
printf("%s\n", money);
locale_free_str((char*)money);
locale_free(ru);
anlocales_free(al);
}
make
# Outputs:
# dist/libanLocales.so # Linux
# dist/libanLocales.dylib # macOS
rustup target add x86_64-pc-windows-gnu
cargo build --release --target x86_64-pc-windows-gnu
# Outputs:
# target/x86_64-pc-windows-gnu/release/anLocales.dll
# you can run "make" but if its not working use this method
To enable localization in some programs using this library, you need the anLocales library. Follow the instructions for your platform:
I think you already build the library, but if not, you can download from artifacts, or follow the instructions from building guide
libanLocales.solibanLocales.dylibanLocales.dllMove or copy the library to a folder in your systemβs library path. Examples:
Linux/macOS:
cp target/release/libanLocales.so /usr/local/lib/
Windows:
anLocales.dll to a folder in %PATH%.π‘ Tip: On Linux/macOS, if the library is not found, you may need to update the library path:
export LD_LIBRARY_PATH=/path/to/library:$LD_LIBRARY_PATH # Linux export DYLD_LIBRARY_PATH=/path/to/library:$DYLD_LIBRARY_PATH # macOS
# Linux
gcc main.c -L. -lanLocales -o main
# Windows
cl main.c anLocales.dll
temp/ for fast startup.so/.dll)anlocales.h)