Commit b0d7aa0a authored by Julien Lepiller's avatar Julien Lepiller

Add appstore format

parent 4e6aee70
......@@ -21,6 +21,7 @@ from translation_finder import discover
from .project import Project
from .fetcher import GitFetcher
from .analyzer import AndroidAnalyzer
from .analyzer import AppstoreAnalyzer
from .analyzer import GettextAnalyzer
def main():
......@@ -67,7 +68,9 @@ def main():
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)
a = GettextAnalyzer(resource['new_base'], resource['filemask'], True)
elif resource['file_format'] == 'appstore':
a = AppstoreAnalyzer(resource['template'], resource['filemask'])
else:
raise Exception('No such analyzer: ' + resource['file_format'])
p.set_analyzer(a)
......
......@@ -16,6 +16,7 @@
import os
import polib
import sys
from pathlib import Path
from androidstringslib import android
class Analyzer(object):
......@@ -56,6 +57,31 @@ class AndroidAnalyzer(Analyzer):
res[lang] = (translated, number)
return res
class AppstoreAnalyzer(Analyzer):
def __init__(self, template, translation):
self.template = template
self.translation = translation
Analyzer.__init__(self)
def analyze(self, path):
res = {}
appstore = Path(path + '/' + self.template).parent
template = Path(path + '/' + self.template)
template_files = [x for x in list(template.glob('**/*')) if x.is_file()]
template_files = [str(x)[len(str(template))+1:] for x in template_files]
langs = appstore.glob('*')
for lang in langs:
if not lang.is_dir():
continue
if str(lang) == str(template):
continue
langname = str(lang)[len(str(appstore))+1:]
lang_files = [x for x in list(lang.glob('**/*')) if x.is_file()]
lang_files = [str(x)[len(str(lang))+1:] for x in lang_files]
lang_files = [x for x in lang_files if x in template_files]
res[langname] = (len(lang_files), len(template_files))
return res
class GettextAnalyzer(Analyzer):
def __init__(self, pot, pofiles, mono=False):
self.pot = pot
......
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