[IMP] translations: support generic "report" translation type + export from *.mako files + multiple types for _get_source() + lint cleanup
bzr revid: odo@openerp.com-20101008140349-9hclfqwjmndkrtn4
This commit is contained in:
parent
560ccd262a
commit
2171202b32
|
@ -25,7 +25,8 @@ import tools
|
||||||
TRANSLATION_TYPE = [
|
TRANSLATION_TYPE = [
|
||||||
('field', 'Field'),
|
('field', 'Field'),
|
||||||
('model', 'Object'),
|
('model', 'Object'),
|
||||||
('rml', 'RML'),
|
('rml', 'RML (deprecated - use Report)'), # Pending deprecation - to be replaced by report!
|
||||||
|
('report', 'Report/Template'),
|
||||||
('selection', 'Selection'),
|
('selection', 'Selection'),
|
||||||
('view', 'View'),
|
('view', 'View'),
|
||||||
('wizard_button', 'Wizard Button'),
|
('wizard_button', 'Wizard Button'),
|
||||||
|
@ -131,14 +132,14 @@ class ir_translation(osv.osv):
|
||||||
return len(ids)
|
return len(ids)
|
||||||
|
|
||||||
@tools.cache(skiparg=3)
|
@tools.cache(skiparg=3)
|
||||||
def _get_source(self, cr, uid, name, tt, lang, source=None):
|
def _get_source(self, cr, uid, name, types, lang, source=None):
|
||||||
"""
|
"""
|
||||||
Returns the translation for the given combination of name, type, language
|
Returns the translation for the given combination of name, type, language
|
||||||
and source. All values passed to this method should be unicode (not byte strings),
|
and source. All values passed to this method should be unicode (not byte strings),
|
||||||
especially ``source``.
|
especially ``source``.
|
||||||
|
|
||||||
:param name: identification of the term to translate, such as field name
|
:param name: identification of the term to translate, such as field name
|
||||||
:param type: type of term to translate (see ``type`` field on ir.translation)
|
:param types: single string defining type of term to translate (see ``type`` field on ir.translation), or sequence of allowed types (strings)
|
||||||
:param lang: language code of the desired translation
|
:param lang: language code of the desired translation
|
||||||
:param source: optional source term to translate (should be unicode)
|
:param source: optional source term to translate (should be unicode)
|
||||||
:rtype: unicode
|
:rtype: unicode
|
||||||
|
@ -147,24 +148,25 @@ class ir_translation(osv.osv):
|
||||||
"""
|
"""
|
||||||
# FIXME: should assert that `source` is unicode and fix all callers to always pass unicode
|
# FIXME: should assert that `source` is unicode and fix all callers to always pass unicode
|
||||||
# so we can remove the string encoding/decoding.
|
# so we can remove the string encoding/decoding.
|
||||||
|
|
||||||
if not lang:
|
if not lang:
|
||||||
return u''
|
return u''
|
||||||
|
if isinstance(types, basestring):
|
||||||
|
types = (types,)
|
||||||
if source:
|
if source:
|
||||||
cr.execute('select value ' \
|
cr.execute('select value ' \
|
||||||
'from ir_translation ' \
|
'from ir_translation ' \
|
||||||
'where lang=%s ' \
|
'where lang=%s ' \
|
||||||
'and type=%s ' \
|
'and type in %s ' \
|
||||||
'and name=%s ' \
|
'and name=%s ' \
|
||||||
'and src=%s',
|
'and src=%s',
|
||||||
(lang or '', tt, tools.ustr(name), source))
|
(lang or '', types, tools.ustr(name), source))
|
||||||
else:
|
else:
|
||||||
cr.execute('select value ' \
|
cr.execute('select value ' \
|
||||||
'from ir_translation ' \
|
'from ir_translation ' \
|
||||||
'where lang=%s ' \
|
'where lang=%s ' \
|
||||||
'and type=%s ' \
|
'and type in %s ' \
|
||||||
'and name=%s',
|
'and name=%s',
|
||||||
(lang or '', tt, tools.ustr(name)))
|
(lang or '', types, tools.ustr(name)))
|
||||||
res = cr.fetchone()
|
res = cr.fetchone()
|
||||||
trad = res and res[0] or u''
|
trad = res and res[0] or u''
|
||||||
if source and not trad:
|
if source and not trad:
|
||||||
|
|
|
@ -23,6 +23,7 @@ import codecs
|
||||||
import csv
|
import csv
|
||||||
import fnmatch
|
import fnmatch
|
||||||
import inspect
|
import inspect
|
||||||
|
import itertools
|
||||||
import locale
|
import locale
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
@ -34,8 +35,7 @@ import logging
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
|
|
||||||
import osv, tools, pooler
|
import tools, pooler
|
||||||
import ir
|
|
||||||
import netsvc
|
import netsvc
|
||||||
from tools.misc import UpdateableStr
|
from tools.misc import UpdateableStr
|
||||||
|
|
||||||
|
@ -472,7 +472,6 @@ def trans_generate(lang, modules, dbname=None):
|
||||||
|
|
||||||
query = 'SELECT name, model, res_id, module' \
|
query = 'SELECT name, model, res_id, module' \
|
||||||
' FROM ir_model_data'
|
' FROM ir_model_data'
|
||||||
query_param = None
|
|
||||||
if 'all_installed' in modules:
|
if 'all_installed' in modules:
|
||||||
query += ' WHERE module IN ( SELECT name FROM ir_module_module WHERE state = \'installed\') '
|
query += ' WHERE module IN ( SELECT name FROM ir_module_module WHERE state = \'installed\') '
|
||||||
query_param = None
|
query_param = None
|
||||||
|
@ -589,7 +588,7 @@ def trans_generate(lang, modules, dbname=None):
|
||||||
push_translation(module, 'model', name, 0, encode(obj_value[field_name]))
|
push_translation(module, 'model', name, 0, encode(obj_value[field_name]))
|
||||||
|
|
||||||
if hasattr(field_def, 'selection') and isinstance(field_def.selection, (list, tuple)):
|
if hasattr(field_def, 'selection') and isinstance(field_def.selection, (list, tuple)):
|
||||||
for key, val in field_def.selection:
|
for dummy, val in field_def.selection:
|
||||||
push_translation(module, 'selection', name, 0, encode(val))
|
push_translation(module, 'selection', name, 0, encode(val))
|
||||||
|
|
||||||
elif model=='ir.actions.report.xml':
|
elif model=='ir.actions.report.xml':
|
||||||
|
@ -598,19 +597,18 @@ def trans_generate(lang, modules, dbname=None):
|
||||||
if obj.report_rml:
|
if obj.report_rml:
|
||||||
fname = obj.report_rml
|
fname = obj.report_rml
|
||||||
parse_func = trans_parse_rml
|
parse_func = trans_parse_rml
|
||||||
report_type = "rml"
|
report_type = "report"
|
||||||
elif obj.report_xsl:
|
elif obj.report_xsl:
|
||||||
fname = obj.report_xsl
|
fname = obj.report_xsl
|
||||||
parse_func = trans_parse_xsl
|
parse_func = trans_parse_xsl
|
||||||
report_type = "xsl"
|
report_type = "xsl"
|
||||||
try:
|
if fname and obj.report_type in ('pdf', 'xsl'):
|
||||||
xmlstr = tools.file_open(fname).read()
|
try:
|
||||||
d = etree.XML(xmlstr)
|
d = etree.parse(tools.file_open(fname))
|
||||||
for t in parse_func(d):
|
for t in parse_func(d):
|
||||||
push_translation(module, report_type, name, 0, t)
|
push_translation(module, report_type, name, 0, t)
|
||||||
except IOError, etree.XMLSyntaxError:
|
except (IOError, etree.XMLSyntaxError):
|
||||||
if fname:
|
logging.getLogger("i18n").exception("couldn't export translation for report %s %s %s", name, report_type, fname)
|
||||||
logger.notifyChannel("i18n", netsvc.LOG_ERROR, "couldn't export translation for report %s %s %s" % (name, report_type, fname))
|
|
||||||
|
|
||||||
for constraint in pool.get(model)._constraints:
|
for constraint in pool.get(model)._constraints:
|
||||||
msg = constraint[1]
|
msg = constraint[1]
|
||||||
|
@ -666,22 +664,25 @@ def trans_generate(lang, modules, dbname=None):
|
||||||
else :
|
else :
|
||||||
path_list = [root_path,tools.config['addons_path']]
|
path_list = [root_path,tools.config['addons_path']]
|
||||||
|
|
||||||
for path in path_list:
|
def export_code_terms_from_file(fname, path, root, terms_type):
|
||||||
for root, dirs, files in tools.osutil.walksymlinks(path):
|
fabsolutepath = join(root, fname)
|
||||||
for fname in fnmatch.filter(files, '*.py'):
|
frelativepath = fabsolutepath[len(path):]
|
||||||
fabsolutepath = join(root, fname)
|
module = get_module_from_path(frelativepath)
|
||||||
frelativepath = fabsolutepath[len(path):]
|
is_mod_installed = module in installed_modules
|
||||||
module = get_module_from_path(frelativepath)
|
if (('all' in modules) or (module in modules)) and is_mod_installed:
|
||||||
is_mod_installed = module in installed_modules
|
code_string = tools.file_open(fabsolutepath, subdir='').read()
|
||||||
if (('all' in modules) or (module in modules)) and is_mod_installed:
|
iter = re.finditer('[^a-zA-Z0-9_]_\([\s]*["\'](.+?)["\'][\s]*\)', code_string, re.S)
|
||||||
code_string = tools.file_open(fabsolutepath, subdir='').read()
|
if module in installed_modules:
|
||||||
iter = re.finditer('[^a-zA-Z0-9_]_\([\s]*["\'](.+?)["\'][\s]*\)',
|
frelativepath = str("addons" + frelativepath)
|
||||||
code_string, re.S)
|
for i in iter:
|
||||||
|
push_translation(module, terms_type, frelativepath, 0, encode(i.group(1)))
|
||||||
|
|
||||||
if module in installed_modules :
|
for path in path_list:
|
||||||
frelativepath =str("addons"+frelativepath)
|
for root, dummy, files in tools.osutil.walksymlinks(path):
|
||||||
for i in iter:
|
for fname in itertools.chain(fnmatch.filter(files, '*.py')):
|
||||||
push_translation(module, 'code', frelativepath, 0, encode(i.group(1)))
|
export_code_terms_from_file(fname, path, root, 'code')
|
||||||
|
for fname in itertools.chain(fnmatch.filter(files, '*.mako')):
|
||||||
|
export_code_terms_from_file(fname, path, root, 'report')
|
||||||
|
|
||||||
|
|
||||||
out = [["module","type","name","res_id","src","value"]] # header
|
out = [["module","type","name","res_id","src","value"]] # header
|
||||||
|
|
Loading…
Reference in New Issue