Updated documentation generators

This commit is contained in:
Manuel Cortez 2021-06-27 20:55:16 -05:00
parent 969a75e9f3
commit 9dfccd2bd0
2 changed files with 18 additions and 17 deletions

View File

@ -16,9 +16,9 @@ def prepare_documentation_in_file(fileSource, fileDest):
if "\n" == i: if "\n" == i:
newvar = "\"\"," newvar = "\"\","
elif "\n" == i[-1]: elif "\n" == i[-1]:
newvar = "_(u\"\"\"%s\"\"\"),\n" % (i[:-1]) newvar = "\"\"\"%s\"\"\",\n" % (i[:-1])
else: else:
newvar = "_(u\"\"\"%s\"\"\"),\n" % (i) newvar = "\"\"\"%s\"\"\",\n" % (i)
f2.write(newvar) f2.write(newvar)
f1.close() f1.close()
f2.write("]") f2.write("]")

View File

@ -8,10 +8,11 @@ import shutil
from codecs import open as _open from codecs import open as _open
from importlib import reload from importlib import reload
def change_language(name, language): def get_translation_function(name, language):
global _ if language == "en":
os.environ["lang"] = language return gettext.NullTranslations()
_ = gettext.install(name, os.path.join(paths.app_path(), "locales")) translation_function = gettext.translation(name, os.path.join(paths.app_path(), "locales"), languages=[language])
return translation_function
# the list of supported language codes of TW Blue # the list of supported language codes of TW Blue
languages = ["en", "es", "fr", "de", "it", "gl", "ja", "ru", "ro", "eu", "ca", "da"] languages = ["en", "es", "fr", "de", "it", "gl", "ja", "ru", "ro", "eu", "ca", "da"]
@ -19,17 +20,15 @@ languages = ["en", "es", "fr", "de", "it", "gl", "ja", "ru", "ro", "eu", "ca", "
def generate_document(language, document_type="documentation"): def generate_document(language, document_type="documentation"):
if document_type == "documentation": if document_type == "documentation":
translation_file = "twblue-documentation" translation_file = "twblue-documentation"
change_language(translation_file, language) translation_function = get_translation_function(translation_file, language)
reload(strings) markdown_file = markdown.markdown("\n".join([translation_function.gettext(s[:-1]) if s != "\n" else s for s in strings.documentation[1:]]), extensions=["markdown.extensions.toc"])
markdown_file = markdown.markdown("\n".join(strings.documentation[1:]), extensions=["markdown.extensions.toc"]) title = translation_function.gettext(strings.documentation[0][:-1])
title = strings.documentation[0]
filename = "manual.html" filename = "manual.html"
elif document_type == "changelog": elif document_type == "changelog":
translation_file = "twblue-changelog" translation_file = "twblue-changelog"
change_language(translation_file, language) translation_function = get_translation_function(translation_file, language)
reload(changelog) markdown_file = markdown.markdown("\n".join([translation_function.gettext(s[:-1]) if s != "\n" else s for s in changelog.documentation[1:]]), extensions=["markdown.extensions.toc"])
markdown_file = markdown.markdown("\n".join(changelog.documentation[1:]), extensions=["markdown.extensions.toc"]) title = translation_function.gettext(changelog.documentation[0][:-1])
title = changelog.documentation[0]
filename = "changelog.html" filename = "changelog.html"
first_html_block = """<!doctype html> first_html_block = """<!doctype html>
<html lang="%s"> <html lang="%s">
@ -56,11 +55,13 @@ def create_documentation():
shutil.copy(os.path.join("..", "license.txt"), os.path.join("documentation", "license.txt")) shutil.copy(os.path.join("..", "license.txt"), os.path.join("documentation", "license.txt"))
for i in languages: for i in languages:
print("Creating documentation for: %s" % (i,)) print("Creating documentation for: %s" % (i,))
generate_document(i) try:
generate_document(i, "changelog") generate_document(i)
generate_document(i, "changelog")
except:
continue
print("Done") print("Done")
change_language("twblue-documentation", "en")
import strings import strings
import changelog import changelog
create_documentation() create_documentation()