1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-27 06:28:31 +00:00

Rename translations dir for integrations (#34494)

This commit is contained in:
Joakim Sørensen
2020-04-22 01:11:05 +02:00
committed by GitHub
parent d06fce6997
commit 730a257f3c
5208 changed files with 55 additions and 25 deletions

View File

@@ -29,6 +29,25 @@ REMOVED_TITLE_MSG = (
"manifest."
)
MOVED_TRANSLATIONS_DIRECTORY_MSG = (
"The '.translations' directory has been moved, the new name is 'translations', "
"starting with Home Assistant 0.111 your translations will no longer "
"load if you do not move/rename this "
)
def check_translations_directory_name(integration: Integration) -> None:
"""Check that the correct name is used for the translations directory."""
legacy_translations = integration.path / ".translations"
translations = integration.path / "translations"
if translations.is_dir():
# No action required
return
if legacy_translations.is_dir():
integration.add_warning("translations", MOVED_TRANSLATIONS_DIRECTORY_MSG)
def find_references(strings, prefix, found):
"""Find references."""
@@ -188,6 +207,9 @@ ONBOARDING_SCHEMA = vol.Schema({vol.Required("area"): {str: str}})
def validate_translation_file(config: Config, integration: Integration, all_strings):
"""Validate translation files for integration."""
if config.specific_integrations:
check_translations_directory_name(integration)
strings_file = integration.path / "strings.json"
references = []

View File

@@ -41,7 +41,7 @@ def find_core():
if not strings.is_file():
continue
translations = int_dir / ".translations" / "en.json"
translations = int_dir / "translations" / "en.json"
strings_json = json.loads(strings.read_text())
translations_json = json.loads(translations.read_text())

View File

@@ -39,7 +39,7 @@ def run_download_docker():
"json",
"--unzip_to",
"/opt/dest",
],
]
)
print()
@@ -78,12 +78,9 @@ def get_component_path(lang, component):
"""Get the component translation path."""
if os.path.isdir(os.path.join("homeassistant", "components", component)):
return os.path.join(
"homeassistant", "components", component, ".translations", f"{lang}.json"
)
else:
return os.path.join(
"homeassistant", "components", ".translations", f"{component}.{lang}.json"
"homeassistant", "components", component, "translations", f"{lang}.json"
)
raise ExitApp(f"Integration {component} not found under homeassistant/components/")
def get_platform_path(lang, component, platform):
@@ -94,7 +91,7 @@ def get_platform_path(lang, component, platform):
"components",
component,
platform,
".translations",
"translations",
f"{lang}.json",
)
else:
@@ -102,7 +99,7 @@ def get_platform_path(lang, component, platform):
"homeassistant",
"components",
component,
".translations",
"translations",
f"{platform}.{lang}.json",
)