summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorP. Christeas <p_christ@hol.gr>2010-11-16 18:35:10 +0200
committerP. Christeas <p_christ@hol.gr>2010-11-16 18:35:10 +0200
commit89c40dec2f4933790c82c130e2a47bb46396937a (patch)
treedc24b35691d36cf2d18e68e14e83b20b29c2345d
parentcfdd34d511aeda2b8937a19aaeb4948c16d76665 (diff)
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
-rw-r--r--bin/tools/translate.py49
1 files changed, 35 insertions, 14 deletions
diff --git a/bin/tools/translate.py b/bin/tools/translate.py
index c75153cdde8..686f9677b43 100644
--- a/bin/tools/translate.py
+++ b/bin/tools/translate.py
@@ -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: