[IMP] core: modernize tgz translations export
* don't use FS to do export * update translations export dialog to fix outdated links (launchpad & 6.1 translations doc) Note: can't use ``TarFile.gettarinfo`` to create the TarInfo object because it wants an actual file object with a ``name`` attribute and possibly even an fd. closes #22798
This commit is contained in:
@@ -24,13 +24,11 @@
|
||||
the rightmost column (value) contains the translations</li>
|
||||
<li>PO(T) format: you should edit it with a PO editor such as
|
||||
<a href="http://www.poedit.net/" target="_blank">POEdit</a>, or your preferred text editor</li>
|
||||
<li>TGZ format: this is a compressed archive containing a PO file, directly suitable
|
||||
for uploading to Odoo's translation platform,
|
||||
<a href="https://translations.launchpad.net/openobject-addons" target="_blank">Launchpad</a></li>
|
||||
<li>TGZ format: bundles multiple PO(T) files as a single archive</li>
|
||||
</ul>
|
||||
</p>
|
||||
<p>For more details about translating Odoo in your language, please refer to the
|
||||
<a href="http://doc.openerp.com/v6.1/contribute/07_improving_translations.html" target="_blank">documentation</a>.</p>
|
||||
<a href="https://github.com/odoo/odoo/wiki/Translations" target="_blank">documentation</a>.</p>
|
||||
</div>
|
||||
<footer states="choose">
|
||||
<button name="act_getfile" string="Export" type="object" class="btn-primary"/>
|
||||
|
||||
+17
-13
@@ -687,23 +687,27 @@ def trans_export(lang, modules, buffer, format, cr):
|
||||
writer.write(row['modules'], row['tnrs'], src, row['translation'], row['comments'])
|
||||
|
||||
elif format == 'tgz':
|
||||
rows_by_module = {}
|
||||
rows_by_module = defaultdict(list)
|
||||
for row in rows:
|
||||
module = row[0]
|
||||
rows_by_module.setdefault(module, []).append(row)
|
||||
tmpdir = tempfile.mkdtemp()
|
||||
for mod, modrows in rows_by_module.items():
|
||||
tmpmoddir = join(tmpdir, mod, 'i18n')
|
||||
os.makedirs(tmpmoddir)
|
||||
pofilename = (lang if lang else mod) + ".po" + ('t' if not lang else '')
|
||||
buf = open(join(tmpmoddir, pofilename), 'wb')
|
||||
_process('po', [mod], modrows, buf, lang)
|
||||
buf.close()
|
||||
rows_by_module[module].append(row)
|
||||
|
||||
tar = tarfile.open(fileobj=buffer, mode='w|gz')
|
||||
tar.add(tmpdir, '')
|
||||
tar.close()
|
||||
with tarfile.open(fileobj=buffer, mode='w|gz') as tar:
|
||||
for mod, modrows in rows_by_module.items():
|
||||
with io.BytesIO() as buf:
|
||||
_process('po', [mod], modrows, buf, lang)
|
||||
buf.seek(0)
|
||||
|
||||
info = tarfile.TarInfo(
|
||||
join(mod, 'i18n', '{basename}.{ext}'.format(
|
||||
basename=lang or mod,
|
||||
ext='po' if lang else 'pot',
|
||||
)))
|
||||
# addfile will read <size> bytes from the buffer so
|
||||
# size *must* be set first
|
||||
info.size = len(buf.getvalue())
|
||||
|
||||
tar.addfile(info, fileobj=buf)
|
||||
else:
|
||||
raise Exception(_('Unrecognized extension: must be one of '
|
||||
'.csv, .po, or .tgz (received .%s).') % format)
|
||||
|
||||
Reference in New Issue
Block a user