mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2024-11-22 11:18:08 -06:00
Added changelog to the translatable documentation
This commit is contained in:
parent
b3451e229d
commit
7a2e51ef03
3
.gitignore
vendored
3
.gitignore
vendored
@ -18,4 +18,5 @@ src/launcher.bat
|
||||
src/sounds/iOs
|
||||
release-snapshot/
|
||||
src/com_cache/
|
||||
doc/strings.py
|
||||
doc/strings.py
|
||||
doc/changelog.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")
|
||||
prepare_documentation_in_file("manual.md", "strings.py")
|
||||
prepare_documentation_in_file("changelog.md", "changelog.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 = """<!doctype html>
|
||||
<html lang="%s">
|
||||
<head>
|
||||
@ -23,12 +35,12 @@ def generate_document(language):
|
||||
</head>
|
||||
<body>
|
||||
<header><h1>%s</h1></header>
|
||||
""" % (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</body>\n</html>"
|
||||
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()
|
@ -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.
|
||||
|
@ -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
|
||||
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
|
Loading…
Reference in New Issue
Block a user