瀏覽代碼

dev (utils): add a script to prioritise translations

Rather than using the catalog script and post processing, make a script
to directly find untranslated entities, count them and sort.
Jason Rumney 3 月之前
父節點
當前提交
21e344d0ed
共有 1 個文件被更改,包括 35 次插入0 次删除
  1. 35 0
      util/translation_candidates.py

+ 35 - 0
util/translation_candidates.py

@@ -0,0 +1,35 @@
+#!/usr/bin/python3
+"""Build a list of candidates for translation
+
+This script was created to prioritise common entities for translation.
+"""
+
+import sys
+
+from custom_components.tuya_local.helpers.device_config import (
+    TuyaDeviceConfig,
+    available_configs,
+)
+
+
+def main() -> int:
+    candidates: dict[str, int] = {}
+
+    for config in available_configs():
+        device = TuyaDeviceConfig(config)
+        for entity in device.all_entities():
+            if entity.name:
+                if entity.config_id in candidates:
+                    candidates[entity.config_id] += 1
+                else:
+                    candidates[entity.config_id] = 1
+
+    sorted_candidates = sorted(
+        candidates.items(), key=lambda item: item[1], reverse=True
+    )
+    for candidate, count in sorted_candidates:
+        print(f"{candidate}: {count}")
+
+
+if __name__ == "__main__":
+    sys.exit(main())