Merge lp:~openerp-dev/openobject-server/6.0-opw-18482-atp into lp:openobject-server/6.0

Proposed by Atul Patel(OpenERP)
Status: Rejected
Rejected by: Olivier Dony (Odoo)
Proposed branch: lp:~openerp-dev/openobject-server/6.0-opw-18482-atp
Merge into: lp:openobject-server/6.0
Diff against target: 131 lines (+33/-14)
1 file modified
bin/tools/translate.py (+33/-14)
To merge this branch: bzr merge lp:~openerp-dev/openobject-server/6.0-opw-18482-atp
Reviewer Review Type Date Requested Status
Olivier Dony (Odoo) Disapprove
Lorenzo Battistini (community) Approve
Olivier Dony (Old Profile) Pending
Review via email: mp+81701@code.launchpad.net

Description of the change

Hello,

[Issue:18482]- Bad format of exported report translation
 I have fixed issue and Improve translations for webkit report sample using export po.

there is also bug in which step is mentioned. here is link:
https://bugs.launchpad.net/openobject-server/+bug/819334

kindly review it.

Thanks
Atul

To post a comment you must log in.
Revision history for this message
Lorenzo Battistini (elbati) wrote :

Hello Atul,

according to my tests, this merge fixes bug 819334 .

Thanks

review: Approve
Revision history for this message
Olivier Dony (Odoo) (odo-openerp) wrote :

I might be wrong, but wouldn't a patch in report_webkit itself be much simpler and less riskier for stable?

For example this minimalist patch [1] makes webkit reports translations global to all webkit reports. This is pretty much what happens with terms that come from the code at the moment, and terms from mako templates are very similar to code. I think it would be sufficient and acceptable here.

[1] http://pastebin.com/KsFEFZyQ

review: Needs Information
Revision history for this message
Rifakat Husen (OpenERP) (rha-openerp) wrote :

@odo: I understand your concern here.
I applied your patch and it didn't work for me. Its calling translate_call() of report_webkit,
but while we do export of any po file from 'Export Translation', its calling server's act_getfile() of base.language.export

report_webkit does not come into picture in exporting po procedure.

Correct me if I am missing something.

Regards.

Revision history for this message
Olivier Dony (Odoo) (odo-openerp) wrote :

On 11/22/2011 07:38 AM, Rifakat (OpenERP) wrote:
> @odo: I understand your concern here.
> I applied your patch and it didn't work for me. Its calling translate_call() of report_webkit,
> but while we do export of any po file from 'Export Translation', its calling server's act_getfile() of base.language.export
>
> report_webkit does not come into picture in exporting po procedure.

Yes that seems like the expected behavior.
As far as I can see on the bug report, the problem is that
translate_call() does not consider the translated strings because it
uses a different name than what is exported in the PO files.

The bug report says:

"""
Due to the line
#: report:addons/report_webkit_sample/report/report_webkit_html.mako:35
translation couldn't correctly imported.
"""

This is the same export format as for strings that come from the code
with _(). And as I explained, I think the exported format is fine!
We decided to consider the mako templates of report_webkit just like
normal code, as they are also using something similar to _().
So there is no reason to change that, and it's fine to see
"report:addons/report_webkit_sample/report/report_webkit_html.mako" in
the exported PO!

The only thing to do is to make translate_call() behave like the _()
method we use in the code, and thus make it ignore the name of the
report, which cannot be matched properly, just like for string that cme
from code. This is what my one-line patch is trying to do.

> Correct me if I am missing something.

Have you tested the case of the bug report after applying my patch?
If it does not work, please explain what does not work:
- what entries do you have in ir.translation after importing a PO
containing webkit translations
- are the strings translated when you generate the report in the PO
language?
- if not, can you investigate why translate_call does not find them?

Keep in mind that we want to fix the fact that the translations are
ignored, *not* the format in which the translations are exported.

Thanks!

Revision history for this message
Rifakat Husen (OpenERP) (rha-openerp) wrote :

Hello Olivier,

Thanks for the clarification.

The problem I am facing is,

While calling the method _get_source() we pass name as None from translate_call(),
but always get name(mako path) in _get_source() rather than None.

Yes I have tested the case with our patch,
>- what entries do you have in ir.translation after importing a PO
>containing webkit translations
Lang: Italiano
name: addons/report_webkit_sample/report/report_webkit_html.mako
source: Supplier Invoice
value: Fattura Fornitore

>- are the strings translated when you generate the report in the PO
>language?
Yes, strings are translated.

Thanks for your help.

Revision history for this message
Olivier Dony (Odoo) (odo-openerp) wrote :

On 11/28/2011 01:38 PM, Rifakat (OpenERP) wrote:
> The problem I am facing is,
>
> While calling the method _get_source() we pass name as None from translate_call(),
> but always get name(mako path) in _get_source() rather than None.

Yes, and that's fine. We don't pass name=None because we expect to have
name=None in the ir.translation table, we pass name=None because we
don't know the name and don't care about matching it.
ir.translation._get_source will not try to match the name if we pass
None. This is just the same as what happens with strings that come from
Python code like _('foo').

> Yes I have tested the case with our patch,
>> - what entries do you have in ir.translation after importing a PO
>> containing webkit translations
> Lang: Italiano
> name: addons/report_webkit_sample/report/report_webkit_html.mako
> source: Supplier Invoice
> value: Fattura Fornitore

Looks correct.

>> - are the strings translated when you generate the report in the PO
>> language?
> Yes, strings are translated.

Then that patch is working fine from the beginning.
As I explained, all we care about is to be able to get translated
strings in final webkit reports, the rest of the bug report can be
ignored. So if it works, use it, we're done, no need to waste more time
on this.

Revision history for this message
Olivier Dony (Odoo) (odo-openerp) wrote :

Update: the proper one-line patch has landed on trunk addons at revision [1] and was backported to 6.0 at revision [2].
See the commit comment of revision [1] for more details if my comments on the current merge proposal are not clear enough.

[1] trunk addons rev.6365 revid: <email address hidden>
[2] 6.0 addons rev.5009 revid: <email address hidden>

review: Disapprove

Unmerged revisions

3536. By Atul Patel(OpenERP)

[FIX]translations: support webkit report translation.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'bin/tools/translate.py'
--- bin/tools/translate.py 2011-06-08 12:56:28 +0000
+++ bin/tools/translate.py 2011-11-09 10:14:13 +0000
@@ -42,6 +42,11 @@
42from tools.misc import UpdateableStr42from tools.misc import UpdateableStr
43from tools.misc import SKIPPED_ELEMENT_TYPES43from tools.misc import SKIPPED_ELEMENT_TYPES
4444
45join_dquotes = re.compile(r'([^\\])"[\s\\]*"', re.DOTALL)
46join_quotes = re.compile(r'([^\\])\'[\s\\]*\'', re.DOTALL)
47re_dquotes = re.compile(r'[^a-zA-Z0-9_]_\([\s]*"(.+?)"[\s]*?\)', re.DOTALL)
48re_quotes = re.compile(r'[^a-zA-Z0-9_]_\([\s]*\'(.+?)\'[\s]*?\)', re.DOTALL)
49
45_LOCALE2WIN32 = {50_LOCALE2WIN32 = {
46 'af_ZA': 'Afrikaans_South Africa',51 'af_ZA': 'Afrikaans_South Africa',
47 'sq_AL': 'Albanian_Albania',52 'sq_AL': 'Albanian_Albania',
@@ -316,6 +321,7 @@
316 if not line.startswith('msgid'):321 if not line.startswith('msgid'):
317 raise Exception("malformed file: bad line: %s" % line)322 raise Exception("malformed file: bad line: %s" % line)
318 source = unquote(line[6:])323 source = unquote(line[6:])
324
319 line = self.lines.pop(0).strip()325 line = self.lines.pop(0).strip()
320 if not source and self.first:326 if not source and self.first:
321 # if the source is "" and it's the first msgid, it's the special327 # if the source is "" and it's the first msgid, it's the special
@@ -482,6 +488,16 @@
482 res.extend(trans_parse_xsl(n))488 res.extend(trans_parse_xsl(n))
483 return res489 return res
484490
491def trans_parse_webkit(de):
492 res = []
493 ite = re_dquotes.finditer(de)
494 for i in ite:
495 src = i.group(1)
496 src = join_dquotes.sub(r'\1', src)
497 src = src.decode('string_escape')
498 res.append(src)
499 return res
500
485def trans_parse_rml(de):501def trans_parse_rml(de):
486 res = []502 res = []
487 for n in de:503 for n in de:
@@ -534,7 +550,6 @@
534 uid = 1550 uid = 1
535 l = pool.obj_pool.items()551 l = pool.obj_pool.items()
536 l.sort()552 l.sort()
537
538 query = 'SELECT name, model, res_id, module' \553 query = 'SELECT name, model, res_id, module' \
539 ' FROM ir_model_data'554 ' FROM ir_model_data'
540555
@@ -554,7 +569,6 @@
554 query_models += ' ORDER BY module, model'569 query_models += ' ORDER BY module, model'
555570
556 cr.execute(query, query_param)571 cr.execute(query, query_param)
557
558 _to_translate = []572 _to_translate = []
559 def push_translation(module, type, name, id, source):573 def push_translation(module, type, name, id, source):
560 tuple = (module, source, name, id, type)574 tuple = (module, source, name, id, type)
@@ -669,12 +683,27 @@
669 fname = ""683 fname = ""
670 if obj.report_rml:684 if obj.report_rml:
671 fname = obj.report_rml685 fname = obj.report_rml
672 parse_func = trans_parse_rml686 file, fileextension = os.path.splitext(fname)
687 if fileextension == '.mako':
688 parse_func = trans_parse_webkit
689 report_type = "report"
690 else:
691 parse_func = trans_parse_rml
673 report_type = "report"692 report_type = "report"
693
674 elif obj.report_xsl:694 elif obj.report_xsl:
675 fname = obj.report_xsl695 fname = obj.report_xsl
676 parse_func = trans_parse_xsl696 parse_func = trans_parse_xsl
677 report_type = "xsl"697 report_type = "xsl"
698
699 if obj.report_type == 'webkit':
700 report_file = tools.file_open(fname)
701 dt = report_file.read()
702 res = parse_func(dt)
703 name = 'report.%s' % name
704 for src in res:
705 push_translation(module, report_type, name, 0, src)
706
678 if fname and obj.report_type in ('pdf', 'xsl'):707 if fname and obj.report_type in ('pdf', 'xsl'):
679 try:708 try:
680 report_file = tools.file_open(fname)709 report_file = tools.file_open(fname)
@@ -697,15 +726,12 @@
697 push_translation(module, 'model', name, xml_name, encode(trad))726 push_translation(module, 'model', name, xml_name, encode(trad))
698727
699 # End of data for ir.model.data query results728 # End of data for ir.model.data query results
700
701 cr.execute(query_models, query_param)729 cr.execute(query_models, query_param)
702
703 def push_constraint_msg(module, term_type, model, msg):730 def push_constraint_msg(module, term_type, model, msg):
704 # Check presence of __call__ directly instead of using731 # Check presence of __call__ directly instead of using
705 # callable() because it will be deprecated as of Python 3.0732 # callable() because it will be deprecated as of Python 3.0
706 if not hasattr(msg, '__call__'):733 if not hasattr(msg, '__call__'):
707 push_translation(module, term_type, model, 0, encode(msg))734 push_translation(module, term_type, model, 0, encode(msg))
708
709 for (model_id, model, module) in cr.fetchall():735 for (model_id, model, module) in cr.fetchall():
710 module = encode(module)736 module = encode(module)
711 model = encode(model)737 model = encode(model)
@@ -760,11 +786,7 @@
760 logger.debug("Scanning modules at paths: ", path_list)786 logger.debug("Scanning modules at paths: ", path_list)
761787
762 mod_paths = []788 mod_paths = []
763 join_dquotes = re.compile(r'([^\\])"[\s\\]*"', re.DOTALL)789
764 join_quotes = re.compile(r'([^\\])\'[\s\\]*\'', re.DOTALL)
765 re_dquotes = re.compile(r'[^a-zA-Z0-9_]_\([\s]*"(.+?)"[\s]*?\)', re.DOTALL)
766 re_quotes = re.compile(r'[^a-zA-Z0-9_]_\([\s]*\'(.+?)\'[\s]*?\)', re.DOTALL)
767
768 def export_code_terms_from_file(fname, path, root, terms_type):790 def export_code_terms_from_file(fname, path, root, terms_type):
769 fabsolutepath = join(root, fname)791 fabsolutepath = join(root, fname)
770 frelativepath = fabsolutepath[len(path):]792 frelativepath = fabsolutepath[len(path):]
@@ -819,8 +841,6 @@
819 for root, dummy, files in tools.osutil.walksymlinks(path):841 for root, dummy, files in tools.osutil.walksymlinks(path):
820 for fname in itertools.chain(fnmatch.filter(files, '*.py')):842 for fname in itertools.chain(fnmatch.filter(files, '*.py')):
821 export_code_terms_from_file(fname, path, root, 'code')843 export_code_terms_from_file(fname, path, root, 'code')
822 for fname in itertools.chain(fnmatch.filter(files, '*.mako')):
823 export_code_terms_from_file(fname, path, root, 'report')
824844
825845
826 out = [["module","type","name","res_id","src","value"]] # header846 out = [["module","type","name","res_id","src","value"]] # header
@@ -829,7 +849,6 @@
829 for module, source, name, id, type in _to_translate:849 for module, source, name, id, type in _to_translate:
830 trans = trans_obj._get_source(cr, uid, name, type, lang, source)850 trans = trans_obj._get_source(cr, uid, name, type, lang, source)
831 out.append([module, type, name, id, source, encode(trans) or ''])851 out.append([module, type, name, id, source, encode(trans) or ''])
832
833 return out852 return out
834853
835def trans_load(cr, filename, lang, verbose=True, context=None):854def trans_load(cr, filename, lang, verbose=True, context=None):