Allow to translate en_US language (custom)
- en_US is translatable also - fix cache on translation - add view to language - fix client translation windows bzr revid: ced-b6ab18eba46eb8e1e8a97ed5afa6797078cec659
This commit is contained in:
parent
80a9af32db
commit
0caeaf1d9b
|
@ -25,6 +25,7 @@
|
||||||
"module/module_report.xml",
|
"module/module_report.xml",
|
||||||
# "module/move_module_wizard.xml",
|
# "module/move_module_wizard.xml",
|
||||||
"res/res_request_view.xml",
|
"res/res_request_view.xml",
|
||||||
|
"res/res_lang_view.xml",
|
||||||
"res/partner/partner_report.xml",
|
"res/partner/partner_report.xml",
|
||||||
"res/partner/partner_view.xml",
|
"res/partner/partner_view.xml",
|
||||||
"res/partner/partner_wizard.xml",
|
"res/partner/partner_wizard.xml",
|
||||||
|
|
|
@ -47,8 +47,16 @@ class ir_translation(osv.osv, Cacheable):
|
||||||
_name = "ir.translation"
|
_name = "ir.translation"
|
||||||
_log_access = False
|
_log_access = False
|
||||||
|
|
||||||
def _get_language(sel, cr, uid, context):
|
def _get_language(self, cr, uid, context):
|
||||||
return tools.scan_languages()
|
lang_obj = self.pool.get('res.lang')
|
||||||
|
lang_ids = lang_obj.search(cr, uid, [('translatable', '=', True)],
|
||||||
|
context=context)
|
||||||
|
langs = lang_obj.browse(cr, uid, lang_ids, context=context)
|
||||||
|
res = [(lang.code, lang.name) for lang in langs]
|
||||||
|
for lang_dict in tools.scan_languages():
|
||||||
|
if lang_dict not in res:
|
||||||
|
res.append(lang_dict)
|
||||||
|
return res
|
||||||
|
|
||||||
_columns = {
|
_columns = {
|
||||||
'name': fields.char('Field Name', size=128, required=True),
|
'name': fields.char('Field Name', size=128, required=True),
|
||||||
|
@ -67,35 +75,67 @@ class ir_translation(osv.osv, Cacheable):
|
||||||
translations, to_fetch = {}, []
|
translations, to_fetch = {}, []
|
||||||
for id in ids:
|
for id in ids:
|
||||||
trans = self.get((lang, name, id))
|
trans = self.get((lang, name, id))
|
||||||
if trans:
|
if trans is not None:
|
||||||
translations[id] = trans
|
translations[id] = trans
|
||||||
else:
|
else:
|
||||||
to_fetch.append(id)
|
to_fetch.append(id)
|
||||||
if to_fetch:
|
if to_fetch:
|
||||||
cr.execute('select res_id,value from ir_translation where lang=%s and type=%s and name=%s and res_id in ('+','.join(map(str, to_fetch))+')', (lang,tt,name))
|
cr.execute('select res_id,value ' \
|
||||||
|
'from ir_translation ' \
|
||||||
|
'where lang=%s ' \
|
||||||
|
'and type=%s ' \
|
||||||
|
'and name=%s ' \
|
||||||
|
'and res_id in ('+','.join(map(str, to_fetch))+')',
|
||||||
|
(lang,tt,name))
|
||||||
for res_id, value in cr.fetchall():
|
for res_id, value in cr.fetchall():
|
||||||
self.add((lang, tt, name, res_id), value)
|
self.add((lang, tt, name, res_id), value)
|
||||||
translations[res_id] = value
|
translations[res_id] = value
|
||||||
|
for res_id in ids:
|
||||||
|
if res_id not in translations:
|
||||||
|
self.add((lang, tt, name, res_id), False)
|
||||||
|
translations[res_id] = False
|
||||||
return translations
|
return translations
|
||||||
|
|
||||||
def _set_ids(self, cr, uid, name, tt, lang, ids, value):
|
def _set_ids(self, cr, uid, name, tt, lang, ids, value):
|
||||||
cr.execute('delete from ir_translation where lang=%s and type=%s and name=%s and res_id in ('+','.join(map(str,ids))+')', (lang,tt,name))
|
cr.execute('delete from ir_translation ' \
|
||||||
|
'where lang=%s ' \
|
||||||
|
'and type=%s ' \
|
||||||
|
'and name=%s ' \
|
||||||
|
'and res_id in ('+','.join(map(str,ids))+')',
|
||||||
|
(lang,tt,name))
|
||||||
for id in ids:
|
for id in ids:
|
||||||
self.create(cr, uid, {'lang':lang, 'type':tt, 'name':name, 'res_id':id, 'value':value})
|
self.create(cr, uid, {
|
||||||
|
'lang':lang,
|
||||||
|
'type':tt,
|
||||||
|
'name':name,
|
||||||
|
'res_id':id,
|
||||||
|
'value':value,
|
||||||
|
})
|
||||||
return len(ids)
|
return len(ids)
|
||||||
|
|
||||||
def _get_source(self, cr, uid, name, tt, lang, source=None):
|
def _get_source(self, cr, uid, name, tt, lang, source=None):
|
||||||
trans = self.get((lang, tt, name, source))
|
trans = self.get((lang, tt, name, source))
|
||||||
if trans:
|
if trans is not None:
|
||||||
return trans
|
return trans
|
||||||
|
|
||||||
if source:
|
if source:
|
||||||
source = source.strip().replace('\n',' ')
|
source = source.strip().replace('\n',' ')
|
||||||
if isinstance(source, unicode):
|
if isinstance(source, unicode):
|
||||||
source = source.encode('utf8')
|
source = source.encode('utf8')
|
||||||
cr.execute('select value from ir_translation where lang=%s and type=%s and name=%s and src=%s', (lang, tt, str(name), source))
|
cr.execute('select value ' \
|
||||||
|
'from ir_translation ' \
|
||||||
|
'where lang=%s ' \
|
||||||
|
'and type=%s ' \
|
||||||
|
'and name=%s ' \
|
||||||
|
'and src=%s',
|
||||||
|
(lang, tt, str(name), source))
|
||||||
else:
|
else:
|
||||||
cr.execute('select value from ir_translation where lang=%s and type=%s and name=%s', (lang, tt, str(name)))
|
cr.execute('select value ' \
|
||||||
|
'from ir_translation ' \
|
||||||
|
'where lang=%s ' \
|
||||||
|
'and type=%s ' \
|
||||||
|
'and name=%s',
|
||||||
|
(lang, tt, str(name)))
|
||||||
res = cr.fetchone()
|
res = cr.fetchone()
|
||||||
if res:
|
if res:
|
||||||
self.add((lang, tt, name, source), res[0])
|
self.add((lang, tt, name, source), res[0])
|
||||||
|
@ -103,4 +143,20 @@ class ir_translation(osv.osv, Cacheable):
|
||||||
else:
|
else:
|
||||||
self.add((lang, tt, name, source), False)
|
self.add((lang, tt, name, source), False)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def unlink(self, cursor, user, ids, context=None):
|
||||||
|
self.clear()
|
||||||
|
return super(ir_translation, self).unlink(cusor, user, ids,
|
||||||
|
context=context)
|
||||||
|
|
||||||
|
def create(self, cursor, user, vals, context=None):
|
||||||
|
self.clear()
|
||||||
|
return super(ir_translation, self).create(cursor, user, ids,
|
||||||
|
context=context)
|
||||||
|
|
||||||
|
def write(self, cursor, user, ids, vals, context=None):
|
||||||
|
self.clear()
|
||||||
|
return super(ir_translation, self).write(cursor, user, ids,
|
||||||
|
context=context)
|
||||||
|
|
||||||
ir_translation()
|
ir_translation()
|
||||||
|
|
|
@ -34,6 +34,7 @@ import partner
|
||||||
import res_currency
|
import res_currency
|
||||||
import res_company
|
import res_company
|
||||||
import res_user
|
import res_user
|
||||||
|
import res_lang
|
||||||
import res_request
|
import res_request
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
##############################################################################
|
||||||
|
#
|
||||||
|
# Copyright (c) 2007 TINY SPRL. (http://tiny.be) All Rights Reserved.
|
||||||
|
# Fabien Pinckaers <fp@tiny.Be>
|
||||||
|
#
|
||||||
|
# WARNING: This program as such is intended to be used by professional
|
||||||
|
# programmers who take the whole responsability of assessing all potential
|
||||||
|
# consequences resulting from its eventual inadequacies and bugs
|
||||||
|
# End users who are looking for a ready-to-use solution with commercial
|
||||||
|
# garantees and support are strongly adviced to contract a Free Software
|
||||||
|
# Service Company
|
||||||
|
#
|
||||||
|
# This program is Free Software; you can redistribute it and/or
|
||||||
|
# modify it under the terms of the GNU General Public License
|
||||||
|
# as published by the Free Software Foundation; either version 2
|
||||||
|
# of the License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
#
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
|
from osv import fields, osv
|
||||||
|
|
||||||
|
class lang(osv.osv):
|
||||||
|
_name = "res.lang"
|
||||||
|
_columns = {
|
||||||
|
'name': fields.char('Name', size=64, required=True),
|
||||||
|
'code': fields.char('Code', size=5, required=True),
|
||||||
|
'translatable': fields.boolean('Translatable'),
|
||||||
|
'active': fields.boolean('Active'),
|
||||||
|
'direction': fields.selection([('ltr', 'Left-to-right'), ('rtl', 'Right-to-left')], 'Direction',resuired=True),
|
||||||
|
}
|
||||||
|
_defaults = {
|
||||||
|
'active': lambda *a: 1,
|
||||||
|
'translatable': lambda *a: 0,
|
||||||
|
'direction': lambda *a: 'ltr',
|
||||||
|
}
|
||||||
|
|
||||||
|
lang()
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<terp>
|
||||||
|
<data>
|
||||||
|
<record model="ir.ui.view" id="res_lang_tree">
|
||||||
|
<field name="name">res.lang.tree</field>
|
||||||
|
<field name="model">res.lang</field>
|
||||||
|
<field name="type">tree</field>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<tree string="Languages" editable="bottom">
|
||||||
|
<field name="name"/>
|
||||||
|
<field name="code"/>
|
||||||
|
<field name="direction"/>
|
||||||
|
<field name="translatable"/>
|
||||||
|
<field name="active"/>
|
||||||
|
</tree>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
<record model="ir.actions.act_window" id="res_lang_act_window">
|
||||||
|
<field name="res_model">res.lang</field>
|
||||||
|
<field name="view_type">form</field>
|
||||||
|
<field name="context">{'active_test': False}</field>
|
||||||
|
</record>
|
||||||
|
<menuitem name="Administration/Translations/Languages"
|
||||||
|
action="res_lang_act_window" id="menu_res_lang_act_window"/>
|
||||||
|
</data>
|
||||||
|
</terp>
|
|
@ -81,22 +81,6 @@ class roles(osv.osv):
|
||||||
return False
|
return False
|
||||||
roles()
|
roles()
|
||||||
|
|
||||||
class lang(osv.osv):
|
|
||||||
_name = "res.lang"
|
|
||||||
_columns = {
|
|
||||||
'name': fields.char('Name', size=64, required=True),
|
|
||||||
'code': fields.char('Code', size=5, required=True),
|
|
||||||
'translatable': fields.boolean('Translatable'),
|
|
||||||
'active': fields.boolean('Active'),
|
|
||||||
'direction': fields.selection([('ltr', 'Left-to-right'), ('rtl', 'Right-to-left')], 'Direction',resuired=True),
|
|
||||||
}
|
|
||||||
_defaults = {
|
|
||||||
'active': lambda *a: 1,
|
|
||||||
'translatable': lambda *a: 0,
|
|
||||||
'direction': lambda *a: 'ltr',
|
|
||||||
}
|
|
||||||
lang()
|
|
||||||
|
|
||||||
class users(osv.osv):
|
class users(osv.osv):
|
||||||
_name = "res.users"
|
_name = "res.users"
|
||||||
_log_access = False
|
_log_access = False
|
||||||
|
|
|
@ -824,13 +824,12 @@ class orm(object):
|
||||||
else:
|
else:
|
||||||
res = map(lambda x: {'id':x}, ids)
|
res = map(lambda x: {'id':x}, ids)
|
||||||
|
|
||||||
if context.get('lang', False) and context['lang'] != 'en_US':
|
for f in fields_pre:
|
||||||
for f in fields_pre:
|
if self._columns[f].translate:
|
||||||
if self._columns[f].translate:
|
ids = map(lambda x: x['id'], res)
|
||||||
ids = map(lambda x: x['id'], res)
|
res_trans = self.pool.get('ir.translation')._get_ids(cr, user, self._name+','+f, 'model', context.get('lang', False) or 'en_US', ids)
|
||||||
res_trans = self.pool.get('ir.translation')._get_ids(cr, user, self._name+','+f, 'model', context['lang'], ids)
|
for r in res:
|
||||||
for r in res:
|
r[f] = res_trans.get(r['id'], False) or r[f]
|
||||||
r[f] = res_trans.get(r['id'], r[f])
|
|
||||||
|
|
||||||
for table in self._inherits:
|
for table in self._inherits:
|
||||||
col = self._inherits[table]
|
col = self._inherits[table]
|
||||||
|
@ -1284,29 +1283,26 @@ class orm(object):
|
||||||
res[f][arg] = getattr(self._columns[f], arg)
|
res[f][arg] = getattr(self._columns[f], arg)
|
||||||
|
|
||||||
# translate the field label
|
# translate the field label
|
||||||
if context.get('lang', False) and context['lang'] != 'en_US':
|
res_trans = translation_obj._get_source(cr, user,
|
||||||
res_trans = translation_obj._get_source(cr, user,
|
self._name + ',' + f, 'field', context.get('lang', False) or 'en_US')
|
||||||
self._name + ',' + f, 'field', context['lang'])
|
if res_trans:
|
||||||
if res_trans:
|
res[f]['string'] = res_trans
|
||||||
res[f]['string'] = res_trans
|
help_trans = translation_obj._get_source(cr, user,
|
||||||
help_trans = translation_obj._get_source(cr, user,
|
self._name + ',' + f, 'help', context.get('lang', False) or 'en_US')
|
||||||
self._name + ',' + f, 'help', context['lang'])
|
if help_trans:
|
||||||
if help_trans:
|
res[f]['help'] = help_trans
|
||||||
res[f]['help'] = help_trans
|
|
||||||
|
|
||||||
if hasattr(self._columns[f], 'selection'):
|
if hasattr(self._columns[f], 'selection'):
|
||||||
if isinstance(self._columns[f].selection, (tuple, list)):
|
if isinstance(self._columns[f].selection, (tuple, list)):
|
||||||
sel = self._columns[f].selection
|
sel = self._columns[f].selection
|
||||||
|
|
||||||
# translate each selection option
|
# translate each selection option
|
||||||
if context.get('lang', False) and context['lang'] != 'en_US':
|
sel2 = []
|
||||||
sel2 = []
|
for (key,val) in sel:
|
||||||
for (key,val) in sel:
|
val2 = translation_obj._get_source(cr, user,
|
||||||
val2 = translation_obj._get_source(cr, user,
|
self._name + ',' + f, 'selection',
|
||||||
self._name + ',' + f, 'selection',
|
context.get('lang', False) or 'en_US', val)
|
||||||
context['lang'], val)
|
sel2.append((key, val2 or val))
|
||||||
sel2.append((key, val2 or val))
|
sel = sel2
|
||||||
sel = sel2
|
|
||||||
res[f]['selection'] = sel
|
res[f]['selection'] = sel
|
||||||
else:
|
else:
|
||||||
# call the 'dynamic selection' function
|
# call the 'dynamic selection' function
|
||||||
|
@ -1705,12 +1701,20 @@ class orm(object):
|
||||||
args[i] += (table,)
|
args[i] += (table,)
|
||||||
i+=1
|
i+=1
|
||||||
else:
|
else:
|
||||||
if field.translate and context.get('lang', False) and context['lang'] != 'en_US':
|
if field.translate:
|
||||||
if args[i][1] in ('like', 'ilike'):
|
if args[i][1] in ('like', 'ilike'):
|
||||||
args[i] = (args[i][0], args[i][1], '%%%s%%' % args[i][2])
|
args[i] = (args[i][0], args[i][1], '%%%s%%' % args[i][2])
|
||||||
cr.execute('select res_id from ir_translation where name = %s and lang = %s and type = %s and value '+args[i][1]+' %s', (table._name+','+args[i][0], context['lang'], 'model', args[i][2]))
|
cr.execute('select res_id from ir_translation ' \
|
||||||
|
'where name = %s and lang = %s ' \
|
||||||
|
'and type = %s ' \
|
||||||
|
'and value ' + args[i][1] + ' %s',
|
||||||
|
(table._name+','+args[i][0],
|
||||||
|
context.get('lang', False) or 'en_US', 'model',
|
||||||
|
args[i][2]))
|
||||||
ids = map(lambda x: x[0], cr.fetchall())
|
ids = map(lambda x: x[0], cr.fetchall())
|
||||||
cr.execute('select id from "'+table._table+'" where "'+args[i][0]+'" '+args[i][1]+' %s', (args[i][2],))
|
cr.execute('select id from "' + table._table + '" ' \
|
||||||
|
'where "' + args[i][0]+'" '+args[i][1]+' %s',
|
||||||
|
(args[i][2],))
|
||||||
ids += map(lambda x: x[0], cr.fetchall())
|
ids += map(lambda x: x[0], cr.fetchall())
|
||||||
args[i] = ('id', 'in', ids, table)
|
args[i] = ('id', 'in', ids, table)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -38,6 +38,7 @@ import sys
|
||||||
|
|
||||||
import psycopg
|
import psycopg
|
||||||
from netsvc import Logger, LOG_ERROR
|
from netsvc import Logger, LOG_ERROR
|
||||||
|
from tools.misc import UpdateableDict
|
||||||
|
|
||||||
module_list = []
|
module_list = []
|
||||||
module_class_list = {}
|
module_class_list = {}
|
||||||
|
@ -262,34 +263,21 @@ class osv(orm.orm):
|
||||||
|
|
||||||
class Cacheable(object):
|
class Cacheable(object):
|
||||||
|
|
||||||
_cache = {}
|
_cache = UpdateableDict()
|
||||||
count = 0
|
|
||||||
|
|
||||||
def __delete_key(self, key):
|
|
||||||
odico = self._cache
|
|
||||||
for key_item in key[:-1]:
|
|
||||||
odico = odico[key_item]
|
|
||||||
del odico[key[-1]]
|
|
||||||
|
|
||||||
def __add_key(self, key, value):
|
|
||||||
odico = self._cache
|
|
||||||
for key_item in key[:-1]:
|
|
||||||
odico = odico.setdefault(key_item, {})
|
|
||||||
odico[key[-1]] = value
|
|
||||||
|
|
||||||
def add(self, key, value):
|
def add(self, key, value):
|
||||||
self.__add_key(key, value)
|
self._cache[key] = value
|
||||||
|
|
||||||
def invalidate(self, key):
|
def invalidate(self, key):
|
||||||
self.__delete_key(key)
|
del self._cache[key]
|
||||||
|
|
||||||
def get(self, key):
|
def get(self, key):
|
||||||
try:
|
try:
|
||||||
w = self._cache[key]
|
w = self._cache[key]
|
||||||
return w
|
return w
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def clear(self):
|
def clear(self):
|
||||||
self._cache.clear()
|
self._cache.clear()
|
||||||
self._items = []
|
self._items = []
|
||||||
|
|
|
@ -209,7 +209,7 @@ class rml_parse(object):
|
||||||
# translate the RML file
|
# translate the RML file
|
||||||
if 'lang' in self.localcontext:
|
if 'lang' in self.localcontext:
|
||||||
lang = self.localcontext['lang']
|
lang = self.localcontext['lang']
|
||||||
if lang not in (False, 'en_US') and text and not text.isspace():
|
if lang and text and not text.isspace():
|
||||||
transl_obj = self.pool.get('ir.translation')
|
transl_obj = self.pool.get('ir.translation')
|
||||||
piece_list = self._transl_regex.split(text)
|
piece_list = self._transl_regex.split(text)
|
||||||
for pn in range(len(piece_list)):
|
for pn in range(len(piece_list)):
|
||||||
|
|
Loading…
Reference in New Issue