changeset 9bf65e1188fb in trytond:default
details: https://hg.tryton.org/trytond?cmd=changeset;node=9bf65e1188fb
description:
        Do not create empty translations

        issue5452
        review267251002
diffstat:

 CHANGELOG                 |   1 +
 trytond/ir/translation.py |  16 +++++++++++++---
 2 files changed, 14 insertions(+), 3 deletions(-)

diffs (76 lines):

diff -r f1ee858677a7 -r 9bf65e1188fb CHANGELOG
--- a/CHANGELOG Mon Apr 15 15:56:03 2019 +0200
+++ b/CHANGELOG Mon Apr 15 16:07:52 2019 +0200
@@ -1,3 +1,4 @@
+* Do not create empty translations
 * Replace dsn by params to connect to postgresql
 * Simplify cron
 * Add duration on Cache
diff -r f1ee858677a7 -r 9bf65e1188fb trytond/ir/translation.py
--- a/trytond/ir/translation.py Mon Apr 15 15:56:03 2019 +0200
+++ b/trytond/ir/translation.py Mon Apr 15 16:07:52 2019 +0200
@@ -115,6 +115,8 @@
 
         name = model.__name__ + ',name'
         src = model._get_name()
+        if not src:
+            return
         cursor.execute(*ir_translation.select(ir_translation.id,
                 where=(ir_translation.lang == 'en')
                 & (ir_translation.type == 'model')
@@ -172,7 +174,7 @@
 
         def insert(field, type, name, string):
             for val in string:
-                if val in translations[type][name]:
+                if not val or val in translations[type][name]:
                     continue
                 cursor.execute(
                     *ir_translation.insert(columns,
@@ -202,6 +204,8 @@
         trans_buttons = {t['name']: t for t in cursor_dict(cursor)}
 
         def update_insert_button(state_name, button):
+            if not button.string:
+                return
             trans_name = '%s,%s,%s' % (
                 wizard.__name__, state_name, button.state)
             if trans_name not in trans_buttons:
@@ -422,6 +426,8 @@
                     else:
                         src = getattr(record, field_name)
                     if not translation:
+                        if not src and not value:
+                            continue
                         translation = cls()
                         translation.name = name
                         translation.lang = lang
@@ -467,6 +473,8 @@
                 else:
                     src = getattr(record, field_name)
                 if not translation:
+                    if not src and not value:
+                        continue
                     translation = cls()
                     translation.name = name
                     translation.lang = lang
@@ -847,7 +855,8 @@
             entry = polib.POEntry(msgid=(translation.src or ''),
                 msgstr=(translation.value or ''), msgctxt=trans_ctxt,
                 flags=flags)
-            pofile.append(entry)
+            if entry.msgid or entry.msgstr:
+                pofile.append(entry)
 
         if pofile:
             pofile.sort()
@@ -926,7 +935,8 @@
 
             for _, _, string, _ in genshi_extract(
                     content, keywords, comment_tags, options):
-                yield string
+                if string:
+                    yield string
         if not template_class:
             raise ValueError('a template class is required')
         return method

Reply via email to