manifestv2: add some i18n support for doc/notifications

This commit is contained in:
Alexandre Aubin 2022-05-21 16:38:51 +02:00
parent 8b1333a837
commit 2ccb0c8db6
2 changed files with 45 additions and 19 deletions

View file

@ -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

View file

@ -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):