Merge lp:~savoirfairelinux-openerp/ocb-server/translate_warnings_1297525-trunk into lp:ocb-server

Status: Rejected
Rejected by: Holger Brunn (Therp)
Proposed branch: lp:~savoirfairelinux-openerp/ocb-server/translate_warnings_1297525-trunk
Merge into: lp:ocb-server
Diff against target: 69 lines (+9/-7)
3 files modified
openerp/osv/orm.py (+1/-1)
openerp/service/wsgi_server.py (+6/-4)
openerp/tools/translate.py (+2/-2)
To merge this branch: bzr merge lp:~savoirfairelinux-openerp/ocb-server/translate_warnings_1297525-trunk
Reviewer Review Type Date Requested Status
Holger Brunn (Therp) Disapprove
Stefan Rijnhart (Opener) Abstain
Sandy Carter (http://www.savoirfairelinux.com) Needs Information
OpenERP Community Reviewer/Maintainer Pending
Review via email: mp+212736@code.launchpad.net

Description of the change

When searching a frame for context, the _() looks for self.localcontext but misses self.context.
The integration of this patch allows for web warnings (such as except_orm) to be translated by _()

To post a comment you must log in.
Revision history for this message
Holger Brunn (Therp) (hbrunn) :
review: Approve (code review)
5296. By Mohammed Shekha(Open ERP)

[FIX]Base, Tools Translation: Fixed the issue of translation, warnings, except_orm and which is raised through OpenERPSession class send method or raised xmlrpclib.Fault in xmlrpc_handle_exception_legacy will also not be translatanble, also there is no way through which translation terms which are used outside any module like used in tools and service will not be registered in pot when translation is exported, we need to add those path explicitly.

5297. By El Hadji Dem (http://www.savoirfairelinux.com)

[FIX] Fixed instance of ValidateError not being translated

Revision history for this message
Sandy Carter (http://www.savoirfairelinux.com) (sandy-carter) wrote :

Two commits have been added:
r5296 from OpenERP's support
r5297 from our team for a case I missed of error message translation

Revision history for this message
Stefan Rijnhart (Opener) (stefan-opener) wrote :

Thanks for the proposal!

Strings like 'AccessError' and 'ValidateError' are not proper English, so they cannot be translated. Either we accept the current strings as fixed codes (in lieu of a proper exception type) and they should not be passed to gettext, or we should replace them with translatable strings such as Access Error and Validation Error.

review: Needs Fixing
Revision history for this message
Sandy Carter (http://www.savoirfairelinux.com) (sandy-carter) wrote :

@Stefan they give a satisfactory message when translated (no update to .po needed)

I don't want to change too much from the original code, but if you feel it's really needed, I can replace them with your suggestions.

review: Needs Information
Revision history for this message
Stefan Rijnhart (Opener) (stefan-opener) wrote :

Yes, I would like you to take the opportunity to improve this as well. I would prefer to see proper English here, but I am not sure if its value is checked on any occasion in case the exception is caught (in lieu of a proper exception subclassing, I can imagine).

5298. By Sandy Carter (http://www.savoirfairelinux.com)

[IMP] Use english translatable string in error popups

Revision history for this message
Sandy Carter (http://www.savoirfairelinux.com) (sandy-carter) wrote :

Done.

Please make sure this doesn't have funny side effects and translates properly.

Revision history for this message
Stefan Rijnhart (Opener) (stefan-opener) wrote :

OK, here's a reason not to change the labels and keep them untranslatable:

    hr_attendance/test/attendance_process.yml: assert e[0]=='ValidateError', e

Apparently, these labels are used in tests.

Revision history for this message
Sandy Carter (http://www.savoirfairelinux.com) (sandy-carter) wrote :

The tests fail anyway in any other language, especially in yml tests
Should I fix that assert too.

Revision history for this message
Stefan Rijnhart (Opener) (stefan-opener) wrote :

Well, if that is possible. What kind of solution were you thinking of to fix the test?

Revision history for this message
Sandy Carter (http://www.savoirfairelinux.com) (sandy-carter) wrote :

Basically, if I change the labels, I would change the message in the tests.
Ideally, an assertRaises should be used there, but I have no idea if yml tests support that.

Revision history for this message
Stefan Rijnhart (Opener) (stefan-opener) wrote :

Can you be sure that if a translator on Launchpad changed the translation of this term, it does not make the tests fail?

Revision history for this message
Stefan Rijnhart (Opener) (stefan-opener) wrote :

The en_US translation I mean.

Revision history for this message
Sandy Carter (http://www.savoirfairelinux.com) (sandy-carter) wrote :

It would make the tests fail, but this problem is widespread in OE.
For example test_20_message_post (openerp.addons.mail.tests.test_mail_features.test_mail) fails when a translator changes the value. It just doesn't fail in en_US because the values haven't changed. The same is not true for other locales.

A solution to this would be to use _() in the assert. I am not sure if that's possible in yml.

If we're talking about changing en_US why not revert my last commit and translate "ValidateError" as "Validate Error"?

Revision history for this message
Stefan Rijnhart (Opener) (stefan-opener) wrote :

I guess it's hard for us to decide without input from the upstream developers. I really don't want to break ocb tests, and to prevent that it would need a coordinated merge between the two projects. So I would therefore still favour having 'ValidateError' to be restored and untranslatable for ocb, but maybe change it to a translatable 'Validation Error' in proposals on upstream trunk server and the tests in addons?

Revision history for this message
Sandy Carter (http://www.savoirfairelinux.com) (sandy-carter) wrote :

I have already made some MPs for upstream, but the code is pretty different.

Revision history for this message
Stefan Rijnhart (Opener) (stefan-opener) wrote :

Not sure what you mean there. Do you think my suggestions are not a good idea?

Revision history for this message
Sandy Carter (http://www.savoirfairelinux.com) (sandy-carter) wrote :

Sorry. I didn't explain very well.
I have MPs for OCB, 7.0 and trunk for this bug.
OE trunk doesn't have both MP (server and web) because it too much, therefore web doesn't have an MP.
As for server, commits up to r5297 ([FIX] Fixed instance of ValidateError not being translated) have been proposed.

Revision history for this message
Stefan Rijnhart (Opener) (stefan-opener) wrote :

I think we need a reviewer with a fresh look on this.

review: Abstain
Revision history for this message
Holger Brunn (Therp) (hbrunn) wrote :

Development for 7.0 has moved to github on https://github.com/OCA/ocb - please move your merge proposal there if it is still valid.

(I close and reject this in order to have a cleaner overview for 6.1 MPs which indeed have to be done on launchpad)

review: Disapprove

Unmerged revisions

5298. By Sandy Carter (http://www.savoirfairelinux.com)

[IMP] Use english translatable string in error popups

5297. By El Hadji Dem (http://www.savoirfairelinux.com)

[FIX] Fixed instance of ValidateError not being translated

5296. By Mohammed Shekha(Open ERP)

[FIX]Base, Tools Translation: Fixed the issue of translation, warnings, except_orm and which is raised through OpenERPSession class send method or raised xmlrpclib.Fault in xmlrpc_handle_exception_legacy will also not be translatanble, also there is no way through which translation terms which are used outside any module like used in tools and service will not be registered in pot when translation is exported, we need to add those path explicitly.

5295. By Sandy Carter (http://www.savoirfairelinux.com)

Also look for context in self

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'openerp/osv/orm.py'
--- openerp/osv/orm.py 2014-04-07 10:57:40 +0000
+++ openerp/osv/orm.py 2014-04-30 15:28:06 +0000
@@ -1559,7 +1559,7 @@
1559 )1559 )
1560 self._invalids.update(fields)1560 self._invalids.update(fields)
1561 if error_msgs:1561 if error_msgs:
1562 raise except_orm('ValidateError', '\n'.join(error_msgs))1562 raise except_orm(_('Validate Error'), '\n'.join(error_msgs))
1563 else:1563 else:
1564 self._invalids.clear()1564 self._invalids.clear()
15651565
15661566
=== modified file 'openerp/service/wsgi_server.py'
--- openerp/service/wsgi_server.py 2013-11-25 10:38:42 +0000
+++ openerp/service/wsgi_server.py 2014-04-30 15:28:06 +0000
@@ -44,6 +44,7 @@
44import openerp44import openerp
45import openerp.modules45import openerp.modules
46import openerp.tools.config as config46import openerp.tools.config as config
47from openerp.tools.translate import _
47import websrv_lib48import websrv_lib
4849
49_logger = logging.getLogger(__name__)50_logger = logging.getLogger(__name__)
@@ -138,17 +139,18 @@
138 return response139 return response
139140
140def xmlrpc_handle_exception_legacy(e):141def xmlrpc_handle_exception_legacy(e):
142 code_string = u"%s -- %s\n\n%s"
141 if isinstance(e, openerp.osv.osv.except_osv):143 if isinstance(e, openerp.osv.osv.except_osv):
142 fault = xmlrpclib.Fault('warning -- ' + e.name + '\n\n' + e.value, '')144 fault = xmlrpclib.Fault(code_string % (_("warning"), e.name, e.value), '')
143 response = xmlrpclib.dumps(fault, allow_none=False, encoding=None)145 response = xmlrpclib.dumps(fault, allow_none=False, encoding=None)
144 elif isinstance(e, openerp.exceptions.Warning):146 elif isinstance(e, openerp.exceptions.Warning):
145 fault = xmlrpclib.Fault('warning -- Warning\n\n' + str(e), '')147 fault = xmlrpclib.Fault(code_string % (_("warning"), _("Warning"), e), '')
146 response = xmlrpclib.dumps(fault, allow_none=False, encoding=None)148 response = xmlrpclib.dumps(fault, allow_none=False, encoding=None)
147 elif isinstance(e, openerp.exceptions.AccessError):149 elif isinstance(e, openerp.exceptions.AccessError):
148 fault = xmlrpclib.Fault('warning -- AccessError\n\n' + str(e), '')150 fault = xmlrpclib.Fault(code_string % (_("warning"), _("Access Error"), e), '')
149 response = xmlrpclib.dumps(fault, allow_none=False, encoding=None)151 response = xmlrpclib.dumps(fault, allow_none=False, encoding=None)
150 elif isinstance(e, openerp.exceptions.AccessDenied):152 elif isinstance(e, openerp.exceptions.AccessDenied):
151 fault = xmlrpclib.Fault('AccessDenied', str(e))153 fault = xmlrpclib.Fault(_('Access Denied'), str(e))
152 response = xmlrpclib.dumps(fault, allow_none=False, encoding=None)154 response = xmlrpclib.dumps(fault, allow_none=False, encoding=None)
153 elif isinstance(e, openerp.exceptions.DeferredException):155 elif isinstance(e, openerp.exceptions.DeferredException):
154 info = e.traceback156 info = e.traceback
155157
=== modified file 'openerp/tools/translate.py'
--- openerp/tools/translate.py 2014-04-11 16:37:46 +0000
+++ openerp/tools/translate.py 2014-04-30 15:28:06 +0000
@@ -196,7 +196,7 @@
196 lang = ctx.get('lang')196 lang = ctx.get('lang')
197 s = frame.f_locals.get('self', {})197 s = frame.f_locals.get('self', {})
198 if not lang:198 if not lang:
199 c = getattr(s, 'localcontext', None)199 c = getattr(s, 'localcontext', None) or getattr(s, 'context', None)
200 if c:200 if c:
201 lang = c.get('lang')201 lang = c.get('lang')
202 if not lang:202 if not lang:
@@ -863,7 +863,7 @@
863 path_list = [root_path,] + apaths863 path_list = [root_path,] + apaths
864864
865 # Also scan these non-addon paths865 # Also scan these non-addon paths
866 for bin_path in ['osv', 'report' ]:866 for bin_path in ['osv', 'report', 'tools', 'service' ]:
867 path_list.append(os.path.join(config.config['root_path'], bin_path))867 path_list.append(os.path.join(config.config['root_path'], bin_path))
868868
869 _logger.debug("Scanning modules at paths: ", path_list)869 _logger.debug("Scanning modules at paths: ", path_list)