mirror of
https://github.com/home-assistant/core.git
synced 2025-07-31 11:18:00 +02:00
Add Translations 2.0 migrate script (#34261)
This commit is contained in:
50
script/translations/migrate.py
Normal file
50
script/translations/migrate.py
Normal file
@ -0,0 +1,50 @@
|
||||
"""Migrate things."""
|
||||
import json
|
||||
from pprint import pprint
|
||||
|
||||
from .const import INTEGRATIONS_DIR
|
||||
from .lokalise import get_api
|
||||
|
||||
MIGRATED = {}
|
||||
|
||||
|
||||
def run():
|
||||
"""Migrate translations."""
|
||||
to_migrate = {}
|
||||
|
||||
for integration in INTEGRATIONS_DIR.iterdir():
|
||||
strings_file = integration / "strings.json"
|
||||
if not strings_file.is_file():
|
||||
continue
|
||||
|
||||
if integration.name in MIGRATED:
|
||||
continue
|
||||
|
||||
strings = json.loads(strings_file.read_text())
|
||||
|
||||
if "title" in strings:
|
||||
from_key = f"component::{integration.name}::config::title"
|
||||
to_key = f"component::{integration.name}::title"
|
||||
to_migrate[from_key] = to_key
|
||||
|
||||
updates = []
|
||||
|
||||
lokalise = get_api()
|
||||
|
||||
print("Gathering IDs")
|
||||
|
||||
for from_key, to_key in to_migrate.items():
|
||||
key_data = lokalise.keys_list({"filter_keys": from_key})
|
||||
if len(key_data) != 1:
|
||||
print(
|
||||
f"Lookin up {from_key} key in Lokalise returns {len(key_data)} results, expected 1"
|
||||
)
|
||||
continue
|
||||
|
||||
updates.append({"key_id": key_data[0]["key_id"], "key_name": to_key})
|
||||
|
||||
pprint(updates)
|
||||
|
||||
print()
|
||||
print("Updating keys")
|
||||
pprint(lokalise.keys_bulk_update(updates).json())
|
Reference in New Issue
Block a user