[damned-lies] Monkey-patch translate-toolkit pogrep command to workaround bug
- From: Claude Paroz <claudep src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [damned-lies] Monkey-patch translate-toolkit pogrep command to workaround bug
- Date: Mon, 26 Mar 2018 10:43:26 +0000 (UTC)
commit ae98afb57502cec605ead6b33ea519a2825a9367
Author: Claude Paroz <claude 2xlibre net>
Date: Mon Mar 26 12:23:24 2018 +0200
Monkey-patch translate-toolkit pogrep command to workaround bug
stats/tests/tests.py | 6 ++++++
stats/utils.py | 11 +++++++++++
2 files changed, 17 insertions(+), 0 deletions(-)
---
diff --git a/stats/tests/tests.py b/stats/tests/tests.py
index be8d39b..9755ae2 100644
--- a/stats/tests/tests.py
+++ b/stats/tests/tests.py
@@ -137,6 +137,12 @@ class ModuleTestCase(TestCase):
fr_po_stat = Statistics.objects.get(branch=self.branch, domain__name='po', language__locale='fr')
self.assertEqual(fr_po_stat.translated(), 44)
self.assertEqual(fr_po_stat.translated_words(), 131)
+ self.assertEqual(fr_po_stat.full_po, fr_po_stat.part_po)
+ # Partial translated file
+ it_po_stat = Statistics.objects.get(branch=self.branch, domain__name='po', language__locale='it')
+ self.assertEqual(it_po_stat.translated(), 9)
+ self.assertEqual(it_po_stat.full_po, it_po_stat.part_po)
+
pot_doc_stat = Statistics.objects.get(branch=self.branch, domain__name='help', language=None)
self.assertEqual(len(pot_doc_stat.full_po.figures), 2)
fr_doc_stat = Statistics.objects.get(branch=self.branch, domain__name='help', language__locale='fr')
diff --git a/stats/utils.py b/stats/utils.py
index 1947240..7cef43f 100644
--- a/stats/utils.py
+++ b/stats/utils.py
@@ -12,6 +12,17 @@ from unittest.mock import MagicMock
try:
from translate.tools import pogrep, pocount
+ # monkey-patch ttk (https://github.com/translate/translate/issues/2129)
+ from translate.storage.base import TranslationStore
+ orig_addunit = TranslationStore.addunit
+ def patchedAddunit(self, unit):
+ # Prevent two header units in the same store
+ if unit.isheader() and len(self.units) and self.units[0].isheader():
+ unit._store = self
+ self.units[0] = unit
+ else:
+ orig_addunit(self, unit)
+ TranslationStore.addunit = patchedAddunit
has_toolkit = True
except ImportError:
has_toolkit = False
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]