Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regenerate existing READMEs even if translation status has dropped from a lower value than 100% #2337

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 33 additions & 9 deletions tools/readme_generator/make_readme.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from typing import Dict, Optional, List, Tuple

import toml
import glob
from jinja2 import Environment, FileSystemLoader
from babel.support import Translations
from babel.messages.pofile import PoFileParser
Expand Down Expand Up @@ -106,7 +107,7 @@ def generate_READMEs(app_path: Path):
continue
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(
loader=FileSystemLoader(README_GEN_DIR / "templates"),
extensions=["jinja2.ext.i18n"],
Expand All @@ -123,17 +124,21 @@ def generate_single_README(lang_suffix: str, lang: str):
# Fallback to english if maintainer too lazy to translate the description
elif (app_path / "doc" / "DESCRIPTION.md").exists():
description = (app_path / "doc" / "DESCRIPTION.md").read_text()
translation_warning = True
else:
description = None
translation_warning = True

disclaimer: Optional[str]
if (app_path / "doc" / f"DISCLAIMER{lang_suffix}.md").exists():
disclaimer = (app_path / "doc" / f"DISCLAIMER{lang_suffix}.md").read_text()
# Fallback to english if maintainer too lazy to translate the disclaimer idk
elif (app_path / "doc" / "DISCLAIMER.md").exists():
disclaimer = (app_path / "doc" / "DISCLAIMER.md").read_text()
translation_warning = True
else:
disclaimer = None
translation_warning = True

# TODO: Add url to the documentation... and actually create that documentation :D
antifeatures = {
Expand All @@ -152,6 +157,7 @@ def generate_single_README(lang_suffix: str, lang: str):
)

out: str = template.render(
translation_warning=translation_warning,
lang=lang,
upstream=upstream,
description=description,
Expand All @@ -165,19 +171,37 @@ def generate_single_README(lang_suffix: str, lang: str):
generate_single_README("", "en")

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 = []
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])
language_name_in_itself = Language.get(language).autonym()
links_to_other_READMEs.append(
(
f"README_{language}.md",
translations.gettext("Read the README in %(language)s")
% {"language": language_name_in_itself},
if language in fully_translated_langs:
links_to_other_READMEs.append(
(
f"README_{language}.md",
translations.gettext("Read the README in %(language)s")
% {"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"))
out: str = env.get_template("ALL_README.md.j2").render(
Expand Down
6 changes: 6 additions & 0 deletions tools/readme_generator/templates/README.md.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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}})

{% 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)*
{% endif -%}

> *{{ _("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.") }}*
Expand Down
Loading