2016-06-06 02:41:42 -05:00
|
|
|
# -*- coding: utf-8 -*-
|
2019-11-26 09:06:03 -06:00
|
|
|
import gettext
|
2016-06-06 02:41:42 -05:00
|
|
|
import os
|
2019-11-26 09:06:03 -06:00
|
|
|
import locale
|
|
|
|
import markdown
|
2018-12-19 04:58:34 -06:00
|
|
|
import shutil
|
2016-06-06 02:41:42 -05:00
|
|
|
from codecs import open as _open
|
2019-11-26 09:06:03 -06:00
|
|
|
from importlib import reload
|
2016-06-06 02:41:42 -05:00
|
|
|
|
2019-11-26 09:06:03 -06:00
|
|
|
def change_language(name, language):
|
|
|
|
global _
|
|
|
|
os.environ["lang"] = language
|
|
|
|
print(name)
|
|
|
|
print(os.path.join(os.getcwd(), "locales"))
|
|
|
|
_ = gettext.install(name, os.path.join(os.getcwd(), "locales"))
|
|
|
|
|
|
|
|
languages = ["en", "ru"]
|
2016-06-06 02:41:42 -05:00
|
|
|
|
2018-12-19 04:58:34 -06:00
|
|
|
def generate_document(language, document_type="documentation"):
|
2019-11-26 09:06:03 -06:00
|
|
|
translation_file = "socializer-documentation"
|
|
|
|
change_language(translation_file, language)
|
2018-12-19 04:58:34 -06:00
|
|
|
if document_type == "documentation":
|
|
|
|
reload(strings)
|
|
|
|
markdown_file = markdown.markdown("\n".join(strings.documentation[1:]), extensions=["markdown.extensions.toc"])
|
2019-01-20 02:41:32 -06:00
|
|
|
title = strings.documentation[0][1:]
|
2018-12-19 04:58:34 -06:00
|
|
|
filename = "manual.html"
|
|
|
|
elif document_type == "changelog":
|
|
|
|
reload(changelog)
|
|
|
|
markdown_file = markdown.markdown("\n".join(changelog.documentation[1:]), extensions=["markdown.extensions.toc"])
|
2019-01-20 02:41:32 -06:00
|
|
|
title = changelog.documentation[0][1:]
|
2018-12-19 04:58:34 -06:00
|
|
|
filename = "changelog.html"
|
2016-06-06 02:41:42 -05:00
|
|
|
first_html_block = """<!doctype html>
|
|
|
|
<html lang="%s">
|
|
|
|
<head>
|
|
|
|
<title>%s</title>
|
|
|
|
<meta charset="utf-8">
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<header><h1>%s</h1></header>
|
2018-12-19 04:58:34 -06:00
|
|
|
""" % (language, title, title)
|
2016-06-06 02:41:42 -05:00
|
|
|
first_html_block = first_html_block+ markdown_file
|
|
|
|
first_html_block = first_html_block + "\n</body>\n</html>"
|
2018-12-18 17:36:52 -06:00
|
|
|
if not os.path.exists(os.path.join("documentation", language)):
|
|
|
|
os.mkdir(os.path.join("documentation", language))
|
2018-12-19 04:58:34 -06:00
|
|
|
mdfile = _open(os.path.join("documentation", language, filename), "w", encoding="utf-8")
|
2016-06-06 02:41:42 -05:00
|
|
|
mdfile.write(first_html_block)
|
|
|
|
mdfile.close()
|
|
|
|
|
|
|
|
def create_documentation():
|
|
|
|
print("Creating documentation in the supported languages...\n")
|
2018-12-19 04:58:34 -06:00
|
|
|
if not os.path.exists("documentation"):
|
|
|
|
os.mkdir("documentation")
|
|
|
|
if os.path.exists(os.path.join("documentation", "license.txt")) == False:
|
|
|
|
shutil.copy(os.path.join("..", "license.txt"), os.path.join("documentation", "license.txt"))
|
2016-06-06 02:41:42 -05:00
|
|
|
for i in languages:
|
|
|
|
print("Creating documentation for: %s" % (i,))
|
|
|
|
generate_document(i)
|
2018-12-19 04:58:34 -06:00
|
|
|
generate_document(i, "changelog")
|
2016-06-06 02:41:42 -05:00
|
|
|
print("Done")
|
|
|
|
|
2019-11-26 09:06:03 -06:00
|
|
|
change_language("socializer-documentation", "en")
|
|
|
|
import strings
|
|
|
|
import changelog
|
2016-06-06 02:41:42 -05:00
|
|
|
create_documentation()
|