Files
kvm/ui/tools/resort_messages.py
Adam Shiervani da5793a117 fix(logging): reset troubleshooting log level after reboot (#1404)
* fix(logging): reset troubleshooting log level after reboot

Restore WARN on boot so temporary troubleshooting verbosity cannot silently fill device storage before rolling logs land. Update the settings copy to describe the reboot reset, add an e2e regression test for the INFO-to-WARN behavior, and make the i18n resort helper accept lint-staged file arguments.

* fix(i18n): avoid formatter churn in locale files

Keep localization message JSON on the repo's existing resort_messages.py formatting so translation-only changes do not explode into full-file diffs. Remove JSON from the generic oxfmt lint-staged rule and restage the locale files in their canonical format.
2026-04-09 11:07:04 +02:00

65 lines
1.8 KiB
Python

#!/usr/bin/env python3
import argparse
import json
from pathlib import Path
def main():
p = argparse.ArgumentParser(
description="Sort translations keys in message *.json files"
)
p.add_argument(
"files", nargs="*", help="specific message JSON files to sort"
)
p.add_argument(
"--path", default="./localization/messages/", help="path to messages *.json"
)
args = p.parse_args()
if args.files:
files = [Path(file) for file in args.files]
missing = [file for file in files if not file.is_file()]
if missing:
print("message file(s) not found:")
for file in missing:
print(f" - {file}")
raise SystemExit(2)
else:
messages_path = Path(args.path)
if not messages_path.is_dir():
print(f"message path is not a directory: {messages_path}")
raise SystemExit(2)
files = list(messages_path.glob("*.json"))
if len(files) == 0:
print(f"no message files (*.json) found in: {messages_path}")
raise SystemExit(3)
for f in files:
print(f"Processing {f.name} ...")
data = json.loads(f.read_text(encoding="utf-8"))
# Keep $schema first if present
schema = None
if "$schema" in data:
schema = data.pop("$schema")
sorted_items = dict(sorted(data.items()))
if schema is not None:
out = {"$schema": schema}
out.update(sorted_items)
else:
out = sorted_items
f.write_text(
json.dumps(out, ensure_ascii=False, indent=4) + "\n", encoding="utf-8"
)
if args.files:
print(f"Processed {len(files)} files")
else:
print(f"Processed {len(files)} files in {messages_path}")
if __name__ == "__main__":
main()