diff --git a/src/app.py b/src/app.py index 0eb06d33b..01d5cc7eb 100644 --- a/src/app.py +++ b/src/app.py @@ -1972,24 +1972,47 @@ def _get_manifest_of_app(path): def _parse_app_doc_and_notifications(path): - # FIXME: need to find a way to handle i18n in there (file named FOOBAR_fr.md etc.) - doc = {} - for pagename in glob.glob(os.path.join(path, "doc") + "/*.md"): - name = os.path.basename(pagename)[:-len('.md')] - doc[name] = read_file(pagename).strip() + for filepath in glob.glob(os.path.join(path, "doc") + "/*.md"): + + # to be improved : [a-z]{2,3} is a clumsy way of parsing the + # lang code ... some lang code are more complex that this é_è + m = re.match("([A-Z]*)(_[a-z]{2,3})?.md", filepath.split("/")[-1]) + + if not m: + # FIXME: shall we display a warning ? idk + continue + pagename, lang = m.groups() + lang = lang.strip("_") if lang else "en" + + if pagename not in doc: + doc[pagename] = {} + doc[pagename][lang] = read_file(filepath).strip() notifications = {} for step in ["pre_install", "post_install", "pre_upgrade", "post_upgrade"]: notifications[step] = {} - if os.path.exists(os.path.join(path, "doc", "notifications", f"{step}.md")): - notifications[step]["main"] = read_file(os.path.join(path, "doc", "notifications", f"{step}.md")).strip() - else: - for notification in glob.glob(os.path.join(path, "doc", "notifications", f"{step}.d") + "/*.md"): - name = os.path.basename(notification)[:-len('.md')] - notifications[step][name].append(read_file(notification).strip()) + for filepath in glob.glob(os.path.join(path, "doc", "notifications", f"{step}*.md")): + m = re.match(step + "(_[a-z]{2,3})?.md", filepath.split("/")[-1]) + if not m: + continue + pagename = "main" + lang = m.groups()[0].strip("_") if m.groups()[0] else "en" + if pagename not in notifications[step]: + notifications[step][pagename] = {} + notifications[step][pagename][lang] = read_file(filepath).strip() + + for filepath in glob.glob(os.path.join(path, "doc", "notifications", f"{step}.d") + "/*.md"): + m = re.match(r"([A-Za-z0-9\.\~]*)(_[a-z]{2,3})?.md", filepath.split("/")[-1]) + if not m: + continue + pagename, lang = m.groups() + lang = lang.strip("_") if lang else "en" + if pagename not in notifications[step]: + notifications[step][pagename] = {} + notifications[step][pagename][lang] = read_file(filepath).strip() return doc, notifications diff --git a/src/tests/test_apps.py b/src/tests/test_apps.py index 2c6deac7d..4661e54b2 100644 --- a/src/tests/test_apps.py +++ b/src/tests/test_apps.py @@ -219,8 +219,8 @@ def test_legacy_app_manifest_preinstall(): assert "description" in m assert "integration" in m assert "install" in m - assert "doc" in m and not m["doc"] - assert "notifications" in m and not m["notifications"] + assert m.get("doc") == {} + assert m.get("notifications") == {} def test_manifestv2_app_manifest_preinstall(): @@ -231,9 +231,11 @@ def test_manifestv2_app_manifest_preinstall(): assert "install" in m assert "description" in m assert "doc" in m - assert "This is a dummy description of this app features" in m["doc"]["DESCRIPTION"] + assert "This is a dummy description of this app features" in m["doc"]["DESCRIPTION"]["en"] + assert "Ceci est une fausse description des fonctionalités de l'app" in m["doc"]["DESCRIPTION"]["fr"] assert "notifications" in m - assert "This is a dummy disclaimer to display prior to the install" in m["notifications"]["pre_install"] + assert "This is a dummy disclaimer to display prior to the install" in m["notifications"]["pre_install"]["en"] + assert "Ceci est un faux disclaimer à présenter avant l'installation" in m["notifications"]["pre_install"]["fr"] def test_manifestv2_app_install_main_domain(): @@ -266,11 +268,12 @@ def test_manifestv2_app_info_postinstall(): assert "install" in m assert "description" in m assert "doc" in m - assert "The app install dir is /var/www/manifestv2_app" in m["doc"]["ADMIN"] + assert "The app install dir is /var/www/manifestv2_app" in m["doc"]["ADMIN"]["en"] + assert "Le dossier d'install de l'app est /var/www/manifestv2_app" in m["doc"]["ADMIN"]["fr"] assert "notifications" in m - assert "The app install dir is /var/www/manifestv2_app" in m["notifications"]["post_install"] - assert "The app id is manifestv2_app" in m["notifications"]["post_install"] - assert f"The app url is {main_domain}/manifestv2" in m["notifications"]["post_install"] + assert "The app install dir is /var/www/manifestv2_app" in m["notifications"]["post_install"]["en"] + assert "The app id is manifestv2_app" in m["notifications"]["post_install"]["en"] + assert f"The app url is {main_domain}/manifestv2" in m["notifications"]["post_install"]["en"] def test_manifestv2_app_info_preupgrade(monkeypatch):