diff --git a/readme_generator/make_readme.py b/readme_generator/make_readme.py index f3a0da9..13d1a3c 100755 --- a/readme_generator/make_readme.py +++ b/readme_generator/make_readme.py @@ -12,6 +12,7 @@ import toml from jinja2 import Environment, FileSystemLoader from babel.support import Translations from babel.messages.pofile import PoFileParser +from langcodes import Language README_GEN_DIR = Path(__file__).resolve().parent APPS_REPO_ROOT = README_GEN_DIR.parent.parent @@ -154,6 +155,23 @@ def generate_READMEs(app_path: Path): for lang in fully_translated_langs: generate_single_README("_" + lang, lang) + links_to_other_READMEs = [] + for language in fully_translated_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}, + ) + ) + + out: str = env.get_template("ALL_README.md.j2").render( + links_to_other_READMEs=links_to_other_READMEs + ) + (app_path / "ALL_README.md").write_text(out) + if __name__ == "__main__": parser = argparse.ArgumentParser( diff --git a/readme_generator/requirements.txt b/readme_generator/requirements.txt index 5b4e5f2..f68c0e6 100644 --- a/readme_generator/requirements.txt +++ b/readme_generator/requirements.txt @@ -4,3 +4,5 @@ pyyaml toml websockets==10.0 babel +langcodes +language_data diff --git a/readme_generator/templates/ALL_README.md.j2 b/readme_generator/templates/ALL_README.md.j2 new file mode 100644 index 0000000..fd6d98c --- /dev/null +++ b/readme_generator/templates/ALL_README.md.j2 @@ -0,0 +1,13 @@ +# All available README files by language + +[Read the README in English](README.md) + +{% for filename, translated_sentence in links_to_other_READMEs %} +* [{{ translated_sentence }}]({{ filename }}) +{% endfor %} + +{% if False %} +Yes this is a hack to add the translatable string to messages.pot + +{{ _("Read the README in %(language)s") }} +{% endif %}