[FIX] tools: export translations of models.py

When exporting the translations, the terms stored in individual files outside of
addons folders (e.g. openerp/models.py) needs to be scanned as well and added in
base translations.
Some folders like osv and report were enough to add these files but with the new
api moving the ORM to openerp folder, a non-recusrive scan needs to be added.

Fixes #7482
This commit is contained in:
Martin Trigaux 2015-07-09 11:27:04 +02:00
parent 4792156e1f
commit 8ac392873b
1 changed files with 12 additions and 6 deletions

View File

@ -843,16 +843,19 @@ def trans_generate(lang, modules, cr):
lambda m: m['name'],
registry['ir.module.module'].search_read(cr, uid, [('state', '=', 'installed')], fields=['name']))
path_list = list(openerp.modules.module.ad_paths)
path_list = [(path, True) for path in openerp.modules.module.ad_paths]
# Also scan these non-addon paths
for bin_path in ['osv', 'report' ]:
path_list.append(os.path.join(config.config['root_path'], bin_path))
for bin_path in ['osv', 'report', 'modules', 'service', 'tools']:
path_list.append((os.path.join(config.config['root_path'], bin_path), True))
# non-recursive scan for individual files in root directory but without
# scanning subdirectories that may contain addons
path_list.append((config.config['root_path'], False))
_logger.debug("Scanning modules at paths: %s", path_list)
def get_module_from_path(path):
for mp in path_list:
if path.startswith(mp) and os.path.dirname(path) != mp:
for (mp, rec) in path_list:
if rec and path.startswith(mp) and os.path.dirname(path) != mp:
path = path[len(mp)+1:]
return path.split(os.path.sep)[0]
return 'base' # files that are not in a module are considered as being in 'base' module
@ -887,7 +890,7 @@ def trans_generate(lang, modules, cr):
finally:
src_file.close()
for path in path_list:
for (path, recursive) in path_list:
_logger.debug("Scanning files of modules at %s", path)
for root, dummy, files in osutil.walksymlinks(path):
for fname in fnmatch.filter(files, '*.py'):
@ -906,6 +909,9 @@ def trans_generate(lang, modules, cr):
for fname in fnmatch.filter(files, '*.xml'):
babel_extract_terms(fname, path, root, 'openerp.tools.translate:babel_extract_qweb',
extra_comments=[WEB_TRANSLATION_COMMENT])
if not recursive:
# due to topdown, first iteration is in first level
break
out = []
# translate strings marked as to be translated