#translation #json #language

simple-translate-json

Simple mini library made for translations (JSON)

2 releases

0.1.1 Jan 13, 2024
0.1.0 Jan 13, 2024

#122 in #translation

37 downloads per month

MIT license

5KB

simple-translate-json

Simple mini library made for translations (JSON)

Provides system for language translation using serde_json, include_dir and sys_locale The library was made because I couldn't find any simple language library like that

The library simply takes a language directory (that is a include_dir), then searched for a file with the same name as the locale file name should be for example en-us.json (it has to be lowercase)

Example usage:

use include_dir::{Dir, include_dir};
use sys_locale::get_locale;
use simple_translate_json::Translation;

const LANG_DIR: Dir = include_dir!("lang");
let result = Translation::new(get_locale(), LANG_DIR);
assert_eq!(result.get("title"), "example");

lang/en-us.json

{
  "title": "example"
}

lib.rs:

Simple mini library made for translations (JSON)

Provides system for language translation using serde_json, include_dir and sys_locale The library was made because i couldn't find any simple language library like that

The library simply takes a language directory (that is a include_dir), then searched for a file with the same name as the locale The locale file name should be for example en-us.json (it has to be lowercase)

Example usage:

use include_dir::{Dir, include_dir};
use sys_locale::get_locale;
use simple_translate_json::Translation;

const LANG_DIR: Dir = include_dir!("lang");
let result = Translation::new(get_locale(), LANG_DIR);
assert_eq!(result.get("title"), "example");

lang/en-us.json

{
  "title": "example"
}

Dependencies

~0.8–1.4MB
~27K SLoC