anLocales 0.1.0

library for translating your projects in rust.
Documentation

anLocales

anLocales — a cross-platform Rust library for working with locales, similar to glibc-locales, but simpler and with C API support.

  • Supports LC_TIME, LC_NUMERIC, LC_MONETARY, LC_COLLATE, plural rules
  • Date/number formats in data_format.json
  • Interface strings in locale.toml
  • Caching in temp/
  • C API compatible (.so/.dll)

📁 Locale Directory Structure

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
  },
  "LC_COLLATE": {
    "sort_order": "unicode"
  },
  "PLURAL_RULES": "n != 1"
}

Example locale.toml:

settings = "Settings"
exit = "Exit"
hello = "Hello"

⚡ Quick Start (Rust)

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
}

🔗 Using from C

#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);
}

🛠 Building

*nix

make
# Outputs:
# dist/libanLocales.so  # Linux
# dist/libanLocales.dylib # macOS

Windows

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

Linking in C

# Linux
gcc main.c -L. -lanLocales -o main
# Windows
cl main.c anLocales.dll

💡 Features

  • Caching loaded locales in temp/ for fast startup
  • Fallback locale if a key is missing
  • Extendable LC_* structure (add LC_MESSAGES, LC_MONETARY, etc.)
  • Cross-platform (.so/.dll)
  • Full C API compatible (anlocales.h)