Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
mrtryhard committed Nov 19, 2024
2 parents 6443454 + 89505e0 commit 16abceb
Show file tree
Hide file tree
Showing 7 changed files with 192 additions and 191 deletions.
6 changes: 2 additions & 4 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
### Pull request checklist

_Any relevant description here_

- [ ] This pull request relates to an existing [issue ticket](https://github.com/mrtryhard/qt-ts-tools/issues). If not, create one.
- [ ] [`CHANGELOG.md`](https://github.com/mrtryhard/qt-ts-tools/blob/main/CHANGELOG.md) is updated if relevant.
- [ ] You are aware that your contributions is under [APACHE 2.0 License](https://github.com/mrtryhard/qt-ts-tools/blob/main/CONTRIBUTING.md) unless you specify otherwise.

---

_Any other relevant description here_
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ serde = { version = "1.0.215", features = ["derive"] }
sys-locale = "0.3.2"

[profile.release]
strip = true
lto = true
codegen-units = 1
lto = true
panic = "abort"
strip = true
14 changes: 7 additions & 7 deletions src/commands/extract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ use log::debug;
use crate::ts::{TSNode, TranslationNode, TranslationType};
use crate::{tr, ts};

#[derive(clap::ValueEnum, PartialEq, Debug, Clone)]
pub enum TranslationTypeArg {
Obsolete,
Unfinished,
Vanished,
}

/// Extracts a translation type messages and contexts from the input translation file.
#[derive(Args)]
#[command(disable_help_flag = true)]
Expand All @@ -21,13 +28,6 @@ pub struct ExtractArgs {
pub help: Option<bool>,
}

#[derive(clap::ValueEnum, PartialEq, Debug, Clone)]
pub enum TranslationTypeArg {
Obsolete,
Unfinished,
Vanished,
}

/// Filters the translation file to keep only the messages containing unfinished translations.
pub fn extract_main(args: &ExtractArgs) -> Result<(), String> {
match quick_xml::Reader::from_file(&args.input_path) {
Expand Down
54 changes: 27 additions & 27 deletions src/commands/merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,33 @@ pub struct MergeArgs {
pub help: Option<bool>,
}

// This works by depending on cmp looking up only source and location on messages nodes
// and on context by comparing the names only
pub fn merge_main(args: &MergeArgs) -> Result<(), String> {
let left = load_file(&args.input_left);
let right = load_file(&args.input_right);

if let Err(e) = left {
return Err(tr!(
"error-open-or-parse",
("file", args.input_left.as_str()),
("error", e.to_string())
));
}

if let Err(e) = right {
return Err(tr!(
"error-open-or-parse",
("file", args.input_right.as_str()),
("error", e.to_string())
));
}

let result = merge_ts_nodes(left.unwrap(), right.unwrap(), args.keep_translation);

ts::write_to_output(&args.output_path, &result)
}

/// MessageNode that can be `eq(...)`.
#[derive(Eq, PartialOrd, Clone)]
struct EquatableMessageNode {
Expand Down Expand Up @@ -56,33 +83,6 @@ impl Hash for EquatableMessageNode {
}
}

// This works by depending on cmp looking up only source and location on messages nodes
// and on context by comparing the names only
pub fn merge_main(args: &MergeArgs) -> Result<(), String> {
let left = load_file(&args.input_left);
let right = load_file(&args.input_right);

if let Err(e) = left {
return Err(tr!(
"error-open-or-parse",
("file", args.input_left.as_str()),
("error", e.to_string())
));
}

if let Err(e) = right {
return Err(tr!(
"error-open-or-parse",
("file", args.input_right.as_str()),
("error", e.to_string())
));
}

let result = merge_ts_nodes(left.unwrap(), right.unwrap(), args.keep_translation);

ts::write_to_output(&args.output_path, &result)
}

fn merge_ts_nodes(mut left: TSNode, mut right: TSNode, keep_translation: bool) -> TSNode {
if keep_translation {
debug!("--keep_translation flag is active, the following nodes will NOT be updated from the right-side file: translation, comment, oldcomment, oldsource, encoding");
Expand Down
22 changes: 11 additions & 11 deletions src/commands/shell_completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,6 @@ use clap_complete_nushell::Nushell;
use crate::cli::Cli;
use crate::locale::tr;

#[derive(Args)]
#[command(disable_help_flag = true)]
pub struct ShellCompletionArgs {
#[arg(value_enum, help = tr!("cli-shell-completion-shell"))]
shell: clap_complete_command::Shell,
#[arg(short, long, help = tr!("cli-shell-completion-install"))]
output_path: Option<String>,
#[arg(short, long, action = ArgAction::Help, help = tr!("cli-help"), help_heading = tr!("cli-headers-options"))]
help: Option<bool>,
}

#[derive(Debug, Clone, ValueEnum)]
#[value(rename_all = "lower")]
pub enum GenShell {
Expand All @@ -29,6 +18,17 @@ pub enum GenShell {
Zsh,
}

#[derive(Args)]
#[command(disable_help_flag = true)]
pub struct ShellCompletionArgs {
#[arg(value_enum, help = tr!("cli-shell-completion-shell"))]
shell: clap_complete_command::Shell,
#[arg(short, long, help = tr!("cli-shell-completion-install"))]
output_path: Option<String>,
#[arg(short, long, action = ArgAction::Help, help = tr!("cli-help"), help_heading = tr!("cli-headers-options"))]
help: Option<bool>,
}

impl Generator for GenShell {
fn file_name(&self, name: &str) -> String {
match self {
Expand Down
Loading

0 comments on commit 16abceb

Please sign in to comment.