Commit c85f4695 authored by Julien Lepiller's avatar Julien Lepiller

Add gettext support

parent da2f6e89
......@@ -21,6 +21,7 @@ from translation_finder import discover
from .project import Project
from .fetcher import GitFetcher
from .analyzer import AndroidAnalyzer
from .analyzer import GettextAnalyzer
def main():
if(len(sys.argv) < 2):
......@@ -63,6 +64,10 @@ def main():
for resource in translations:
if resource['file_format'] == 'aresource':
a = AndroidAnalyzer(resource['template'])
elif resource['file_format'] == 'po':
a = GettextAnalyzer(resource['new_base'] if hasattr(resource, 'new_base') else None, resource['filemask'])
elif resource['file_format'] == 'po-mono':
a = GettextAnalyzer(resource['new_base'], resource['file_mask'], True)
else:
raise Exception('No such analyzer: ' + resource['file_format'])
p.set_analyzer(a)
......
......@@ -48,3 +48,41 @@ class AndroidAnalyzer(Analyzer):
lang = p[p.find('/values-')+8:]
res[lang] = (translated, number)
return res
class GettextAnalyzer(Analyzer):
def __init__(self, pot, pofiles, mono=False):
self.pot = pot
self.pofiles = pofiles
self.mono = mono
Analyzer.__init__(self)
def analyze(self, path):
if self.mono:
respath = os.path.dirname(os.path.dirname(path + "/" + self.pofiles))
else:
respath = os.path.dirname(path + "/" + self.pofiles)
# pofiles = po/manual/guix-manual.*.po
# pofiles = po/*/app.po
dirs = os.listdir(respath)
if self.mono:
poname = os.basename(path + "/" + self.pofiles)
dirs2 = [os.listdir(p) for p in dirs]
pofiles = [p for p in dirs2 if (os.basename(path + "/" + p)) == poname]
else:
pofiles = [p for p in dirs if p[-2:] == "po"]
res = {}
for pofile in pofiles:
po = polib.pofile(respath + "/" + pofile)
if self.pot is not None:
pot = polib.pofile(self.pot)
po.merge(pot)
translated = 0
number = 0
for entry in po:
if entry.obsolete == 1:
continue
number = number + 1
if entry.msgstr != "":
translated = translated + 1
res[po.metadata['Language']] = (translated, number)
return res
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment