[IMP] tools.translate: be more lenient and accept standart gettext source annotations
authorOlivier Dony <odo@openerp.com>
Thu, 2 Feb 2012 14:32:10 +0000 (15:32 +0100)
committerOlivier Dony <odo@openerp.com>
Thu, 2 Feb 2012 14:32:10 +0000 (15:32 +0100)
 The GetText spec says that PO auto-comments indicating
  the source location have this form:
   #: /path/to/file:lineno
  However OpenERP's POT export system defaults to a modified
  version of this format with an extra 'type' field:
   #: type:/path/to/file:lineno
  The babel extractors we use for openerp-web's translations
  have the GetText format hardcoded, so it's a good idea
  to be more lenient and allow the standards annotations too.
  We can use a default 'code' type for such cases.

  For openerp-web translations the type does not matter,
  as the translations will be directly loaded by the
  web engine from the PO files and served in Javascript
 to the browser, with no typing needed.

  This patch simply avoids failing to parse updated PO files
  that will contain standard GetText annotations for the
  openerp-web related terms.

bzr revid: odo@openerp.com-20120202143210-05p1w24t6u77cyv8

openerp/tools/translate.py

index dbf6bd9..d16049b 100644 (file)
@@ -296,11 +296,14 @@ class TinyPoFile(object):
                 if line.startswith('#~ '):
                     break
                 if line.startswith('#:'):
-                    if ' ' in line[2:].strip():
-                        for lpart in line[2:].strip().split(' '):
-                            tmp_tnrs.append(lpart.strip().split(':',2))
-                    else:
-                        tmp_tnrs.append( line[2:].strip().split(':',2) )
+                    for lpart in line[2:].strip().split(' '):
+                        trans_info = lpart.strip().split(':',2)
+                        if trans_info and len(trans_info) == 2:
+                            # looks like the translation type is missing, which is not
+                            # unexpected because it is not a GetText standard. Default: 'code'
+                            trans_info[:0] = ['code']
+                        if trans_info and len(trans_info) == 3:
+                            tmp_tnrs.append(trans_info)
                 elif line.startswith('#,') and (line[2:].strip() == 'fuzzy'):
                     fuzzy = True
                 line = self.lines.pop(0).strip()