Add argparse to find_unused_strings.py so we can pass in --locale rather than hardcoded
This commit is contained in:
parent
9a82831e87
commit
1d94c04551
1 changed files with 14 additions and 4 deletions
|
|
@ -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)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue