mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-07-08 15:01:00 +02:00
Improve language export and error handling
Refactor language handling and error messages in the script.
This commit is contained in:
@@ -53,30 +53,31 @@ sed -i 's/"\.\$updatediv\.\"//g' "$HOME"/BirdNET-Pi/homepage/views.php
|
|||||||
|
|
||||||
# Correct language labels according to birdnet.conf
|
# Correct language labels according to birdnet.conf
|
||||||
echo "... adapting labels according to birdnet.conf"
|
echo "... adapting labels according to birdnet.conf"
|
||||||
if export "$(grep "^DATABASE_LANG" /config/birdnet.conf)"; then
|
if grep -q '^DATABASE_LANG=' /config/birdnet.conf; then
|
||||||
|
export "$(grep -m1 '^DATABASE_LANG=' /config/birdnet.conf)"
|
||||||
bashio::log.info "Setting language to ${DATABASE_LANG:-en}"
|
bashio::log.info "Setting language to ${DATABASE_LANG:-en}"
|
||||||
|
|
||||||
if [[ -f "$HOME/BirdNET-Pi/scripts/utils/maintainer.py" ]]; then
|
if [[ -f "$HOME/BirdNET-Pi/scripts/utils/maintainer.py" ]]; then
|
||||||
PYTHONPATH="$HOME/BirdNET-Pi:$HOME/BirdNET-Pi/scripts:$HOME/BirdNET-Pi/scripts/utils:${PYTHONPATH:-}" \
|
PYTHONPATH="$HOME/BirdNET-Pi:$HOME/BirdNET-Pi/scripts:$HOME/BirdNET-Pi/scripts/utils:${PYTHONPATH:-}" \
|
||||||
python3 - <<'PY'
|
python3 - <<'PY' 1>/dev/null
|
||||||
import importlib.util
|
import importlib.util
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
home = os.environ.get("HOME", "/home/pi")
|
home = os.environ.get("HOME", "/home/pi")
|
||||||
birdnet_root = os.path.join(home, "BirdNET-Pi")
|
birdnet_root = os.path.join(home, "BirdNET-Pi")
|
||||||
for path in (birdnet_root, os.path.join(birdnet_root, "scripts"), os.path.join(birdnet_root, "scripts", "utils")):
|
for path in (birdnet_root,
|
||||||
|
os.path.join(birdnet_root, "scripts"),
|
||||||
|
os.path.join(birdnet_root, "scripts", "utils")):
|
||||||
if path not in sys.path:
|
if path not in sys.path:
|
||||||
sys.path.insert(0, path)
|
sys.path.insert(0, path)
|
||||||
|
|
||||||
if importlib.util.find_spec("scripts.utils.maintainer") is None:
|
if importlib.util.find_spec("scripts.utils.maintainer") is None:
|
||||||
print("Language maintainer module not found; skipping translation generation.")
|
raise RuntimeError("Language maintainer module not found; skipping.")
|
||||||
raise SystemExit(0)
|
|
||||||
|
|
||||||
from scripts.utils.maintainer import create_language
|
from scripts.utils.maintainer import create_language
|
||||||
|
|
||||||
database_lang = os.environ.get("DATABASE_LANG", "en")
|
database_lang = os.environ.get("DATABASE_LANG", "en")
|
||||||
print(f"Creating translations for {database_lang}")
|
|
||||||
create_language(database_lang)
|
create_language(database_lang)
|
||||||
PY
|
PY
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user