anLocales

Crates.ioanLocales
lib.rsanLocales
version0.1.5
created_at2025-09-24 17:45:04.603398+00
updated_at2025-09-26 14:28:52.120085+00
descriptionlibrary for translating your projects in rust.
homepage
repositoryhttps://github.com/akaruinekooff/anLocales
max_upload_size
id1853474
size61,228
George Kulikov (BrightCat14)

documentation

README

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,
    "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"]

⚑ 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

Installing anLocales Library

To enable localization in some programs using this library, you need the anLocales library. Follow the instructions for your platform:

1. Download or build the library

I think you already build the library, but if not, you can download from artifacts, or follow the instructions from building guide

  • After building, you will have one of the compiled libraries (depending on the platform):
    • Linux: libanLocales.so
    • macOS: libanLocales.dylib
    • Windows: anLocales.dll

2. Place the library

  • Move 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:

      • Copy 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

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)
Commit count: 35

cargo fmt