mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 01:08:12 +00:00
Add ability to generate development translations for all integrations (#87197)
This commit is contained in:
parent
98198d3c1f
commit
9f9873b39a
@ -27,6 +27,7 @@ def get_arguments() -> argparse.Namespace:
|
||||
parser.add_argument(
|
||||
"--integration", type=valid_integration, help="Integration to process."
|
||||
)
|
||||
parser.add_argument("--all", action="store_true", help="Process all integrations.")
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
@ -47,7 +48,7 @@ def flatten_translations(translations):
|
||||
key_stack.pop()
|
||||
else:
|
||||
stack.pop()
|
||||
if len(key_stack) > 0:
|
||||
if key_stack:
|
||||
key_stack.pop()
|
||||
|
||||
return flattened_translations
|
||||
@ -89,29 +90,13 @@ def substitute_reference(value, flattened_translations):
|
||||
return new
|
||||
|
||||
|
||||
def run():
|
||||
"""Run the script."""
|
||||
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()
|
||||
def run_single(translations, flattened_translations, integration):
|
||||
"""Run the script for a single integration."""
|
||||
|
||||
if integration not in translations["component"]:
|
||||
print("Integration has no strings.json")
|
||||
sys.exit(1)
|
||||
|
||||
flattened_translations = flatten_translations(translations)
|
||||
integration_strings = translations["component"][integration]
|
||||
|
||||
translations["component"][integration] = substitute_translation_references(
|
||||
@ -129,4 +114,32 @@ def run():
|
||||
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user