translate: fix scanning the ir.models for translations
The loop would only consider models that have >0 records registered in
ir.model.data.
This is merge of commits 3988ebf4dc130, 070e7d6ac717de and adapt to trunk.
bzr revid: p_christ@hol.gr-20101116163510-yemzlcy0f0yk893l
This commit is contained in:
+35
-14
@@ -499,13 +499,21 @@ def trans_generate(lang, modules, dbname=None):
|
||||
|
||||
query = 'SELECT name, model, res_id, module' \
|
||||
' FROM ir_model_data'
|
||||
|
||||
query_models = """SELECT m.id, m.model, imd.module
|
||||
FROM ir_model AS m, ir_model_data AS imd
|
||||
WHERE m.id = imd.res_id AND imd.model = 'ir.model' """
|
||||
|
||||
if 'all_installed' in modules:
|
||||
query += ' WHERE module IN ( SELECT name FROM ir_module_module WHERE state = \'installed\') '
|
||||
query_models += " AND imd.module in ( SELECT name FROM ir_module_module WHERE state = 'installed') "
|
||||
query_param = None
|
||||
if 'all' not in modules:
|
||||
query += ' WHERE module IN %s'
|
||||
query_models += ' AND imd.module in %s'
|
||||
query_param = (tuple(modules),)
|
||||
query += ' ORDER BY module, model, name'
|
||||
query_models += ' ORDER BY module, model'
|
||||
|
||||
cr.execute(query, query_param)
|
||||
|
||||
@@ -637,20 +645,7 @@ def trans_generate(lang, modules, dbname=None):
|
||||
except (IOError, etree.XMLSyntaxError):
|
||||
logging.getLogger("i18n").exception("couldn't export translation for report %s %s %s", name, report_type, fname)
|
||||
|
||||
model_obj = pool.get(model)
|
||||
def push_constraint_msg(module, term_type, model, msg):
|
||||
# Check presence of __call__ directly instead of using
|
||||
# callable() because it will be deprecated as of Python 3.0
|
||||
if not hasattr(msg, '__call__'):
|
||||
push_translation(module, term_type, model, 0, encode(msg))
|
||||
|
||||
for constraint in model_obj._constraints:
|
||||
push_constraint_msg(module, 'constraint', model, constraint[1])
|
||||
|
||||
for constraint in model_obj._sql_constraints:
|
||||
push_constraint_msg(module, 'sql_constraint', model, constraint[2])
|
||||
|
||||
for field_name,field_def in model_obj._columns.items():
|
||||
for field_name,field_def in obj._table._columns.items():
|
||||
if field_def.translate:
|
||||
name = model + "," + field_name
|
||||
try:
|
||||
@@ -659,6 +654,32 @@ def trans_generate(lang, modules, dbname=None):
|
||||
trad = ''
|
||||
push_translation(module, 'model', name, xml_name, encode(trad))
|
||||
|
||||
# End of data for ir.model.data query results
|
||||
|
||||
cr.execute(query_models, query_param)
|
||||
|
||||
def push_constraint_msg(module, term_type, model, msg):
|
||||
# Check presence of __call__ directly instead of using
|
||||
# callable() because it will be deprecated as of Python 3.0
|
||||
if not hasattr(msg, '__call__'):
|
||||
push_translation(module, term_type, model, 0, encode(msg))
|
||||
|
||||
for (model_id, model, module) in cr.fetchall():
|
||||
module = encode(module)
|
||||
model = encode(model)
|
||||
|
||||
model_obj = pool.get(model)
|
||||
|
||||
if not model_obj:
|
||||
logging.getLogger("i18n").error("Unable to find object %r", model)
|
||||
continue
|
||||
|
||||
for constraint in getattr(model_obj, '_constraints', []):
|
||||
push_constraint_msg(module, 'constraint', model, constraint[1])
|
||||
|
||||
for constraint in getattr(model_obj, '_sql_constraints', []):
|
||||
push_constraint_msg(module, 'sql_constraint', model, constraint[2])
|
||||
|
||||
# parse source code for _() calls
|
||||
def get_module_from_path(path, mod_paths=None):
|
||||
if not mod_paths:
|
||||
|
||||
Reference in New Issue
Block a user