Translation import should accept a list of file names
This will prevent deleting valid translations when a module defines multiple translation files for the same language. issue5733 review32321002
This commit is contained in:
1 parent
7a1bbd6cd4
commit
5353de2e1e
2 files changed
+53
-46
No files matched your search
+45
-43
@@ -776,6 +776,8 @@ class Translation(ModelSQL, ModelView):
|
||||
def translation_import(cls, lang, module, po_path):
|
||||
pool = Pool()
|
||||
ModelData = pool.get('ir.model.data')
|
||||
if isinstance(po_path, basestring):
|
||||
filenames = [po_path]
|
||||
models_data = ModelData.search([
|
||||
('module', '=', module),
|
||||
])
|
||||
@@ -791,7 +793,6 @@ class Translation(ModelSQL, ModelView):
|
||||
|
||||
translations = set()
|
||||
to_save = []
|
||||
pofile = polib.pofile(po_path)
|
||||
|
||||
id2translation = {}
|
||||
key2ids = {}
|
||||
@@ -850,54 +851,55 @@ class Translation(ModelSQL, ModelView):
|
||||
'record')):
|
||||
id2translation = dict((t.id, t)
|
||||
for t in cls.browse(translation_ids))
|
||||
for entry in pofile:
|
||||
if entry.obsolete:
|
||||
continue
|
||||
translation, res_id = cls.from_poentry(entry)
|
||||
translation.lang = lang
|
||||
translation.module = module
|
||||
noupdate = False
|
||||
for pofile in po_path:
|
||||
for entry in polib.pofile(pofile):
|
||||
if entry.obsolete:
|
||||
continue
|
||||
translation, res_id = cls.from_poentry(entry)
|
||||
translation.lang = lang
|
||||
translation.module = module
|
||||
noupdate = False
|
||||
|
||||
if '.' in res_id:
|
||||
to_save.append(override_translation(res_id,
|
||||
translation))
|
||||
continue
|
||||
if '.' in res_id:
|
||||
to_save.append(override_translation(res_id,
|
||||
translation))
|
||||
continue
|
||||
|
||||
model = translation.name.split(',')[0]
|
||||
if (model in fs_id2prop
|
||||
and res_id in fs_id2prop[model]):
|
||||
res_id, noupdate = fs_id2prop[model][res_id]
|
||||
model = translation.name.split(',')[0]
|
||||
if (model in fs_id2prop
|
||||
and res_id in fs_id2prop[model]):
|
||||
res_id, noupdate = fs_id2prop[model][res_id]
|
||||
|
||||
if res_id:
|
||||
try:
|
||||
res_id = int(res_id)
|
||||
except ValueError:
|
||||
res_id = None
|
||||
if not res_id:
|
||||
res_id = -1
|
||||
if res_id:
|
||||
try:
|
||||
res_id = int(res_id)
|
||||
except ValueError:
|
||||
res_id = None
|
||||
if not res_id:
|
||||
res_id = -1
|
||||
|
||||
translation.res_id = res_id
|
||||
key = translation.unique_key
|
||||
if not key:
|
||||
raise ValueError('Unknow translation type: %s' %
|
||||
translation.type)
|
||||
ids = key2ids.get(key, [])
|
||||
translation.res_id = res_id
|
||||
key = translation.unique_key
|
||||
if not key:
|
||||
raise ValueError('Unknow translation type: %s' %
|
||||
translation.type)
|
||||
ids = key2ids.get(key, [])
|
||||
|
||||
if not processing:
|
||||
translation_ids.extend(ids)
|
||||
continue
|
||||
if not processing:
|
||||
translation_ids.extend(ids)
|
||||
continue
|
||||
|
||||
if not ids:
|
||||
to_save.append(translation)
|
||||
else:
|
||||
for translation_id in ids:
|
||||
old_translation = id2translation[translation_id]
|
||||
if not noupdate:
|
||||
old_translation.value = translation.value
|
||||
old_translation.fuzzy = translation.fuzzy
|
||||
to_save.append(old_translation)
|
||||
else:
|
||||
translations.add(old_translation)
|
||||
if not ids:
|
||||
to_save.append(translation)
|
||||
else:
|
||||
for translation_id in ids:
|
||||
old_translation = id2translation[translation_id]
|
||||
if not noupdate:
|
||||
old_translation.value = translation.value
|
||||
old_translation.fuzzy = translation.fuzzy
|
||||
to_save.append(old_translation)
|
||||
else:
|
||||
translations.add(old_translation)
|
||||
cls.save(filter(None, to_save))
|
||||
translations |= set(to_save)
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import imp
|
||||
import operator
|
||||
import ConfigParser
|
||||
from glob import iglob
|
||||
from collections import defaultdict
|
||||
|
||||
from sql import Table
|
||||
from sql.functions import CurrentTimestamp
|
||||
@@ -253,6 +254,7 @@ def load_module_graph(graph, pool, update=None, lang=None):
|
||||
modules_todo.append((module, list(tryton_parser.to_delete)))
|
||||
|
||||
localedir = '%s/%s' % (package.info['directory'], 'locale')
|
||||
lang2filenames = defaultdict(list)
|
||||
for filename in itertools.chain(
|
||||
iglob('%s/*.po' % localedir),
|
||||
iglob('%s/override/*.po' % localedir)):
|
||||
@@ -260,10 +262,13 @@ def load_module_graph(graph, pool, update=None, lang=None):
|
||||
lang2 = os.path.splitext(os.path.basename(filename))[0]
|
||||
if lang2 not in lang:
|
||||
continue
|
||||
logger.info('%s:loading %s', module,
|
||||
filename[len(package.info['directory']) + 1:])
|
||||
lang2filenames[lang2].append(filename)
|
||||
base_path_position = len(package.info['directory']) + 1
|
||||
for language, files in lang2filenames.iteritems():
|
||||
filenames = [f[base_path_position:] for f in files]
|
||||
logger.info('%s:loading %s', module, ','.join(filenames))
|
||||
Translation = pool.get('ir.translation')
|
||||
Translation.translation_import(lang2, module, filename)
|
||||
Translation.translation_import(language, module, files)
|
||||
|
||||
if package_state == 'to remove':
|
||||
continue
|
||||
|
||||
Reference in new issue
Block a user