[damned-lies] Fixes #142 - Remove "do not translate" strings from pot files
- From: Claude Paroz <claudep src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [damned-lies] Fixes #142 - Remove "do not translate" strings from pot files
- Date: Fri, 22 Mar 2019 19:57:07 +0000 (UTC)
commit b858920afd1748e413b2c04051e02c78279c4e25
Author: Claude Paroz <claude 2xlibre net>
Date: Fri Mar 22 20:55:36 2019 +0100
Fixes #142 - Remove "do not translate" strings from pot files
stats/models.py | 3 +++
stats/tests/tests.py | 8 ++++++++
stats/utils.py | 23 +++++++++++++++++++++++
3 files changed, 34 insertions(+)
---
diff --git a/stats/models.py b/stats/models.py
index f0b01339..50c27fa5 100644
--- a/stats/models.py
+++ b/stats/models.py
@@ -785,6 +785,9 @@ class Domain(models.Model):
if file_.match('*.pot'):
potfile = file_
break
+ elif pot_method == 'gettext':
+ # Filter out strings NOT to be translated, typically icon file names.
+ exclude_untrans_messages(potfile)
if errors:
return "", errors
diff --git a/stats/tests/tests.py b/stats/tests/tests.py
index e92f15ae..eaf8c70f 100644
--- a/stats/tests/tests.py
+++ b/stats/tests/tests.py
@@ -843,6 +843,14 @@ class UtilsTests(TestModuleBase):
utils.insert_locale_in_linguas(linguas_path, 'xx')
self.assertTrue(linguas_path.read_text().endswith('xx\n'))
+ def test_exclude_messages_from_potfile(self):
+ pot_file = Path(__file__).parent / 'donottranslate.pot'
+ with tempfile.NamedTemporaryFile(suffix='.pot') as temppot:
+ shutil.copyfile(str(pot_file), temppot.name)
+ utils.exclude_untrans_messages(temppot.name)
+ stats = utils.po_file_stats(Path(temppot.name))
+ self.assertEqual(stats['untranslated'], 2)
+
@test_scratchdir
def test_po_grep(self):
# Take it.po, because desktop.in.h strings are not yet translated
diff --git a/stats/utils.py b/stats/utils.py
index 69db65e5..7023d464 100644
--- a/stats/utils.py
+++ b/stats/utils.py
@@ -699,6 +699,7 @@ def check_identical_figures(fig_stats, base_path, lang):
errors.append(("warn-ext", "Figures should not be copied when identical to original (%s)." %
trans_path))
return errors
+
def add_custom_header(po_path, header, value):
""" Add a custom po file header """
grep_cmd = """grep "%s" %s""" % (header, po_path)
@@ -715,6 +716,28 @@ def add_custom_header(po_path, header, value):
cmd = '''sed -i '/^\"%s/ c\\"%s: %s\\\\n"' %s''' % (header, header, value, po_path)
(stat, out, err) = run_shell_command(cmd)
+
+def exclude_untrans_messages(potfile):
+ """Exclude translatable strings matching some translator comments."""
+ exclude_message = 'translators: do not translate or transliterate this text'
+ # Grep first the file to see if the message is in the file.
+ status, _, _ = run_shell_command(['grep', '-i', exclude_message, potfile])
+ if status != STATUS_OK:
+ return
+
+ with open(str(potfile), 'r+') as fh:
+ lines = fh.readlines()
+ fh.seek(0)
+ skip_unit = False
+ for line in lines:
+ if not exclude_message in line.lower() and not skip_unit:
+ fh.write(line)
+ else:
+ # A blank line is resetting skip_unit
+ skip_unit = line != '\n'
+ fh.truncate()
+
+
def is_po_reduced(file_path):
status, output, errs = run_shell_command(['grep', 'X-DamnedLies-Scope: partial', file_path])
return (status == 0)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]