diff --git a/list_builder.py b/list_builder.py index 4b6db05e..a32bebc3 100755 --- a/list_builder.py +++ b/list_builder.py @@ -32,6 +32,31 @@ def fail(msg, retcode=1): sys.exit(retcode) +def include_translations_in_manifest(app_name, manifest): + for i in os.listdir("locales"): + if not i.endswith("json"): + continue + + if i == "en.json": + continue + + current_lang = i.split(".")[0] + translations = json.load(open(os.path.join("locales", i), "r")) + + key = "%s_manifest_description" % app_name + if key in translations and translations[key]: + manifest["description"][current_lang] = translations[key] + + for category, questions in manifest["arguments"].items(): + for question in questions: + key = "%s_manifest_arguments_%s_%s" % (app_name, category, question["name"]) + if key in translations and translations[key]: + print current_lang, key + question["ask"][current_lang] = translations[key] + + return manifest + + # Main # Create argument parser @@ -102,6 +127,10 @@ for app, info in apps_list.items(): if previous_level != app_level or app_level is None: result_dict[app]["level"] = app_level print("... but has changed of level, updating it from '%s' to '%s'" % (previous_level, app_level)) + + print "update translations but don't download anything" + result_dict[app]['manifest'] = include_translations_in_manifest(app, result_dict[app]['manifest']) + continue # Hosted on GitHub @@ -206,7 +235,7 @@ for app, info in apps_list.items(): 'url': app_url }, 'lastUpdate': timestamp, - 'manifest': manifest, + 'manifest': include_translations_in_manifest(manifest['id'], manifest), 'state': info['state'], 'level': info.get('level', '?') } diff --git a/should_i_rebuild.sh b/should_i_rebuild.sh index 70a2841b..da0ba83a 100644 --- a/should_i_rebuild.sh +++ b/should_i_rebuild.sh @@ -1,5 +1,11 @@ #!/bin/bash +install_hub() { + wget https://github.com/github/hub/releases/download/v2.3.0-pre9/hub-linux-amd64-2.3.0-pre9.tgz + tar xf hub-linux-amd64-2.3.0-pre9.tgz + hub-linux-amd64-2.3.0-pre9/bin/hub pull-request +} + set -ex if [ ! "$1" ] @@ -11,6 +17,7 @@ fi before_official=$(sha256sum official.json) before_community=$(sha256sum community.json) before_dev=$(sha256sum dev.json) +before_pull_commit=$(git show HEAD | head -n 1) git pull @@ -28,3 +35,26 @@ if [ "$before_dev" != "$(sha256sum dev.json)" ] then python ./list_builder.py -g $1 dev.json fi + +if [ "$before_pull_commit" != "$(git show HEAD | head -n 1)" ] +then + python ./update_translations.py + if [ "$(git status -s| grep 'M locales/en.json')" ] + then + git add locales/en.json + git commit -m "[mod] update en.json with new translations" + git push yunohost-bot master + + # uses hub/git-spindle from pypi + # to install: + # $ virtualenv ve + # $ ve/bin/pip install "hub==2.0" + + if [ ! -e hub-linux-amd64-2.3.0-pre9/bin/hub ] + then + install_hub + fi + + hub-linux-amd64-2.3.0-pre9/bin/hub pull-request -h master -m "Update locales/en.json" + fi +fi