[][src]Crate genie_lang

genie-lang reads language files into a map of UTF-8 strings. All three major language file types used by Age of Empires versions are supported: DLLs, INI files, and HD Edition's key-value format.

DLLs are used by the original games. INI files are used for Voobly mods, and can be used with a standard AoC installation through the aoc-language-ini mod.

DLLs

use genie_lang::LangFile;
use std::fs::File;
let f = File::open("./test/dlls/language_x1_p1.dll").unwrap();
let lang_file = LangFile::from_dll(f).unwrap();
assert_eq!(lang_file.get(30177), Some("Turbo Random Map - Buildings create units faster, villagers gather faster, build faster, and carry more."));
assert_eq!(lang_file.get(20156), Some("<b>Byzantines<b> \nDefensive civilization \n· Buildings +10% HPs Dark, +20% Feudal, \n +30% Castle, +40% Imperial Age \n· Camels, skirmishers, Pikemen, Halberdiers cost -25% \n· Fire ships +20% attack \n· Advance to Imperial Age costs -33% \n· Town Watch free \n\n<b>Unique Unit:<b> Cataphract (cavalry) \n\n<b>Unique Tech:<b> Logistica (Cataphracts cause trample damage) \n\n<b>Team Bonus:<b> Monks +50% heal speed"));

INI files

use genie_lang::LangFile;
use std::io::Cursor;
let text = br#"
46523=The Uighurs will join if you kill Ornlu the wolf and return to tell the tale.
; a comment
46524=Uighurs: Yes, that is the pelt of the great wolf. We will join you, Genghis Khan. And to seal the agreement, we will give you the gift of flaming arrows!
"#;
let f = Cursor::new(&text[..]);
let lang_file = LangFile::from_ini(f).unwrap();
assert_eq!(lang_file.get(46523), Some("The Uighurs will join if you kill Ornlu the wolf and return to tell the tale."));

HD key-value files

use genie_lang::LangFile;
use std::io::Cursor;
let text = br#"
46523 "The Uighurs will join if you kill Ornlu the wolf and return to tell the tale."
46524 "Uighurs: Yes, that is the pelt of the great wolf. We will join you, Genghis Khan. And to seal the agreement, we will give you the gift of flaming arrows!"
46604 "Kill the traitor, Kushluk.\n\nPrevent the tent of Genghis Khan (Wonder) from being destroyed."
LOBBYBROWSER_DATMOD_TITLE_FORMAT "DatMod: \"%s\""
"#;
let f = Cursor::new(&text[..]);
let lang_file = LangFile::from_keyval(f).unwrap();
assert_eq!(lang_file.get(46523), Some("The Uighurs will join if you kill Ornlu the wolf and return to tell the tale."));
assert_eq!(lang_file.get_named("LOBBYBROWSER_DATMOD_TITLE_FORMAT"), Some(r#"DatMod: "%s""#));

Creating a file from scratch

use genie_lang::LangFile;
use std::str;
let mut lang_file = LangFile::default();
lang_file.set(46604, "Kill the traitor, Kushluk.\n\nPrevent the tent of Genghis Khan (Wonder) from being destroyed.");
lang_file.set_named("LOBBYBROWSER_DATMOD_TITLE_FORMAT", r#"DatMod: "%s""#);
let mut out = vec![];
lang_file.write_to_ini(&mut out).unwrap();
assert_eq!(
    str::from_utf8(&out).unwrap(),
    r"46604=Kill the traitor, Kushluk.\n\nPrevent the tent of Genghis Khan (Wonder) from being destroyed.
");
let mut out = vec![];
lang_file.write_to_keyval(&mut out).unwrap();
assert_eq!(
    str::from_utf8(&out).unwrap(),
    r#"46604 "Kill the traitor, Kushluk.\n\nPrevent the tent of Genghis Khan (Wonder) from being destroyed."

LOBBYBROWSER_DATMOD_TITLE_FORMAT "DatMod: \"%s\""
"#);

Structs

LangFile

A file containing language strings.

Enums

LoadError

Errors that may occur when loading a language file.