From 7a2e51ef03fd86f28ddab2936c86e65bf8cdfd84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20Cort=C3=A9z?= Date: Sun, 9 Oct 2016 10:45:47 -0500 Subject: [PATCH] Added changelog to the translatable documentation --- .gitignore | 3 ++- doc/documentation_importer.py | 6 +++--- doc/generator.py | 25 +++++++++++++++++++------ doc/languageHandler.py | 8 ++++---- tools/genpot.bat | 3 ++- 5 files changed, 30 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index a930df61..495a2234 100644 --- a/.gitignore +++ b/.gitignore @@ -18,4 +18,5 @@ src/launcher.bat src/sounds/iOs release-snapshot/ src/com_cache/ -doc/strings.py \ No newline at end of file +doc/strings.py +doc/changelog.py \ No newline at end of file diff --git a/doc/documentation_importer.py b/doc/documentation_importer.py index bd1a2f31..cfe00765 100644 --- a/doc/documentation_importer.py +++ b/doc/documentation_importer.py @@ -2,7 +2,7 @@ """ This script converts the hold documentation (saved in markdown files) in a python file with a list of strings to translate it using gettext.""" def prepare_documentation_in_file(fileSource, fileDest): - """ This takes documentation written in a markdown file and put all the contents in a python file, to create a internationalized documentation. + """ This takes documentation written in a markdown file and put all the contents in a python file, to create a translatable documentation. @fileSource str: A markdown(.md) file. @fileDest str: A file where this will put the new strings""" @@ -18,11 +18,11 @@ def prepare_documentation_in_file(fileSource, fileDest): newvar = "_(u\"\"\"%s\"\"\"),\n" % (i[:-1]) else: newvar = "_(u\"\"\"%s\"\"\"),\n" % (i) -# print i[-1:] f2.write(newvar) f1.close() f2.write("]") f2.close() -prepare_documentation_in_file("manual.md", "strings.py") \ No newline at end of file +prepare_documentation_in_file("manual.md", "strings.py") +prepare_documentation_in_file("changelog.md", "changelog.py") \ No newline at end of file diff --git a/doc/generator.py b/doc/generator.py index 730f0bc4..1fee65aa 100644 --- a/doc/generator.py +++ b/doc/generator.py @@ -5,16 +5,28 @@ from codecs import open as _open import languageHandler languageHandler.setLanguage("en") import strings +import changelog # the list of supported language codes of TW Blue languages = ["en", "es", "fr", "de", "it", "gl", "ja", "ru", "ro"] #"eu", "ar", "ca", "es", "fi", "fr", "gl", "hu", "it", "pl", "pt", "ru", "tr"] -def generate_document(language): +def generate_document(language, document_type="documentation"): reload(languageHandler) - languageHandler.setLanguage(language) - reload(strings) - markdown_file = markdown.markdown("\n".join(strings.documentation[1:]), extensions=["markdown.extensions.toc"]) + if document_type == "documentation": + translation_file = "twblue-documentation" + languageHandler.setLanguage(language, translation_file) + reload(strings) + markdown_file = markdown.markdown("\n".join(strings.documentation[1:]), extensions=["markdown.extensions.toc"]) + title = strings.documentation[0] + filename = "manual.html" + elif document_type == "changelog": + translation_file = "twblue-changelog" + languageHandler.setLanguage(language, translation_file) + reload(changelog) + markdown_file = markdown.markdown("\n".join(changelog.documentation[1:]), extensions=["markdown.extensions.toc"]) + title = changelog.documentation[0] + filename = "changelog.html" first_html_block = """ @@ -23,12 +35,12 @@ def generate_document(language):

%s

- """ % (language, strings.documentation[0], strings.documentation[0]) + """ % (language, title, title) first_html_block = first_html_block+ markdown_file first_html_block = first_html_block + "\n\n" if not os.path.exists(language): os.mkdir(language) - mdfile = _open("%s/manual.html" % language, "w", encoding="utf-8") + mdfile = _open("%s/%s" % (language, filename), "w", encoding="utf-8") mdfile.write(first_html_block) mdfile.close() @@ -37,6 +49,7 @@ def create_documentation(): for i in languages: print("Creating documentation for: %s" % (i,)) generate_document(i) + generate_document(i, "changelog") print("Done") create_documentation() \ No newline at end of file diff --git a/doc/languageHandler.py b/doc/languageHandler.py index d8726d94..a532b850 100644 --- a/doc/languageHandler.py +++ b/doc/languageHandler.py @@ -117,7 +117,7 @@ def makePgettext(translations): return unicode(message) return pgettext -def setLanguage(lang): +def setLanguage(lang, translation_file="twblue-documentation"): system = platform.system() global curLang try: @@ -127,10 +127,10 @@ def setLanguage(lang): localeName=locale.windows_locale[windowsLCID] else: localeName=locale.getlocale()[0] - trans=gettext.translation('twblue-documentation', localedir="locales", languages=[localeName]) + trans=gettext.translation(translation_file, localedir="locales", languages=[localeName]) curLang=localeName else: - trans=gettext.translation("twblue-documentation", localedir="locales", languages=[lang]) + trans=gettext.translation(translation_file, localedir="locales", languages=[lang]) curLang=lang localeChanged=False #Try setting Python's locale to lang @@ -150,7 +150,7 @@ def setLanguage(lang): LCID=localeNameToWindowsLCID(lang) ctypes.windll.kernel32.SetThreadLocale(LCID) except IOError: - trans=gettext.translation("twblue-documentation",fallback=True) + trans=gettext.translation(translation_file,fallback=True) curLang="en" trans.install(unicode=True) # Install our pgettext function. diff --git a/tools/genpot.bat b/tools/genpot.bat index dd621a6e..3af37bd7 100644 --- a/tools/genpot.bat +++ b/tools/genpot.bat @@ -1,4 +1,5 @@ @echo off echo Generating application translation strings... C:\python27\python.exe pygettext.py -d twblue ../src/*.pyw ../src/*.py ../src/*/*.py ../src/*/*.pyw ../src/*/*/*.py ../src/*/*/*.pyw ../src/*/*/*/*.py ../src/*/*/*/*.pyw ../src/*/*/*/*/*.py ../src/*/*/*/*/*.pyw -C:\python27\python.exe pygettext.py -v -d twblue-documentation ../doc/*.py \ No newline at end of file +C:\python27\python.exe pygettext.py -v -d twblue-documentation ../doc/strings.py +C:\python27\python.exe pygettext.py -v -d twblue-changelog ../doc/changelog.py \ No newline at end of file