diff --git a/src/args.rs b/src/args.rs index 75566d9..82834e0 100644 --- a/src/args.rs +++ b/src/args.rs @@ -345,6 +345,11 @@ pub struct Arg { /// If not specified, the first language will be used. pub artemis_panmimisoft_txt_lang: Option, #[cfg(feature = "artemis-panmimisoft")] + #[arg(long, global = true, action = ArgAction::SetTrue, requires = "artemis_panmimisoft_txt_lang")] + /// Enable multiple language support for single language Artemis TXT (ぱんみみそふと) script. + /// --artemis-panmimisoft-txt-lang must be set when enabling this. + pub artemis_panmimisoft_txt_multi_lang: bool, + #[cfg(feature = "artemis-panmimisoft")] #[arg(long, global = true)] /// The path to the tag.ini file, which contains the tags to be ignored when finding names in Artemis TXT script (ぱんみみそふと). pub artemis_panmimisoft_txt_tag_ini: Option, diff --git a/src/main.rs b/src/main.rs index e31467e..72b7c0e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3303,6 +3303,8 @@ fn main() { zopfli_iterations_without_improvement: arg.zopfli_iterations_without_improvement, #[cfg(feature = "zopfli")] zopfli_maximum_block_splits: arg.zopfli_maximum_block_splits, + #[cfg(feature = "artemis-panmimisoft")] + artemis_panmimisoft_txt_multi_lang: arg.artemis_panmimisoft_txt_multi_lang, }); match &arg.command { args::Command::Export { input, output } => { diff --git a/src/scripts/artemis/panmimisoft/txt.rs b/src/scripts/artemis/panmimisoft/txt.rs index 32d33a1..500d86a 100644 --- a/src/scripts/artemis/panmimisoft/txt.rs +++ b/src/scripts/artemis/panmimisoft/txt.rs @@ -860,6 +860,7 @@ pub struct TxtScript { tree: ParsedScript, blacklist_names: Arc>, lang: Option, + multi_lang: bool, } impl TxtScript { @@ -872,6 +873,7 @@ impl TxtScript { tree, blacklist_names: config.artemis_panmimisoft_txt_blacklist_names.clone(), lang: config.artemis_panmimisoft_txt_lang.clone(), + multi_lang: config.artemis_panmimisoft_txt_multi_lang, }) } } @@ -1108,6 +1110,13 @@ impl Script for TxtScript { if !has_printlang { let mut adv_started = false; let mut started_line: Option = None; + if self.multi_lang && lang.is_none() { + return Err(anyhow::anyhow!( + "Multi-language import requires a specified language. Use --artemis-panmimisoft-txt-lang to set the language." + )); + } else if !self.multi_lang { + lang = None; + } while current_line < output.len() { let line = output[current_line].clone(); match &line { @@ -1161,7 +1170,21 @@ impl Script for TxtScript { )); } } - let nodes = XMLTextParser::new(&message, "", true).parse()?; + let mut nodes = XMLTextParser::new( + &message, + lang.as_ref().map(|s| s.as_str()).unwrap_or(""), + !self.multi_lang, + ) + .parse()?; + if self.multi_lang { + // Add a printlang tag + nodes.push(ParsedLine::Line(TxtLine(vec![TxtLineNode::Tag( + TagNode { + name: "printlang".to_string(), + attributes: Vec::new(), + }, + )]))); + } let ori_len = (current_line - start) as isize; let new_len = nodes.len() as isize; for _ in start..current_line { @@ -1199,7 +1222,10 @@ impl Script for TxtScript { } } let mut node = node.clone(); - node.tag_set_attr("text", Some(message)); + node.tag_set_attr( + lang.as_ref().map(|s| s.as_str()).unwrap_or("text"), + Some(message), + ); let block = &mut output[current_line]; if let ParsedLine::Line(txt_line) = block { txt_line[i] = node; diff --git a/src/types.rs b/src/types.rs index ee9ed74..12bf6c4 100644 --- a/src/types.rs +++ b/src/types.rs @@ -430,6 +430,10 @@ pub struct ExtraConfig { /// Specify the language of Artemis TXT (ぱんみみそふと) script. /// If not specified, the first language will be used. pub artemis_panmimisoft_txt_lang: Option, + #[cfg(feature = "artemis-panmimisoft")] + /// Enable multiple language support for single language Artemis TXT (ぱんみみそふと) script. + /// artemis_panmimisoft_txt_lang must be set when enabling this. + pub artemis_panmimisoft_txt_multi_lang: bool, #[cfg(feature = "lossless-audio")] /// Audio format for output lossless audio files. pub lossless_audio_fmt: LosslessAudioFormat,