feat(readme_generator/i18n): use langcodes module to get a language name in itself
This commit is contained in:
parent
696e5f4a0d
commit
ce8de39d2f
3 changed files with 33 additions and 0 deletions
|
@ -12,6 +12,7 @@ import toml
|
||||||
from jinja2 import Environment, FileSystemLoader
|
from jinja2 import Environment, FileSystemLoader
|
||||||
from babel.support import Translations
|
from babel.support import Translations
|
||||||
from babel.messages.pofile import PoFileParser
|
from babel.messages.pofile import PoFileParser
|
||||||
|
from langcodes import Language
|
||||||
|
|
||||||
README_GEN_DIR = Path(__file__).resolve().parent
|
README_GEN_DIR = Path(__file__).resolve().parent
|
||||||
APPS_REPO_ROOT = README_GEN_DIR.parent.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:
|
for lang in fully_translated_langs:
|
||||||
generate_single_README("_" + lang, lang)
|
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__":
|
if __name__ == "__main__":
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
|
|
|
@ -4,3 +4,5 @@ pyyaml
|
||||||
toml
|
toml
|
||||||
websockets==10.0
|
websockets==10.0
|
||||||
babel
|
babel
|
||||||
|
langcodes
|
||||||
|
language_data
|
||||||
|
|
13
readme_generator/templates/ALL_README.md.j2
Normal file
13
readme_generator/templates/ALL_README.md.j2
Normal 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 %}
|
Loading…
Reference in a new issue