Merge lp:~openerp-dev/openobject-server/7.0-opw-593029-msh into lp:openobject-server/7.0

Proposed by Mohammed Shekha(Open ERP)
Status: Needs review
Proposed branch: lp:~openerp-dev/openobject-server/7.0-opw-593029-msh
Merge into: lp:openobject-server/7.0
Diff against target: 74 lines (+18/-11)
4 files modified
openerp/addons/base/module/wizard/base_export_language.py (+1/-1)
openerp/addons/base/module/wizard/base_update_translations.py (+1/-1)
openerp/osv/orm.py (+9/-7)
openerp/tools/translate.py (+7/-2)
To merge this branch: bzr merge lp:~openerp-dev/openobject-server/7.0-opw-593029-msh
Reviewer Review Type Date Requested Status
Olivier Dony (Odoo) Disapprove
Martin Trigaux (OpenERP) Pending
Naresh(OpenERP) Pending
Review via email: mp+166438@code.launchpad.net

Description of the change

Hello,

Fixed the issue of tranlation of selection field when there is callable instead of list of tuple.

Demo:- Go to Project form and see there privacy_visisbility field which is selection field, this selection field is never going to be translated as there is callable function instead of list of tuple values.

So fixed if from fields_get and from trans_generate.

Thanks.

To post a comment you must log in.
Revision history for this message
Olivier Dony (Odoo) (odo-openerp) wrote :

I don't think we should change the behavior of the translation system for callable selection fields:

- in the API, when we have static strings we translate them automatically, but when we have callables they are responsible for translating their result. This is the case for the message of _constraints for example: if static it is translated, if callable it is not.
- in many cases the callables will read data from the database (e.g. a list of records), and if the results need to be translated it will already be done (with correct context lang)
- when exporting translations, if we take all results from callables we will have a lot of invalid/incorrect values that will pollute the POT files

Instead the right thing to do would be to fix the callable to make it return translated values correctly:

        return [('public', _('All Users')),
                ('employees', _('Employees Only')),
                ('followers', _('Followers Only'))]

Thanks!

review: Disapprove

Unmerged revisions

4990. By Mohammed Shekha<email address hidden>

[FIX]Fixed the issue of tranlation of selection field when there is callable instead of list of tuple.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'openerp/addons/base/module/wizard/base_export_language.py'
2--- openerp/addons/base/module/wizard/base_export_language.py 2012-12-10 15:27:23 +0000
3+++ openerp/addons/base/module/wizard/base_export_language.py 2013-05-30 05:19:40 +0000
4@@ -32,7 +32,7 @@
5 class base_language_export(osv.osv_memory):
6 _name = "base.language.export"
7
8- def _get_languages(self, cr, uid, context):
9+ def _get_languages(self, cr, uid, context=None):
10 lang_obj = self.pool.get('res.lang')
11 ids = lang_obj.search(cr, uid, [('translatable', '=', True)])
12 langs = lang_obj.browse(cr, uid, ids)
13
14=== modified file 'openerp/addons/base/module/wizard/base_update_translations.py'
15--- openerp/addons/base/module/wizard/base_update_translations.py 2012-12-10 15:27:23 +0000
16+++ openerp/addons/base/module/wizard/base_update_translations.py 2013-05-30 05:19:40 +0000
17@@ -26,7 +26,7 @@
18 from openerp.tools.translate import _
19
20 class base_update_translations(osv.osv_memory):
21- def _get_languages(self, cr, uid, context):
22+ def _get_languages(self, cr, uid, context=None):
23 lang_obj = self.pool.get('res.lang')
24 ids = lang_obj.search(cr, uid, ['&', ('active', '=', True), ('translatable', '=', True),])
25 langs = lang_obj.browse(cr, uid, ids)
26
27=== modified file 'openerp/osv/orm.py'
28--- openerp/osv/orm.py 2013-04-19 14:54:17 +0000
29+++ openerp/osv/orm.py 2013-05-30 05:19:40 +0000
30@@ -3527,15 +3527,17 @@
31 if help_trans:
32 res[f]['help'] = help_trans
33 if 'selection' in res[f]:
34+ sel = sel2 = []
35 if isinstance(field.selection, (tuple, list)):
36 sel = field.selection
37- sel2 = []
38- for key, val in sel:
39- val2 = None
40- if val:
41- val2 = translation_obj._get_source(cr, user, self._name + ',' + f, 'selection', context['lang'], val)
42- sel2.append((key, val2 or val))
43- res[f]['selection'] = sel2
44+ elif callable(field.selection):
45+ sel = field.selection(self, cr, user, context=context)
46+ for key, val in sel:
47+ val2 = None
48+ if val:
49+ val2 = translation_obj._get_source(cr, user, self._name + ',' + f, 'selection', context['lang'], val)
50+ sel2.append((key, val2 or val))
51+ res[f]['selection'] = sel2
52
53 return res
54
55
56=== modified file 'openerp/tools/translate.py'
57--- openerp/tools/translate.py 2013-03-07 16:45:58 +0000
58+++ openerp/tools/translate.py 2013-05-30 05:19:40 +0000
59@@ -751,8 +751,13 @@
60 if not model_data_ids:
61 push_translation(module, 'model', name, 0, encode(obj_value[field_name]))
62
63- if hasattr(field_def, 'selection') and isinstance(field_def.selection, (list, tuple)):
64- for dummy, val in field_def.selection:
65+ if hasattr(field_def, 'selection'):
66+ sel = []
67+ if isinstance(field_def.selection, (list, tuple)):
68+ sel = field_def.selection
69+ elif callable(field_def.selection):
70+ sel = field_def.selection(objmodel, cr, uid, {})
71+ for dummy, val in sel:
72 push_translation(module, 'selection', name, 0, encode(val))
73
74 elif model=='ir.actions.report.xml':