Commit 3cc14948 authored by Claude Paroz's avatar Claude Paroz

Refs #68 - Add a warning when committed file has less translated strings

parent bbd61e46
......@@ -1604,7 +1604,7 @@ class Statistics(models.Model):
return utils.url_join(self.branch.get_vcs_web_url(), self.domain.base_dir)
def po_path(self, potfile=False, reduced=False):
""" Return path of po file on local filesystem """
""" Return path of (merged) po file on local filesystem """
subdir = ""
if self.domain.dtype == "doc":
subdir = "docs"
......@@ -1615,7 +1615,7 @@ class Statistics(models.Model):
return path
def po_url(self, potfile=False, reduced=False):
""" Return URL of po file, e.g. for downloading the file """
""" Return URL of (merged) po file, e.g. for downloading the file """
subdir = ""
if self.domain.dtype == "doc":
subdir = "docs/"
......@@ -1636,6 +1636,18 @@ class Statistics(models.Model):
stats = utils.po_file_stats(file_path)
for err in stats['errors']:
self.set_error(*err)
# If stats are 100%, compare the total number of strings between
# committed po (pofile) and merged po (outpo).
# Until https://savannah.gnu.org/bugs/index.php?50910 is fixed.
if stats['fuzzy'] + stats['untranslated'] == 0: # Fully translated
abs_po_path = self.branch.co_path / self.domain.get_po_path(self.language.locale)
if abs_po_path.exists():
git_stats = utils.po_file_stats(abs_po_path)
if stats['translated'] > git_stats['translated']:
self.set_error('warn', ugettext_noop(
"The currently committed file has less translated strings. "
"You should probably commit this file."
))
try:
df = self.domain.doc_format(self.branch)
except Exception:
......
......@@ -147,6 +147,13 @@ class ModuleTestCase(TestCase):
self.assertEqual(it_po_stat.translated(), 9)
self.assertEqual(it_po_stat.full_po, it_po_stat.part_po)
# Committed file with less strings that merged one.
de_po_stat = Statistics.objects.get(branch=self.branch, domain__name='po', language__locale='de')
self.assertEqual(de_po_stat.information_set.count(), 1)
self.assertTrue(de_po_stat.information_set.first().description.startswith(
'The currently committed file has less translated strings'
))
pot_doc_stat = Statistics.objects.get(branch=self.branch, domain__name='help', language=None)
self.assertEqual(pot_doc_stat.untranslated(), 43)
self.assertEqual(len(pot_doc_stat.full_po.figures), 2)
......
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