translations

This commit is contained in:
2023-05-06 03:05:46 +02:00
parent 45c130f3d7
commit d066215cf3
5 changed files with 30 additions and 6 deletions

View File

@@ -30,8 +30,8 @@ func set_menu(name: String) -> void:
button.connect(\"pressed\", callable.bindv(action.args))
for node in menu.find_children(\"*\"):
if node.has_method(\"set_text\"):
node.text = translations.tr(node.text)
if \"text\" in node:
node.text = translations.get_message(node.text)
func _on_close_pressed() -> void:
get_tree().quit()
@@ -41,6 +41,9 @@ func _on_action_SetMenu(name: String) -> void:
func _on_action_CheckStartGame() -> void:
print(\"CheckStartGame\")
func _on_action_DisplayEndscreen() -> void:
get_tree().quit()
"
[node name="Root" type="MarginContainer"]

10
rust/Cargo.lock generated
View File

@@ -156,6 +156,15 @@ version = "1.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91"
[[package]]
name = "encoding_rs"
version = "0.8.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "071a31f4ee85403370b58aca746f01041ede6f0da2730960ad001edc2b71b394"
dependencies = [
"cfg-if",
]
[[package]]
name = "exr"
version = "1.6.3"
@@ -425,6 +434,7 @@ version = "0.1.0"
dependencies = [
"base64",
"binrw",
"encoding_rs",
"godot",
"image",
"itertools",

View File

@@ -14,6 +14,7 @@ crate-type = ["cdylib", "lib"]
[dependencies]
itertools = "0.10.5"
unicode-segmentation = "1.10.1"
encoding_rs = "0.8.32"
binrw = "0.11.1"
serde = {version = "1.0.160", features = ["derive"]}
serde-xml-rs = "0.6.0"

View File

@@ -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())

View File

@@ -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)) => {