Skip to content

Commit

Permalink
Add languages
Browse files Browse the repository at this point in the history
  • Loading branch information
PabstMirror committed Dec 9, 2024
1 parent fe06fb8 commit d8aee84
Show file tree
Hide file tree
Showing 4 changed files with 296 additions and 10 deletions.
16 changes: 16 additions & 0 deletions libs/stringtable/src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ pub struct Key {
#[serde(skip_serializing_if = "Option::is_none", serialize_with = "min_escape")]
#[serde(alias = "dutch", alias = "DUTCH")]
dutch: Option<String>,
#[serde(skip_serializing_if = "Option::is_none", serialize_with = "min_escape")]
#[serde(alias = "ukrainian", alias = "UKRAINIAN")]
ukrainian: Option<String>,
#[serde(skip_serializing_if = "Option::is_none", serialize_with = "min_escape")]
#[serde(alias = "danish", alias = "DANISH")]
danish: Option<String>,
}

impl Key {
Expand Down Expand Up @@ -215,4 +221,14 @@ impl Key {
pub fn dutch(&self) -> Option<&str> {
self.dutch.as_deref()
}

#[must_use]
pub fn ukrainian(&self) -> Option<&str> {
self.ukrainian.as_deref()
}

#[must_use]
pub fn danish(&self) -> Option<&str> {
self.danish.as_deref()
}
}
23 changes: 23 additions & 0 deletions libs/stringtable/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,29 @@ pub use package::Package;
pub use totals::Totals;
use tracing::error;

static ALL_LANGUAGES: [&str; 20] = [
"English",
"Czech",
"French",
"Spanish",
"Italian",
"Polish",
"Portuguese",
"Russian",
"German",
"Korean",
"Japanese",
"Chinese",
"Chinesesimp",
"Turkish",
"Dutch",
"Finnish",
"Ukrainian",
"Swedish",
"Norwegian",
"Danish",
];

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Project {
#[serde(rename = "@name")]
Expand Down
37 changes: 27 additions & 10 deletions libs/stringtable/src/rapify.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use crate::{Key, Project};
use crate::{Key, Project, ALL_LANGUAGES};
use hemtt_workspace::WorkspacePath;
use tracing::warn;

static ALL_LANGUAGES: [&str; 14] = ["English", "Czech", "French", "Spanish", "Italian", "Polish", "Portuguese", "Russian", "German", "Korean", "Japanese", "Chinese", "Chinesesimp", "Turkish"];

#[derive(Default)]
struct XmlbLayout {
// 4 byte numbers, little end?, nul term strings
Expand Down Expand Up @@ -53,13 +51,11 @@ fn rapify(project: &Project) -> Option<XmlbLayout> {
let mut data: XmlbLayout = XmlbLayout::default();

// Restructure translations: flat for each language
let mut all_keys: Vec<String> = Vec::new();
let mut all_translations: Vec<Vec<String>> = vec![Vec::new(); ALL_LANGUAGES.len()];


let mut all_keys: Vec<String> = Vec::with_capacity(20);
let mut all_translations: Vec<Vec<String>> = vec![Vec::with_capacity(20); ALL_LANGUAGES.len()];

for package in project.packages() {
for package_inner in package.containers() { // ugh
for package_inner in package.containers() {
for key in package_inner.keys() {
all_keys.push(key.id().into());
// Make sure we can translate everything
Expand Down Expand Up @@ -103,7 +99,7 @@ fn rapify(project: &Project) -> Option<XmlbLayout> {
// Languages
for translations in all_translations {
debug_assert_eq!(translations.len(), all_keys.len());
let mut translation_buffer: Vec<u8> = Vec::new();
let mut translation_buffer: Vec<u8> = Vec::with_capacity(10 * translations.len());
write_int(
&mut translation_buffer,
i32::try_from(translations.len()).expect("overflow"),
Expand Down Expand Up @@ -137,7 +133,28 @@ fn rapify(project: &Project) -> Option<XmlbLayout> {
}

fn get_translations(key: &Key, all_translations: &mut [Vec<String>]) -> bool {
let tranlations = [key.english(), key.czech(), key.french(), key.spanish(), key.italian(), key.polish(), key.portuguese(), key.russian(), key.german(), key.korean(), key.japanese(), key.chinese(), key.chinesesimp(), key.turkish()];
let tranlations = [
key.english(),
key.czech(),
key.french(),
key.spanish(),
key.italian(),
key.polish(),
key.portuguese(),
key.russian(),
key.german(),
key.korean(),
key.japanese(),
key.chinese(),
key.chinesesimp(),
key.turkish(),
key.dutch(),
key.finnish(),
key.ukrainian(),
key.swedish(),
key.norwegian(),
key.danish(),
];
debug_assert_eq!(tranlations.len(), ALL_LANGUAGES.len()); // needs to be synced

for (index, result) in tranlations.into_iter().enumerate() {
Expand Down
Loading

0 comments on commit d8aee84

Please sign in to comment.