def add_lang(args): # from website _, fname = mkstemp(suffix=".pot") os.system("pybabel extract -F website/babel.cfg -o %s website/" % fname) os.system("pybabel init -D messages -d translations/ -i %s -l %s" % (fname, args.lang)) os.remove(fname) # from documentation from website.utils import Documentation fhandle, fname = mkstemp(suffix=".pot") with os.fdopen(fhandle, "w") as fid: docs = Documentation(os.path.join(args.repo, 'website', 'docs', 'sources')) docs.extract_messages(fid) os.system("pybabel init -D docs -d translations/ -i %s -l %s" % (fname, args.lang)) os.remove(fname) # from parts data repo = Repository(args.repo) from backends.translations import TranslationBackend fhandle, fname = mkstemp(suffix=".pot") TranslationBackend(repo, []).write_output(fname) os.system("pybabel init -D parts -d translations/ -i %s -l %s" % (fname, args.lang)) os.remove(fname) print( "Don't forget to edit website/templates/base.html " "and add the language to the dropdown menu" )
def translate(args): if args.update_translation: # from website _, fname = mkstemp(suffix=".pot") os.system("pybabel extract -F website/babel.cfg -o %s website/" % fname) os.system("pybabel update -D messages -i %s -d translations/" % fname) os.remove(fname) # from documentation from website.utils import Documentation fhandle, fname = mkstemp(suffix=".pot") with os.fdopen(fhandle, "w") as fid: docs = Documentation(os.path.join(args.repo, 'website', 'docs', 'sources')) docs.extract_messages(fid) os.system("pybabel update -D docs -d translations -i %s" % fname) os.remove(fname) # from parts data repo = Repository(args.repo) from backends.translations import TranslationBackend fhandle, fname = mkstemp(suffix=".pot") TranslationBackend(repo, []).write_output(fname) os.system("pybabel update -D parts -d translations -i %s" % fname) os.remove(fname) if args.compile_translation: os.system("pybabel compile -D messages -d translations/") os.system("pybabel compile -D parts -d translations/") os.system("pybabel compile -D docs -d translations/")
from os import listdir from flask.helpers import safe_join, send_from_directory from urlparse import urljoin from website.cache import cache from website.translation import languages, gettext_docs from website.utils import Specification, Documentation from docutils import core docs = Blueprint("docs", __name__, template_folder="templates", static_folder="static", url_prefix='/<any(%s):lang_code>/docs/<version>' % ",".join(languages)) SOURCES = Documentation(join(docs.root_path, "sources")) STABLE = SOURCES.get_stable() DEV = SOURCES.get_dev() SPECS = Specification(join(docs.root_path, "specs")) @docs.url_defaults def add_language_code(endpoint, values): values.setdefault('lang_code', g.lang_code) if not getattr(g, 'version', None) is None: values.setdefault('version', g.version) else: values.setdefault('version', STABLE)