From cbcc35319e7b6529ddd24d0de3ddea598499fe77 Mon Sep 17 00:00:00 2001 From: Johannes Date: Sat, 18 Jun 2022 22:36:31 +0200 Subject: [PATCH] add ioBroker localization auto-gen --- .github/issue-close-app.yml | 51 ++++++++++++++++ .github/workflows/iobroker-localization.yml | 35 +++++++++++ HMI/code_gen/localization/iobroker.py | 68 +++++++++++++++++++++ 3 files changed, 154 insertions(+) create mode 100644 .github/issue-close-app.yml create mode 100644 .github/workflows/iobroker-localization.yml create mode 100644 HMI/code_gen/localization/iobroker.py diff --git a/.github/issue-close-app.yml b/.github/issue-close-app.yml new file mode 100644 index 00000000..0ada963a --- /dev/null +++ b/.github/issue-close-app.yml @@ -0,0 +1,51 @@ +# CLOSE ISSUE BOT +# --------------- +# A bot which helps you to close issues that don't include some specific contents. +# See how to use it in https://github.com/offu/close-issue-app. + +# Comment that will be sent if an issue is judged to be closed. +comment: >- + This issue has been automatically closed because the PROBLEM REPORT TEMPLATE is missing or incomplete. + + Filling the template is required so standard questions don't need to be asked again each time. + Our ability to provide assistance is greatly hampered if few minutes are not taken to complete the issue template + with the requested information. The details requested potentially affect which options to pursue. The small amount + of time you will spend completing the template will also help the volunteers, providing assistance to you, to reduce + the time required to help you. + + Please, could you be so kind on completing the [PROBLEM REPORT TEMPLATE](https://github.com/arendst/Tasmota/issues/new/choose) in order to have more information so as to properly help you? + + Thank you for taking the time to report, hopefully it can be resolved soon. + + [Docs](https://tasmota.github.io/docs/) for more information. + + [Discussions](https://github.com/arendst/Tasmota/discussions) for Questions, Feature Requests and Projects. + + [Chat](https://discord.gg/Ks2Kzd4) for more users experience. + + Please check the [Code of Conduct](https://github.com/arendst/Tasmota/blob/development/CODE_OF_CONDUCT.md) and the [Contributing Guideline and Policy](https://github.com/arendst/Tasmota/blob/development/CONTRIBUTING.md) + +issueConfigs: +# There can be several configs for different kind of issues. +- content: +# template 1: bug report + - "PROBLEM DESCRIPTION" + - "REQUESTED INFORMATION" + - "TO REPRODUCE" + - "EXPECTED BEHAVIOUR" +- content: +# template 2: feature request + - "FEATURE DESCRIPTION" + - "ADDITIONAL CONTEXT" + - "PANEL / FIRMWARE VERION" + +# Optional configuration: +# +# whether the keywords are case-insensitive +# default value is false, which means keywords are case-sensitive +caseInsensitive: true +# the label that will be added when the bot close an issue +# The bot will only add a label if this property is set. +label: "template missing/incomplete" +# The issue is judged to be legal if it includes all keywords from any of these two configs. +# Or it will be closed by the app. \ No newline at end of file diff --git a/.github/workflows/iobroker-localization.yml b/.github/workflows/iobroker-localization.yml new file mode 100644 index 00000000..cb7f7fda --- /dev/null +++ b/.github/workflows/iobroker-localization.yml @@ -0,0 +1,35 @@ +name: nextion2text + +on: + pull_request: + paths: + - HMI/code_gen/localization/iobroker.py + - apps/nspanel-lovelace-ui/luibackend/translations/* + - .github/workflows/iobroker-localization.yml + push: + branches: + - main + paths: + - HMI/code_gen/localization/iobroker.py + - apps/nspanel-lovelace-ui/luibackend/translations/* + - .github/workflows/iobroker-localization.yml + +jobs: + gen-nextion-to-text: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + ref: ${{ github.head_ref }} + + - name: Gen ioBroker localization file + continue-on-error: false + run: | + cd apps/nspanel-lovelace-ui/luibackend + python ../../HMI/code_gen/localization/iobroker.py + mv ioBroker_NSPanel_locales.json ../../ioBroker/ioBroker_NSPanel_locales.json + + - uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: Update iobroker localization file + #file_pattern: "**.txt" diff --git a/HMI/code_gen/localization/iobroker.py b/HMI/code_gen/localization/iobroker.py new file mode 100644 index 00000000..d7b4fbe0 --- /dev/null +++ b/HMI/code_gen/localization/iobroker.py @@ -0,0 +1,68 @@ +import os +import json +from collections import defaultdict + +keys = { + 'frontend.ui.card.light.brightness': 'lights.Brightness', +# 'frontend.ui.card.light.brightness': 'lights.Color', + 'frontend.ui.card.light.color_temperature': 'lights.Temperature', + 'backend.component.binary_sensor.state.window.off': 'window.closed', + 'backend.component.binary_sensor.state.window.on': 'window.opened', + 'backend.component.binary_sensor.state.door.off': 'door.closed', + 'backend.component.binary_sensor.state.door.on': 'door.opened', + 'frontend.ui.card.lock.lock': 'lock.LOCK', + 'frontend.ui.card.lock.unlock': 'lock.UNLOCK', + 'frontend.ui.card.cover.position': 'blinds.Position', + 'frontend.ui.card.climate.currently': 'thermostat.Currently', + 'frontend.ui.panel.config.devices.entities.state': 'thermostat.State', + 'frontend.ui.card.climate.operation': 'thermostat.Action', +} + + +langs = ["en_US", "de_DE", "nl_NL", "da_DK", "es_ES", "fr_FR", "it_IT", "ru_RU"] + + +def build_locale_filestring(locale): + if locale in ["zh_CN", "zh_Hans_CN", "zh_Hans"]: + locale = "zh-Hans" + elif locale in ["zh_TW", "zh_Hant_TW", "zh_Hant"]: + locale = "zh-Hant" + elif locale == "en_GB": + locale = "en-GB" + elif locale == "pt_BR": + locale = "pt-BR" + else: + locale = locale.split("_")[0] + + filename = f"{locale}.json" + dir_path = os.path.dirname(os.path.realpath(__file__)) + path_frontend_file = os.path.join(dir_path, "translations", "frontend", filename) + path_backend_file = os.path.join(dir_path, "translations", "backend" , filename) + return path_frontend_file, path_backend_file + +def lookup(path_frontend_file, path_backend_file, lookupstr): + with open(path_frontend_file, 'r', encoding="utf-8") as f, open(path_backend_file, 'r', encoding="utf-8") as b: + translations = { "frontend": json.load(f), "backend": json.load(b)} + res = translations + for k in lookupstr.split("."): + if k in res: + res = res[k] + if type(res) is not str: + print("Warning result is not a String") + return res + +def get_translation(locale, lookupstr): + path_frontend_file, path_backend_file = build_locale_filestring(locale) + res = lookup(path_frontend_file, path_backend_file, lookupstr) + return res + +out = defaultdict(lambda: defaultdict(lambda: defaultdict(dict))) +for src, dst in keys.items(): + dst = dst.split(".") + for lang in langs: + out[dst[0]][dst[1]][lang] = get_translation(lang, src) + +#print(json.dumps(out, indent=4, ensure_ascii=False)) + +with open("ioBroker_NSPanel_locales.json", "wb") as text_file: + text_file.write(json.dumps(out, indent=4, ensure_ascii=False).encode('utf8')) \ No newline at end of file