Chris Biersbach (OpenERP) has proposed merging 
lp:~openerp-dev/openobject-server/6.1-opw-577045-cbi into 
lp:openobject-server/6.1.

Requested reviews:
  OpenERP Core Team (openerp)

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-server/6.1-opw-577045-cbi/+merge/126173

Note: Also see the related addons branch 
https://code.launchpad.net/~openerp-dev/openobject-addons/6.1-opw-577045-cbi

This fixes all of the following reports, where translations were missing:

product.pricelist.pdf
stock.move.label.pdf
stock.picking.list.pdf
stock.product.history.pdf
payment.order.pdf
account.general.ledger_landscape.pdf
account.account.balance.pdf
account.financial.report.pdf
account.journal.period.print.sale.purchase.pdf
account.journal.period.print.pdf
account.general.journal.pdf
account.central.journal.pdf
account.partner.balance.pdf
account.aged_trial_balance.pdf
account.third_party_ledger_other.pdf
holidays.summary.pdf
hr.analytical.timesheet_users.pdf

Changelog:

translate.py:
    - added parsing of python code to rml parser 
    - if there are multiple translations for the same term, pick one that is 
not equal to the source 
    - rewrote the trans_parse_xsl function (did not work at all)

interface.py:
    - rewrote the translate() method of report_rml (did not work at all, 
similar changes to trans_parse_xsl)

common_report_header.py:
    - added has_filter method
    - translated results of get_filter

account.account.balance:
    - added missing translate() calls
    - changed ugly equality checks to has_filter calls
    
account.central.journal: OK

account.general.journal: 
    - added missing translate() calls
    
account.general.ledger_landscape:
    - added missing translate() calls
    
stock.product.history:
    - added missing _() calls
    - added a cheat to pass cr and lang on _(...) calls
    - added context to 2 calls so that products are also translated
    
stock.picking.list:
    - added explicit translate() calls for the different possible states
    - added translate() call for "Non Assigned Products:"
   
product.pricelist:
    - added missing _() call
    
payment.order:
    - added missing translate() calls
    
account.vat.declaration:
    - changed get_basedon method to correctly return translated values
    
account.third_party_ledger_other:
    - added missing _() calls
    
account.partner.balance: OK

account.journal.period.print.sale.purchase:
    - added missing translate() calls
    - added missing _() calls
    - fixed incorrect selection field values
    
account.journal.period.print:
    - added missing translate() calls
    
account.financial.report: OK

account.analytic.account.budget:
    - added missing report to account_budget_report.xml
    
account.aged_trial_balance:
    - added "get_direction_selection" method that returns translated values
    - added missing translate() calls
    - added missing _() calls
    - changed "Period length(days)" to "period length (days)"
    
holidays.summary: OK

hr.analytical.timesheet_users: OK

stock.move.label:
    - added missing t="1" attributes
-- 
https://code.launchpad.net/~openerp-dev/openobject-server/6.1-opw-577045-cbi/+merge/126173
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openobject-server/6.1-opw-577045-cbi.
=== modified file 'openerp/report/interface.py'
--- openerp/report/interface.py	2011-09-24 14:52:58 +0000
+++ openerp/report/interface.py	2012-09-25 07:04:59 +0000
@@ -163,15 +163,30 @@
         # * (re)build/update the stylesheet with the translated items
 
         def translate(doc, lang):
-            for node in doc.xpath('//*[@t]'):
-                if not node.text:
-                    continue
-                translation = ir_translation_obj._get_source(cr, uid, self.name2, 'xsl', lang, node.text)
-                if translation:
-                    node.text = translation
-
+            translate_aux(doc, lang, False)
+            
+        def translate_aux(doc, lang, t):
+            for node in doc:
+                t = t or node.get("t")  
+                if t:
+                    text = None
+                    tail = None
+                    if node.text:
+                        text = node.text.strip().replace('\n',' ')    
+                    if node.tail:
+                        tail = node.tail.strip().replace('\n',' ')
+                    if text:
+                        translation1 = ir_translation_obj._get_source(cr, uid, self.name2, 'xsl', lang, text)
+                        if translation1:
+                            node.text = node.text.replace(text, translation1)
+                    if tail:
+                        translation2 = ir_translation_obj._get_source(cr, uid, self.name2, 'xsl', lang, tail)
+                        if translation2:
+                            node.tail = node.tail.replace(tail, translation2)
+                translate_aux(node, lang, t)  
+             
         if context.get('lang', False):
-            translate(stylesheet, context['lang'])
+            translate(stylesheet.iter(), context['lang'])
 
         transform = etree.XSLT(stylesheet)
         xml = etree.tostring(

=== modified file 'openerp/tools/translate.py'
--- openerp/tools/translate.py	2012-06-29 12:04:18 +0000
+++ openerp/tools/translate.py	2012-09-25 07:04:59 +0000
@@ -443,10 +443,15 @@
                 row = grouped_rows.setdefault(src, {})
                 row.setdefault('modules', set()).add(module)
                 if ('translation' not in row) or (not row['translation']):
-                    row['translation'] = trad
+                    if trad != src:
+                        row['translation'] = trad
                 row.setdefault('tnrs', []).append((type, name, res_id))
 
             for src, row in grouped_rows.items():
+                if newlang:
+                    row['translation'] = ''
+                elif not row.get('translation'):
+                    row['translation'] = src
                 writer.write(row['modules'], row['tnrs'], src, row['translation'])
 
         elif format == 'tgz':
@@ -487,17 +492,26 @@
     del trans
 
 def trans_parse_xsl(de):
+    return list(set(trans_parse_xsl_aux(de, False)))
+
+def trans_parse_xsl_aux(de, t):   
     res = []
+   
     for n in de:
-        if n.get("t"):
-            for m in n:
-                if isinstance(m, SKIPPED_ELEMENT_TYPES) or not m.text:
+        t = t or n.get("t")
+        if t:
+                if isinstance(n, SKIPPED_ELEMENT_TYPES) or n.tag.startswith('{http://www.w3.org/1999/XSL/Transform}'):
                     continue
-                l = m.text.strip().replace('\n',' ')
-                if len(l):
-                    res.append(l.encode("utf8"))
-        res.extend(trans_parse_xsl(n))
-    return res
+                if n.text:
+                    l = n.text.strip().replace('\n',' ')
+                    if len(l):
+                        res.append(l.encode("utf8"))
+                if n.tail:
+                    l = n.tail.strip().replace('\n',' ')
+                    if len(l):
+                        res.append(l.encode("utf8"))
+        res.extend(trans_parse_xsl_aux(n, t))
+    return res   
 
 def trans_parse_rml(de):
     res = []
@@ -506,9 +520,13 @@
             if isinstance(m, SKIPPED_ELEMENT_TYPES) or not m.text:
                 continue
             string_list = [s.replace('\n', ' ').strip() for s in re.split('\[\[.+?\]\]', m.text)]
+            string_list2 = [s.replace('\n', ' ').replace('translate(', '')[:-1].strip('"\'') for s in re.findall('translate\(.+?\)', m.text)]
             for s in string_list:
                 if s:
                     res.append(s.encode("utf8"))
+            for s in string_list2:
+                if s:
+                    res.append(s.encode("utf8"))
         res.extend(trans_parse_rml(n))
     return res
 

_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help   : https://help.launchpad.net/ListHelp

Reply via email to