Clean up script for WLED translations (#35260)
parent
3219c380c7
commit
0b8f8db67b
|
@ -324,30 +324,98 @@ def find_frontend_states():
|
|||
migrate_project_keys_translations(FRONTEND_PROJECT_ID, CORE_PROJECT_ID, to_migrate)
|
||||
|
||||
|
||||
def clean_wled():
|
||||
"""Clean WLED strings."""
|
||||
offending_translation = "Wykryto urządzenie [%key:component::wled::title%]"
|
||||
ignore_lang = ["pl"]
|
||||
core_api = get_api(CORE_PROJECT_ID)
|
||||
translations = core_api.keys_list(
|
||||
{
|
||||
"include_translations": 1,
|
||||
"filter_keys": ",".join(
|
||||
[
|
||||
"component::wled::config::flow_title",
|
||||
"component::wled::config::step::user::description",
|
||||
"component::wled::config::step::user::data::host",
|
||||
"component::wled::config::step::zeroconf_confirm::description",
|
||||
"component::wled::config::step::zeroconf_confirm::title",
|
||||
"component::wled::config::error::connection_error",
|
||||
"component::wled::config::abort::already_configured",
|
||||
"component::wled::config::abort::connection_error",
|
||||
]
|
||||
),
|
||||
}
|
||||
)
|
||||
bad_data = {}
|
||||
for translation in translations:
|
||||
bad_key_data = []
|
||||
|
||||
for key_trans in translation["translations"]:
|
||||
if (
|
||||
key_trans["translation"] == offending_translation
|
||||
and key_trans["language_iso"] not in ignore_lang
|
||||
):
|
||||
bad_key_data.append(key_trans["translation_id"])
|
||||
|
||||
if bad_key_data:
|
||||
bad_data[translation["key_id"]] = bad_key_data
|
||||
|
||||
pprint(
|
||||
[
|
||||
{
|
||||
"key_id": key_id,
|
||||
"translations": [
|
||||
{"translation_id": trans_id, "translation": ""}
|
||||
for trans_id in trans_ids
|
||||
],
|
||||
}
|
||||
for key_id, trans_ids in bad_data.items()
|
||||
]
|
||||
)
|
||||
print(sum(len(val) for val in bad_data.values()))
|
||||
|
||||
return
|
||||
|
||||
core_api.keys_bulk_update(
|
||||
[
|
||||
{
|
||||
"key_id": key_id,
|
||||
"translations": [
|
||||
{"translation_id": trans_id, "translation": ""}
|
||||
for trans_id in trans_ids
|
||||
],
|
||||
}
|
||||
for key_id, trans_ids in bad_data.items()
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
def run():
|
||||
"""Migrate translations."""
|
||||
clean_wled()
|
||||
|
||||
# Import new common keys
|
||||
rename_keys(
|
||||
CORE_PROJECT_ID,
|
||||
{
|
||||
"component::netatmo::config::step::pick_implementation::title": "common::config_flow::title::oauth2_pick_implementation",
|
||||
"component::doorbird::config::step::user::data::username": "common::config_flow::data::username",
|
||||
"component::doorbird::config::step::user::data::password": "common::config_flow::data::password",
|
||||
"component::adguard::config::step::user::data::host": "common::config_flow::data::host",
|
||||
"component::adguard::config::step::user::data::port": "common::config_flow::data::port",
|
||||
"component::zha::config::step::user::data::usb_path": "common::config_flow::data::usb_path",
|
||||
"component::smartthings::config::step::pat::data::access_token": "common::config_flow::data::access_token",
|
||||
"component::airvisual::config::step::geography::data::api_key": "common::config_flow::data::api_key",
|
||||
"component::doorbird::config::error::invalid_auth": "common::config_flow::error::invalid_auth",
|
||||
"component::airvisual::config::error::invalid_api_key": "common::config_flow::error::invalid_api_key",
|
||||
"component::tibber::config::error::invalid_access_token": "common::config_flow::error::invalid_access_token",
|
||||
"component::doorbird::config::error::unknown": "common::config_flow::error::unknown",
|
||||
"component::life360::config::abort::user_already_configured": "common::config_flow::abort::already_configured_account",
|
||||
"component::xiaomi_miio::config::abort::already_configured": "common::config_flow::abort::already_configured_device",
|
||||
"component::netatmo::config::abort::missing_configuration": "common::config_flow::abort::oauth2_missing_configuration",
|
||||
"component::netatmo::config::abort::authorize_url_timeout": "common::config_flow::abort::oauth2_authorize_url_timeout",
|
||||
},
|
||||
)
|
||||
# rename_keys(
|
||||
# CORE_PROJECT_ID,
|
||||
# {
|
||||
# "component::netatmo::config::step::pick_implementation::title": "common::config_flow::title::oauth2_pick_implementation",
|
||||
# "component::doorbird::config::step::user::data::username": "common::config_flow::data::username",
|
||||
# "component::doorbird::config::step::user::data::password": "common::config_flow::data::password",
|
||||
# "component::adguard::config::step::user::data::host": "common::config_flow::data::host",
|
||||
# "component::adguard::config::step::user::data::port": "common::config_flow::data::port",
|
||||
# "component::zha::config::step::user::data::usb_path": "common::config_flow::data::usb_path",
|
||||
# "component::smartthings::config::step::pat::data::access_token": "common::config_flow::data::access_token",
|
||||
# "component::airvisual::config::step::geography::data::api_key": "common::config_flow::data::api_key",
|
||||
# "component::doorbird::config::error::invalid_auth": "common::config_flow::error::invalid_auth",
|
||||
# "component::airvisual::config::error::invalid_api_key": "common::config_flow::error::invalid_api_key",
|
||||
# "component::tibber::config::error::invalid_access_token": "common::config_flow::error::invalid_access_token",
|
||||
# "component::doorbird::config::error::unknown": "common::config_flow::error::unknown",
|
||||
# "component::life360::config::abort::user_already_configured": "common::config_flow::abort::already_configured_account",
|
||||
# "component::xiaomi_miio::config::abort::already_configured": "common::config_flow::abort::already_configured_device",
|
||||
# "component::netatmo::config::abort::missing_configuration": "common::config_flow::abort::oauth2_missing_configuration",
|
||||
# "component::netatmo::config::abort::authorize_url_timeout": "common::config_flow::abort::oauth2_authorize_url_timeout",
|
||||
# },
|
||||
# )
|
||||
|
||||
# find_frontend_states()
|
||||
|
||||
|
|
Loading…
Reference in New Issue