1
0
Fork 0

feat(readme_generator/i18n): use langcodes module to get a language name in itself

This commit is contained in:
Laurent Peuch 2024-03-22 06:21:07 +01:00 committed by Bram
parent 696e5f4a0d
commit ce8de39d2f
3 changed files with 33 additions and 0 deletions

View file

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

View file

@ -4,3 +4,5 @@ pyyaml
toml
websockets==10.0
babel
langcodes
language_data

View file

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