Adding the support for secondary languages through xlf files.
Using the okapi framwork it is possible to use the tools provided
in that project to produce xlf files and translate them with different
tranlation tools like Machine tranlsation (MT) or Translation Memory (TM).
import treecutter.constants as const
from treecutter.docbook import Docbook
import re
+from itertools import chain
class Directory():
"""Class containing the state of the directory with articles"""
def __init__(self):
self._cwd = u'.'
+ self._translations = []
self._tree = []
self._basepath = re.compile('[/\w\._-]*/[\w-]+',re.UNICODE)
- def scan(self):
+ def translations(self, directory):
+ paths = (self._cwd, directory)
+ for dirname, dirnames, filenames in chain.from_iterable(os.walk(path) for path in paths):
+ for filename in filenames:
+ if fnmatch.fnmatch(filename, '*.xlf'):
+ file_ = os.path.join(dirname,filename)
+ self._translations.append(file_)
+ return self._translations
+
+
+ def scan(self, draftflag, levelflag):
for dirname, dirnames, filenames in os.walk(self._cwd):
for filename in filenames:
if fnmatch.fnmatch(filename, '*.xml'):
import argparse
from treecutter.directory import Directory
from treecutter.sitemap import Sitemap
+from treecutter.tools import translate
def main():
ts = time()
print "--= Treecutter =--"
dir_ = Directory()
+ t1 = time()
+ totrans = dir_.translations(args.style)
+ print "Translate [%d] : [" % (len(totrans)),
+ translate(totrans)
+ print "]"
+ t2 = time()
+ print "Translate[%5.2f s]" % (round(t2-t1,2))
+
+
sitemap = Sitemap(args)
# Scanning current directory and subdirectory for docbook articles
isoxml = u"//iso_639_3_entry[@*='"+l+"']"
ln = self._isocode.xpath(isoxml)[0].get('name')
if lang != 'en':
- ln = self._tranlang[lang].gettext(ln)
+ ln = self._tranlang[lang].ugettext(ln)
p = unicode(link.link())
if p[-1] == u'/':
p = p +u'index'
p = p+u'.'+l
- li = html.li(html.a(ln.decode('utf-8'),
+ li = html.li(html.a(ln,
href=self._subdir+p,hreflang=l))
menu.append(li)
- return etree.tostring(menu,encoding='UTF-8',pretty_print=False)
+# print type(etree.tostring(menu,encoding='unicode',pretty_print=False))
+ return etree.tostring(menu,encoding='unicode',pretty_print=False)
def publish(self):
print "Size [ %7s ]" % (sizeof_fmt(get_folder_size(self._tmptarget)))
html += '<li%s><a href="%s%s">%s</a>\n' \
% (sel,subdir,l.value().link(),p.menu())
else:
- html += '<li%s><a href="%s%s.en" hreflang="en">%s</a>*\n' \
- % (sel,subdir,l.value().link(), l.value().page('en').menu())
+ link =l.value().link()
+ if link[-1] == u'/':
+ link = link +u'index'
+ html += '<li%s><a href="%s%s.en" hreflang="en">%s</a>\n' \
+ % (sel,subdir,link, l.value().page('en').menu())
if l.children():
html += self._menu(l.children(), lang, page, "", subdir)
html += "</li>\n"