[damned-lies] Refs #68 - Add a warning when committed file has less translated strings



commit 3cc14948470083cd0382f73f93c5aec9de1c0b8b
Author: Claude Paroz <claude 2xlibre net>
Date:   Sun Sep 30 11:14:50 2018 +0200

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

 stats/models.py                |  16 ++++++++++++++--
 stats/tests/gnome-hello.tar.gz | Bin 336857 -> 336876 bytes
 stats/tests/tests.py           |   7 +++++++
 3 files changed, 21 insertions(+), 2 deletions(-)
---
diff --git a/stats/models.py b/stats/models.py
index ca1eb27e..f82c3c22 100644
--- a/stats/models.py
+++ b/stats/models.py
@@ -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:
diff --git a/stats/tests/gnome-hello.tar.gz b/stats/tests/gnome-hello.tar.gz
index 4d6f0161..ac9a63f6 100644
Binary files a/stats/tests/gnome-hello.tar.gz and b/stats/tests/gnome-hello.tar.gz differ
diff --git a/stats/tests/tests.py b/stats/tests/tests.py
index f078b7ef..48f3c86f 100644
--- a/stats/tests/tests.py
+++ b/stats/tests/tests.py
@@ -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)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]