mirror of
https://github.com/Theaninova/mhlib.git
synced 2026-01-21 01:12:58 +00:00
translations
This commit is contained in:
@@ -5,6 +5,7 @@ use crate::formats::sprites::Sprites;
|
||||
use crate::formats::txt::{decrypt_txt, DecryptError};
|
||||
use crate::formats::ui_xml::UiTag;
|
||||
use binrw::BinRead;
|
||||
use encoding_rs::WINDOWS_1252;
|
||||
use itertools::Itertools;
|
||||
use std::collections::HashMap;
|
||||
use std::ffi::OsStr;
|
||||
@@ -82,7 +83,7 @@ where
|
||||
.file_stem()
|
||||
.and_then(OsStr::to_str)
|
||||
.ok_or(Error::Custom("Stem".to_string()))?;
|
||||
let decr = decrypt_txt(data.into_iter()).map_err(|e| Error::DecryptError(e))?;
|
||||
let decr = decrypt_txt(data.into_iter()).map_err(Error::DecryptError)?;
|
||||
if stem.starts_with("tile_collision") {
|
||||
Ok(DatafileFile::TileCollision(decr))
|
||||
} else if stem == "sprites" {
|
||||
@@ -94,8 +95,9 @@ where
|
||||
}
|
||||
}
|
||||
"csv" => Ok(DatafileFile::Translations(
|
||||
String::from_utf8(data)
|
||||
.unwrap()
|
||||
WINDOWS_1252
|
||||
.decode(data.as_slice())
|
||||
.0
|
||||
.split('\n')
|
||||
.map(|l| l.trim())
|
||||
.filter(|l| !l.is_empty())
|
||||
|
||||
@@ -187,8 +187,16 @@ impl ResourceFormatLoaderVirtual for DatafileLoader {
|
||||
Ok(DatafileFile::Translations(translations)) => {
|
||||
let mut translation = Translation::new();
|
||||
for (key, message) in translations {
|
||||
translation.add_message(key.into(), message.join("\n").into(), "".into());
|
||||
translation.add_message(
|
||||
format!("%{}%", key).into(),
|
||||
message.join("\n").into(),
|
||||
"".into(),
|
||||
);
|
||||
}
|
||||
self.save_to_cache(
|
||||
translation.share().upcast(),
|
||||
format!("{}.res", datafile_path),
|
||||
);
|
||||
translation.to_variant()
|
||||
}
|
||||
Ok(DatafileFile::Vorbis(vorbis)) => {
|
||||
|
||||
Reference in New Issue
Block a user