Skip to content

Commit

Permalink
Add ability to generate development translations for all integrations (
Browse files Browse the repository at this point in the history
  • Loading branch information
frenck authored Feb 2, 2023
1 parent 98198d3 commit 9f9873b
Showing 1 changed file with 32 additions and 19 deletions.
51 changes: 32 additions & 19 deletions script/translations/develop.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()


Expand All @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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

0 comments on commit 9f9873b

Please sign in to comment.