Skip to content

Commit 68a9879

Browse files
committed
Merge pull request #38 from sundeep-co-in/STAGE
ZNTA-865: locale support to zanata stats
2 parents bdbd01e + d22f5e0 commit 68a9879

File tree

6 files changed

+29
-10
lines changed

6 files changed

+29
-10
lines changed

CHANGELOG

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
* Thu Jan 7 2016 Sundeep Anand <[email protected]>
1+
* Tue Jan 12 2016 Sundeep Anand <[email protected]> - 1.4.1
22
- Implemented zanata init (ZNTA-780)
33
- Bug ZNTA-853 - Crash when pushing local translations
44
- Bug 1206995 - allow anonymous pull

zanataclient/cmdbase.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,9 @@ def run(self):
236236
for cmd in ('detailstats', 'wordstats', 'docid')
237237
if cmd in self.context_data])
238238
cmd_opts['locale_map'] = self.context_data.get('locale_map')
239+
if self.context_data.get('lang') and isinstance(self.context_data['lang'], str):
240+
cmd_opts['lang'] = filter(lambda locale: locale if locale else None,
241+
self.context_data['lang'].split(','))
239242
self.zanatacmd.display_translation_stats(*id_version, **cmd_opts)
240243

241244

zanataclient/initcmd.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -251,12 +251,12 @@ def print_trans_matches(self, match, locale, transdir):
251251
elements = match.split('/')
252252
elements[0] = transdir
253253
elements[len(elements) - 1] = locale + '.po'
254-
print("\t " + '/'.join(elements))
254+
self.ptxt('info_blue', "\t " + '/'.join(elements))
255255
elif self.local_config.get('project_type') == 'podir':
256256
elements = match.split('/')
257257
elements[0] = transdir
258258
elements.insert(len(elements) - 1, locale)
259-
print("\t " + '/'.join(elements).replace('pot', 'po'))
259+
self.ptxt('info_blue', "\t " + '/'.join(elements).replace('pot', 'po'))
260260

261261
def print_dir_contents(self, directory, mode, transdir):
262262
matches = []
@@ -267,12 +267,13 @@ def print_dir_contents(self, directory, mode, transdir):
267267
if len(matches) > 0:
268268
locale = 'en-US'
269269
if mode == 'source':
270-
print("\n\tFound %s documents: " % mode)
270+
self.ptxt('header', "\n\tFound %s documents: " % mode)
271271
else:
272-
print('\n\tZanata will put translation files as below (e.g. for locale %s): ' % locale)
272+
self.ptxt('header', '\n\tZanata will put translation files as '
273+
'below (e.g. for locale %s): ' % locale)
273274
for match in matches:
274275
if mode == 'source':
275-
print("\t\t%s" % match.rstrip(ext))
276+
self.ptxt('info_blue', "\t\t%s" % match.rstrip(ext))
276277
else:
277278
self.print_trans_matches(match, locale, transdir)
278279

zanataclient/zanata.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,7 @@ def stats(command_options, args):
688688
--project-version : id of the version (defaults to zanata.xml value)
689689
--details : Include statistics for lower levels (i.e., for documents in a project version)
690690
--docid : Document Id to fetch statistics for
691+
--lang : Language list (comma separated)
691692
--word : Include word level statistics. By default only message level statistics are shown
692693
--disable-ssl-cert disable ssl certificate validation in 0.7.x python-httplib2
693694
"""

zanataclient/zanatacmd.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -626,10 +626,11 @@ def display_translation_stats(self, *args, **kwargs):
626626
try:
627627
project_id, project_version = args
628628
server_return = self.zanata_resource.stats.get_project_stats(
629-
project_id, project_version, 'wordstats' in kwargs
629+
project_id, project_version, 'wordstats' in kwargs, kwargs.get('lang')
630630
) if not kwargs.get('docid') else \
631631
self.zanata_resource.stats.get_doc_stats(
632-
project_id, project_version, kwargs['docid'], 'wordstats' in kwargs
632+
project_id, project_version, kwargs['docid'],
633+
'wordstats' in kwargs, kwargs.get('lang')
633634
)
634635
except ZanataException, e:
635636
self.log.error(str(e))

zanataclient/zanatalib/statservice.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,29 @@ def __init__(self, *args, **kargs):
3737
def disable_ssl_cert_validation(self):
3838
self.restclient.disable_ssl_cert_validation()
3939

40-
def get_project_stats(self, project_id, project_version, word=False):
40+
def _append_locales(self, ext, locales):
41+
for locale in locales:
42+
ext += '&locale=%s' % locale
43+
return ext
44+
45+
def get_project_stats(
46+
self, project_id, project_version, word=False, locales=None
47+
):
4148
ext = "?detail=true&word=true" if word else "?detail=true&word=false"
49+
if isinstance(locales, list) and len(locales) > 0:
50+
ext = self._append_locales(ext, locales)
4251
res, content = self.restclient.process_request(
4352
'proj_trans_stats', project_id, project_version,
4453
headers=self.http_headers, extension=ext
4554
)
4655
return self.messages(res, content)
4756

48-
def get_doc_stats(self, project_id, project_version, doc_id, word=False):
57+
def get_doc_stats(
58+
self, project_id, project_version, doc_id, word=False, locales=None
59+
):
4960
ext = "?detail=true&word=true" if word else "?detail=true&word=false"
61+
if isinstance(locales, list) and len(locales) > 0:
62+
ext = self._append_locales(ext, locales)
5063
res, content = self.restclient.process_request(
5164
'doc_trans_stats', project_id, project_version, doc_id,
5265
headers=self.http_headers, extension=ext

0 commit comments

Comments
 (0)