Repository: zng-ui/zng (language: rust)

Issue:
Localization from older dependencies
The `cargo zng l10n` command is not removing localization from older dep versions?


Discussion / hints:

Fix patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c481babcb..0f682be24 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,8 @@
 # Unreleased
 
+* Add `cargo zng l10n --clean`.
+    - Add `cargo zng l10n --clean-deps` to remove previously copied localization before new copy.
+    - Add `cargo zng l10n --clean-template` to remove previously scraped files.
 * Add `cargo zng l10n --no-pkg` to skip scraping the target package, only copy localization from dependencies.
 * Don't show keyboard shortcuts in mobile menus.
 * Fix incorrect `TouchInputArgs::position` in nested windows.
diff --git a/crates/cargo-zng/README.md b/crates/cargo-zng/README.md
index ad6f33c45..85a644c89 100644
--- a/crates/cargo-zng/README.md
+++ b/crates/cargo-zng/README.md
@@ -272,6 +272,20 @@ Options:
 
           Use with --package or --manifest-path to not scrap local dependencies.
 
+      --no-pkg
+          Don't scrap the target package.
+
+          Use with --package or --manifest-path to only scrap dependencies.
+
+      --clean-deps
+          Remove all previously copied dependency localization files
+
+      --clean-template
+          Remove all previously scraped resources before scraping
+
+      --clean
+          Same as --clean-deps --clean-template
+
   -m, --macros <MACROS>
           Custom l10n macro names, comma separated
 
diff --git a/crates/cargo-zng/src/l10n.rs b/crates/cargo-zng/src/l10n.rs
index 5fbf03849..405983046 100644
--- a/crates/cargo-zng/src/l10n.rs
+++ b/crates/cargo-zng/src/l10n.rs
@@ -58,6 +58,18 @@ pub struct L10nArgs {
     #[arg(long, action)]
     no_pkg: bool,
 
+    /// Remove all previously copied dependency localization files.
+    #[arg(long, action)]
+    clean_deps: bool,
+
+    /// Remove all previously scraped resources before scraping.
+    #[arg(long, action)]
+    clean_template: bool,
+
+    /// Same as --clean-deps --clean-template
+    #[arg(long, action)]
+    clean: bool,
+
     /// Custom l10n macro names, comma separated
     #[arg(short, long, default_value = "")]
     macros: String,
@@ -121,6 +133,15 @@ pub fn run(mut args: L10nArgs) {
         }
     }
 
+    if args.check {
+        args.clean = false;
+        args.clean_deps = false;
+        args.clean_template = false;
+    } else if args.clean {
+        args.clean_deps = true;
+        args.clean_template = true;
+    }
+
     if !input.is_empty() {
         if output.is_empty() {
             fatal!("--output is required for --input")
@@ -156,6 +177,13 @@ pub fn run(mut args: L10nArgs) {
                 let r = template.write(|file, contents| {
                     let mut output = PathBuf::from(&output);
                     output.push("template");
+
+                    if args.clean_template {
+                        debug_assert!(!args.check);
+                        if let Err(e) = fs::remove_dir_all(&output) {
+                            error!("cannot remove `{}`, {e}", output.display());
+                        }
+                    }
                     util::check_or_create_dir_all(args.check, &output)?;
                     output.push(format!("{}.ftl", if file.is_empty() { "_" } else { file }));
                     util::check_or_write(args.check, output, contents)
@@ -195,6 +223,13 @@ pub fn run(mut args: L10nArgs) {
                 let mut l10n_dir = |lang: Option<&std::ffi::OsStr>| {
                     any = true;
                     let dir = l10n_dir.join(lang.unwrap()).join("deps");
+
+                    if args.clean_deps {
+                        if let Err(e) = std::fs::remove_dir_all(&dir) {
+                            error!("cannot remove `{}`, {e}", dir.display());
+                        }
+                    }
+
                     let ignore_file = dir.join(".gitignore");
 
                     if !ignore_file.exists() {
@@ -217,7 +252,7 @@ pub fn run(mut args: L10nArgs) {
                             if !args.package.is_empty() {
                                 writeln!(
                                     &mut ignore,
-                                    "# Call `cargo zng l10n --package {}{custom_output}` to update",
+                                    "# Call `cargo zng l10n --package {}{custom_output} --no-pkg --no-local --clean-deps` to update",
                                     args.package
                                 )
                                 .unwrap();
@@ -226,7 +261,7 @@ pub fn run(mut args: L10nArgs) {
                                 let path = path.strip_prefix(std::env::current_dir().unwrap()).unwrap_or(path);
                                 writeln!(
                                     &mut ignore,
-                                    "# Call `cargo zng l10n --manifest-path \"{}\"` to update",
+                                    "# Call `cargo zng l10n --manifest-path \"{}\" --no-pkg --no-local --clean-deps` to update",
                                     path.display()
                                 )
                                 .unwrap();
@@ -336,6 +371,9 @@ pub fn run(mut args: L10nArgs) {
                     no_deps: true,
                     no_local: true,
                     no_pkg: false,
+                    clean_deps: false,
+                    clean_template: false,
+                    clean: false,
                     macros: args.macros.clone(),
                     pseudo: String::new(),
                     pseudo_m: String::new(),


Test patch: