Add ability to generate development translations for all integrations (#87197)
This commit is contained in:
parent
98198d3c1f
commit
9f9873b39a
1 changed files with 32 additions and 19 deletions
|
@ -27,6 +27,7 @@ def get_arguments() -> argparse.Namespace:
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--integration", type=valid_integration, help="Integration to process."
|
"--integration", type=valid_integration, help="Integration to process."
|
||||||
)
|
)
|
||||||
|
parser.add_argument("--all", action="store_true", help="Process all integrations.")
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
|
@ -47,7 +48,7 @@ def flatten_translations(translations):
|
||||||
key_stack.pop()
|
key_stack.pop()
|
||||||
else:
|
else:
|
||||||
stack.pop()
|
stack.pop()
|
||||||
if len(key_stack) > 0:
|
if key_stack:
|
||||||
key_stack.pop()
|
key_stack.pop()
|
||||||
|
|
||||||
return flattened_translations
|
return flattened_translations
|
||||||
|
@ -89,29 +90,13 @@ def substitute_reference(value, flattened_translations):
|
||||||
return new
|
return new
|
||||||
|
|
||||||
|
|
||||||
def run():
|
def run_single(translations, flattened_translations, integration):
|
||||||
"""Run the script."""
|
"""Run the script for a single integration."""
|
||||||
args = get_arguments()
|
|
||||||
if args.integration:
|
|
||||||
integration = args.integration
|
|
||||||
else:
|
|
||||||
integration = None
|
|
||||||
while (
|
|
||||||
integration is None
|
|
||||||
or not Path(f"homeassistant/components/{integration}").exists()
|
|
||||||
):
|
|
||||||
if integration is not None:
|
|
||||||
print(f"Integration {integration} doesn't exist!")
|
|
||||||
print()
|
|
||||||
integration = input("Integration to process: ")
|
|
||||||
|
|
||||||
translations = upload.generate_upload_data()
|
|
||||||
|
|
||||||
if integration not in translations["component"]:
|
if integration not in translations["component"]:
|
||||||
print("Integration has no strings.json")
|
print("Integration has no strings.json")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
flattened_translations = flatten_translations(translations)
|
|
||||||
integration_strings = translations["component"][integration]
|
integration_strings = translations["component"][integration]
|
||||||
|
|
||||||
translations["component"][integration] = substitute_translation_references(
|
translations["component"][integration] = substitute_translation_references(
|
||||||
|
@ -129,4 +114,32 @@ def run():
|
||||||
|
|
||||||
download.write_integration_translations()
|
download.write_integration_translations()
|
||||||
|
|
||||||
|
print(f"Processed {integration}")
|
||||||
|
|
||||||
|
|
||||||
|
def run():
|
||||||
|
"""Run the script."""
|
||||||
|
args = get_arguments()
|
||||||
|
translations = upload.generate_upload_data()
|
||||||
|
flattened_translations = flatten_translations(translations)
|
||||||
|
|
||||||
|
if args.all:
|
||||||
|
for integration in translations["component"]:
|
||||||
|
run_single(translations, flattened_translations, integration)
|
||||||
|
return 0
|
||||||
|
|
||||||
|
if args.integration:
|
||||||
|
integration = args.integration
|
||||||
|
else:
|
||||||
|
integration = None
|
||||||
|
while (
|
||||||
|
integration is None
|
||||||
|
or not Path(f"homeassistant/components/{integration}").exists()
|
||||||
|
):
|
||||||
|
if integration is not None:
|
||||||
|
print(f"Integration {integration} doesn't exist!")
|
||||||
|
print()
|
||||||
|
integration = input("Integration to process: ")
|
||||||
|
|
||||||
|
run_single(translations, flattened_translations, integration)
|
||||||
return 0
|
return 0
|
||||||
|
|
Loading…
Add table
Reference in a new issue