1
0
Fork 0
mirror of https://github.com/YunoHost/apps.git synced 2024-09-03 20:06:07 +02:00

regen READMEs even if only partially translated

This commit is contained in:
oleole39 2024-04-09 01:43:20 +02:00
parent 0e695c28b2
commit 339a0c64f9
2 changed files with 40 additions and 11 deletions

View file

@ -106,7 +106,7 @@ def generate_READMEs(app_path: Path):
continue continue
screenshots.append(str(entry.relative_to(app_path))) screenshots.append(str(entry.relative_to(app_path)))
def generate_single_README(lang_suffix: str, lang: str): def generate_single_README(lang_suffix: str, lang: str, translation_warning: bool = False):
env = Environment( env = Environment(
loader=FileSystemLoader(README_GEN_DIR / "templates"), loader=FileSystemLoader(README_GEN_DIR / "templates"),
extensions=["jinja2.ext.i18n"], extensions=["jinja2.ext.i18n"],
@ -123,8 +123,10 @@ def generate_READMEs(app_path: Path):
# Fallback to english if maintainer too lazy to translate the description # Fallback to english if maintainer too lazy to translate the description
elif (app_path / "doc" / "DESCRIPTION.md").exists(): elif (app_path / "doc" / "DESCRIPTION.md").exists():
description = (app_path / "doc" / "DESCRIPTION.md").read_text() description = (app_path / "doc" / "DESCRIPTION.md").read_text()
translation_warning = True
else: else:
description = None description = None
translation_warning = True
disclaimer: Optional[str] disclaimer: Optional[str]
if (app_path / "doc" / f"DISCLAIMER{lang_suffix}.md").exists(): if (app_path / "doc" / f"DISCLAIMER{lang_suffix}.md").exists():
@ -132,8 +134,10 @@ def generate_READMEs(app_path: Path):
# Fallback to english if maintainer too lazy to translate the disclaimer idk # Fallback to english if maintainer too lazy to translate the disclaimer idk
elif (app_path / "doc" / "DISCLAIMER.md").exists(): elif (app_path / "doc" / "DISCLAIMER.md").exists():
disclaimer = (app_path / "doc" / "DISCLAIMER.md").read_text() disclaimer = (app_path / "doc" / "DISCLAIMER.md").read_text()
translation_warning = True
else: else:
disclaimer = None disclaimer = None
translation_warning = True
# TODO: Add url to the documentation... and actually create that documentation :D # TODO: Add url to the documentation... and actually create that documentation :D
antifeatures = { antifeatures = {
@ -152,6 +156,7 @@ def generate_READMEs(app_path: Path):
) )
out: str = template.render( out: str = template.render(
translation_warning=translation_warning,
lang=lang, lang=lang,
upstream=upstream, upstream=upstream,
description=description, description=description,
@ -165,12 +170,22 @@ def generate_READMEs(app_path: Path):
generate_single_README("", "en") generate_single_README("", "en")
for lang in fully_translated_langs: for lang in fully_translated_langs:
generate_single_README("_" + lang, lang) generate_single_README("_" + lang, lang, False)
existing_READMEs_paths = glob.glob('README_*', root_dir=app_path)
existing_READMEs_langs = [name.removesuffix('.md').split('_')[-1] for name in existing_READMEs_paths]
other_existing_READMEs_langs = [x for x in existing_READMEs_langs if x not in fully_translated_langs]
for lang in other_existing_READMEs_langs:
generate_single_README("_" + lang, lang, True)
links_to_other_READMEs = [] links_to_other_READMEs = []
for language in fully_translated_langs: fully_translated_or_existing_langs = list(set(fully_translated_langs) | set(existing_READMEs_langs)) # Union
for language in fully_translated_or_existing_langs:
translations = Translations.load("translations", [language]) translations = Translations.load("translations", [language])
language_name_in_itself = Language.get(language).autonym() language_name_in_itself = Language.get(language).autonym()
if language in fully_translated_langs:
links_to_other_READMEs.append( links_to_other_READMEs.append(
( (
f"README_{language}.md", f"README_{language}.md",
@ -178,6 +193,14 @@ def generate_READMEs(app_path: Path):
% {"language": language_name_in_itself}, % {"language": language_name_in_itself},
) )
) )
elif language in other_existing_READMEs_langs:
links_to_other_READMEs.append(
(
f"README_{language}.md",
translations.gettext("Read the README in %(language)s (incomplete)")
% {"language": language_name_in_itself},
)
)
env = Environment(loader=FileSystemLoader(README_GEN_DIR / "templates")) env = Environment(loader=FileSystemLoader(README_GEN_DIR / "templates"))
out: str = env.get_template("ALL_README.md.j2").render( out: str = env.get_template("ALL_README.md.j2").render(

View file

@ -25,7 +25,13 @@ It shall NOT be edited by hand.") }}
[![{{ _("Install %(application_name)s with YunoHost")|format(application_name=manifest.name) }}](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app={{manifest.id}}) [![{{ _("Install %(application_name)s with YunoHost")|format(application_name=manifest.name) }}](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app={{manifest.id}})
{% if translation_warning %}
> [!WARNING]
> {{ _("The README is not fully translated in this language. You may want to read this README [in other languages]") }}](./ALL_README.md))
> {{ _("Help would be appreciated for [completing the translation]")}}(https://translate.yunohost.org/projects/yunohost/readme-generator/{{lang}}).
{% else %}
*[{{ _("Read this README in other languages.") }}](./ALL_README.md)* *[{{ _("Read this README in other languages.") }}](./ALL_README.md)*
{% endif -%}
> *{{ _("This package allows you to install %(application_name)s quickly and simply on a YunoHost server.")|format(application_name=manifest.name) }}* > *{{ _("This package allows you to install %(application_name)s quickly and simply on a YunoHost server.")|format(application_name=manifest.name) }}*
> *{{ _("If you don't have YunoHost, please consult [the guide](https://yunohost.org/install) to learn how to install it.") }}* > *{{ _("If you don't have YunoHost, please consult [the guide](https://yunohost.org/install) to learn how to install it.") }}*