Improve translation
- Translate help text - Better view of translation - Fix wizard that import lang bzr revid: ced-008b5b15580909d32caa00121c0c1c20622c4fd3
This commit is contained in:
parent
648d08dc71
commit
e7ac3b5f85
|
@ -789,12 +789,12 @@
|
|||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Translations">
|
||||
<field name="name" select="1"/>
|
||||
<field name="name" select="2"/>
|
||||
<field name="res_id" select="2"/>
|
||||
<field name="type" select="2"/>
|
||||
<field name="lang" select="1"/>
|
||||
<field name="src" colspan="4" select="1"/>
|
||||
<field name="type" select="1"/>
|
||||
<field name="res_id" select="1"/>
|
||||
<field name="value" colspan="4" select="1"/>
|
||||
<field name="src" select="1"/>
|
||||
<field name="value" select="1"/>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
@ -803,10 +803,11 @@
|
|||
<field name="model">ir.translation</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Translations">
|
||||
<tree string="Translations" editable="bottom">
|
||||
<field name="src"/>
|
||||
<field name="value"/>
|
||||
<field name="name"/>
|
||||
<field name="lang"/>
|
||||
<field name="src"/>
|
||||
<field name="type"/>
|
||||
</tree>
|
||||
</field>
|
||||
|
|
|
@ -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'),
|
||||
}
|
||||
|
|
|
@ -45,17 +45,20 @@ view_form="""<?xml version="1.0"?>
|
|||
</group>
|
||||
</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': [],
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue