Add argparse to find_unused_strings.py so we can pass in --locale rather than hardcoded
All checks were successful
CI / test (push) Successful in 5m20s
Lint / test (push) Successful in 31s
Trivy / test (push) Successful in 24s

This commit is contained in:
Miguel Jacq 2025-11-27 11:02:33 +11:00
parent 9a82831e87
commit 1d94c04551
Signed by: mig5
GPG key ID: 59B3F0C24135C6A9

View file

@ -1,5 +1,6 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import argparse
import ast import ast
import json import json
from pathlib import Path from pathlib import Path
@ -9,10 +10,8 @@ from typing import Dict, Set
BASE_DIR = Path(__file__).resolve().parent / "bouquin" BASE_DIR = Path(__file__).resolve().parent / "bouquin"
LOCALES_DIR = BASE_DIR / "locales" LOCALES_DIR = BASE_DIR / "locales"
DEFAULT_LOCALE = "en"
def load_json_keys(locale: str) -> Set[str]:
def load_json_keys(locale: str = DEFAULT_LOCALE) -> Set[str]:
"""Load all keys from the given locale JSON file.""" """Load all keys from the given locale JSON file."""
path = LOCALES_DIR / f"{locale}.json" path = LOCALES_DIR / f"{locale}.json"
with path.open(encoding="utf-8") as f: with path.open(encoding="utf-8") as f:
@ -224,7 +223,18 @@ def collect_used_keys() -> Set[str]:
def main() -> None: def main() -> None:
json_keys = load_json_keys() parser = argparse.ArgumentParser(
description="Find missing or unused strings for a given locale"
)
parser.add_argument(
"--locale",
type=str,
default="en",
help="Locale key e.g en, fr, it",
)
args = parser.parse_args()
json_keys = load_json_keys(args.locale)
used_keys = collect_used_keys() used_keys = collect_used_keys()
unused_keys = sorted(json_keys - used_keys) unused_keys = sorted(json_keys - used_keys)