diff --git a/bin/addons/base/ir/ir.xml b/bin/addons/base/ir/ir.xml
index 3410aa98163..8ee400fed62 100644
--- a/bin/addons/base/ir/ir.xml
+++ b/bin/addons/base/ir/ir.xml
@@ -789,12 +789,12 @@
form
@@ -803,10 +803,11 @@
ir.translation
tree
-
+
+
+
-
diff --git a/bin/addons/base/ir/ir_translation.py b/bin/addons/base/ir/ir_translation.py
index d6485a6aec0..dedd34a3a28 100644
--- a/bin/addons/base/ir/ir_translation.py
+++ b/bin/addons/base/ir/ir_translation.py
@@ -28,15 +28,33 @@
from osv import fields, osv
from osv.osv import Cacheable
+import tools
+
+TRANSLATION_TYPE = [
+ ('field', 'Field'),
+ ('model', 'Model'),
+ ('rml', 'RML'),
+ ('selection', 'Selection'),
+ ('view', 'View'),
+ ('wizard_button', 'Wizard Button'),
+ ('wizard_field', 'Wizard Field'),
+ ('wizard_view', 'Wizard View'),
+ ('xsl', 'XSL'),
+ ('help', 'Help'),
+]
class ir_translation(osv.osv, Cacheable):
_name = "ir.translation"
_log_access = False
+
+ def _get_language(sel, cr, uid, context):
+ return tools.scan_languages()
+
_columns = {
'name': fields.char('Field Name', size=128, required=True),
'res_id': fields.integer('Resource ID'),
- 'lang': fields.char('Language', size=5),
- 'type': fields.char('Type', size=16),
+ 'lang': fields.selection(_get_language, string='Language', size=5),
+ 'type': fields.selection(TRANSLATION_TYPE, string='Type', size=16),
'src': fields.text('Source'),
'value': fields.text('Translation Value'),
}
diff --git a/bin/addons/base/module/wizard/wizard_import_lang.py b/bin/addons/base/module/wizard/wizard_import_lang.py
index ebb52517160..e8f99a8f292 100644
--- a/bin/addons/base/module/wizard/wizard_import_lang.py
+++ b/bin/addons/base/module/wizard/wizard_import_lang.py
@@ -45,17 +45,20 @@ view_form="""
"""
+fields_form={
+ 'name':{'string':'Language name', 'type':'char', 'size':64, 'required':True},
+ 'code':{'string':'Code (eg:en__US)', 'type':'char', 'size':5, 'required':True},
+ 'data':{'string':'File', 'type':'binary', 'required':True},
+}
+
class wizard_import_lang(wizard.interface):
+
def _import_lang(self, cr, uid, data, context):
form=data['form']
buf=base64.decodestring(data['form']['data']).split('\n')
tools.trans_load_data(cr.dbname, buf, form['code'], lang_name=form['name'])
return {}
- fields_form={
- 'name':{'string':'Language name', 'type':'char', 'size':64, 'required':True},
- 'code':{'string':'Code (eg:en_US)', 'type':'char', 'size':5, 'required':True},
- 'data':{'string':'File', 'type':'binary', 'required':True},
- }
+
states={
'init':{
'actions': [],
diff --git a/bin/osv/orm.py b/bin/osv/orm.py
index 4c37e20e129..0c7f6b04c60 100644
--- a/bin/osv/orm.py
+++ b/bin/osv/orm.py
@@ -1211,29 +1211,40 @@ class orm(object):
# returns the definition of each field in the object
# the optional fields parameter can limit the result to some fields
def fields_get(self, cr, user, fields=None, context=None):
- if not context:
- context={}
+ if context is None:
+ context = {}
res = {}
+ translation_obj = self.pool.get('ir.translation')
+ model_access_obj = self.pool.get('ir.model.access')
for parent in self._inherits:
- res.update(self.pool.get(parent).fields_get(cr, user, fields, context))
- read_access= self.pool.get('ir.model.access').check(cr, user, self._name,'write',raise_exception=False)
+ res.update(self.pool.get(parent).fields_get(cr, user, fields,
+ context))
+ read_access= model_access_obj.check(cr, user, self._name, 'write',
+ raise_exception=False)
for f in self._columns.keys():
res[f] = {'type': self._columns[f]._type}
- for arg in ('string','readonly','states','size','required','change_default','translate', 'help', 'select'):
+ for arg in ('string', 'readonly', 'states', 'size', 'required',
+ 'change_default', 'translate', 'help', 'select'):
if getattr(self._columns[f], arg):
res[f][arg] = getattr(self._columns[f], arg)
if not read_access:
res[f]['readonly']= True
- res[f]['states']={}
+ res[f]['states'] = {}
for arg in ('digits', 'invisible'):
- if hasattr(self._columns[f], arg) and getattr(self._columns[f], arg):
+ if hasattr(self._columns[f], arg) \
+ and getattr(self._columns[f], arg):
res[f][arg] = getattr(self._columns[f], arg)
# translate the field label
if context.get('lang', False) and context['lang'] != 'en_US':
- res_trans = self.pool.get('ir.translation')._get_source(cr, user, self._name+','+f, 'field', context['lang'])
+ res_trans = translation_obj._get_source(cr, user,
+ self._name + ',' + f, 'field', context['lang'])
if res_trans:
res[f]['string'] = res_trans
+ help_trans = translation_obj._get_source(cr, user,
+ self._name + ',' + f, 'help', context['lang'])
+ if help_trans:
+ res[f]['help'] = help_trans
if hasattr(self._columns[f], 'selection'):
if isinstance(self._columns[f].selection, (tuple, list)):
@@ -1243,14 +1254,18 @@ class orm(object):
if context.get('lang', False) and context['lang'] != 'en_US':
sel2 = []
for (key,val) in sel:
- val2 = self.pool.get('ir.translation')._get_source(cr, user, self._name+','+f, 'selection', context['lang'], val)
+ val2 = translation_obj._get_source(cr, user,
+ self._name + ',' + f, 'selection',
+ context['lang'], val)
sel2.append((key, val2 or val))
sel = sel2
res[f]['selection'] = sel
else:
# call the 'dynamic selection' function
- res[f]['selection'] = self._columns[f].selection(self, cr, user, context)
- if res[f]['type'] in ('one2many', 'many2many', 'many2one', 'one2one'):
+ res[f]['selection'] = self._columns[f].selection(self, cr,
+ user, context)
+ if res[f]['type'] in ('one2many', 'many2many',
+ 'many2one', 'one2one'):
res[f]['relation'] = self._columns[f]._obj
res[f]['domain'] = self._columns[f]._domain
res[f]['context'] = self._columns[f]._context
diff --git a/bin/tools/translate.py b/bin/tools/translate.py
index a1327c301ed..4e24df37c9f 100644
--- a/bin/tools/translate.py
+++ b/bin/tools/translate.py
@@ -137,6 +137,17 @@ def trans_generate(lang, modules, dbname=None):
if len(res):
value = res[0]['value']
out.append(["field", name, "0", field_def.string.encode('utf8'), value])
+ if field_def.help:
+ value = ''
+ if lang:
+ cr.execute('SELECT * FROM ir_translation ' \
+ 'WHERE type=\'help\' ' \
+ 'AND name = %s ' \
+ 'AND lang = %s', (name, lang))
+ res = cr.dictfetchall()
+ if res:
+ value = res[0]['value']
+ out.append(['help', name, '0', field_def.help.encode('utf8'), value])
if field_def.translate:
ids = osv.orm.orm.search(obj, cr, uid, [])
obj_values = obj.read(cr, uid, ids, [field_name])
@@ -274,7 +285,12 @@ def trans_load_data(db_name, data, lang, strict=False, lang_name=None):
langs = lang_obj.read(cr, uid, lang_ids)
ls = map(lambda x: (x['code'],x['name']), langs)
- ir.ir_set(cr, uid, 'meta', 'lang', 'lang', [('res.users',False,)], 'en', True, False, meta = {'type':'selection', 'string':'Language', 'selection':ls})
+ ir.ir_set(cr, uid, 'meta', 'lang', 'lang', [('res.users',False,)],
+ False, True, False, meta={
+ 'type': 'selection',
+ 'string': 'Language',
+ 'selection':ls,
+ })
ids = pool.get('res.users').search(cr, uid, [])
for id in ids: