# -*- coding: utf-8 -*- import gettext import os import locale import paths import markdown import shutil from importlib import reload # Languages already translated or translating the documentation. documentation_languages = ["en", "es", "fr", "de", "it", "gl", "ja", "ru", "ro", "eu", "ca", "da", "sr"] # Changelog translated languages. changelog_languages = ["en", "ca", "de", "es", "eu", "fr", "gl", "ja", "ro", "ru", "sr"] # this function will help us to have both strings.py and changelog.py without issues by installing a global dummy translation function. def install_null_translation(name): _ = gettext.NullTranslations() _.install() return def get_translations(name): """ Create translation instances for every language of the translated document. """ translations = {} if "documentation" in name: langs = documentation_languages else: langs = changelog_languages for l in langs: if l != "en": _ = gettext.translation(name, os.path.join(paths.app_path(), "locales"), languages=[l]) translations[l] = _ else: _ = gettext.NullTranslations() translations[l] = _ return translations def generate_document(lang, lang_name, document_type="documentation"): """ Generates a document by using the provided lang object, which should be a translation, and lang_name, which should be the two letter code representing the language. """ if document_type == "documentation": translation_file = "twblue-documentation" markdown_file = markdown.markdown("\n".join([lang.gettext(s) if s != "" else s for s in strings.documentation[1:]]), extensions=["markdown.extensions.toc"]) title = lang.gettext(strings.documentation[0]) filename = "manual.html" elif document_type == "changelog": translation_file = "twblue-changelog" markdown_file = markdown.markdown("\n".join([lang.gettext(s) if s != "" else s for s in changelog.documentation[1:]]), extensions=["markdown.extensions.toc"]) title = lang.gettext(changelog.documentation[0]) filename = "changelog.html" first_html_block = """