[IMP] base.export.language: improve/cleanup wizard model and its form view

bzr revid: odo@openerp.com-20120928120703-n87j8osun6bptehm
This commit is contained in:
Olivier Dony
2012-09-28 14:07:03 +02:00
parent 722bb4461d
commit f76f9d0001
2 changed files with 72 additions and 60 deletions
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
# OpenERP, Open Source Business Applications
# Copyright (c) 2004-2012 OpenERP S.A. <http://openerp.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
@@ -22,68 +22,68 @@
import tools
import base64
import cStringIO
import pooler
from osv import fields,osv
from tools.translate import _
from tools.misc import get_iso_codes
NEW_LANG_KEY = '__new__'
class base_language_export(osv.osv_memory):
_name = "base.language.export"
def _get_languages(self, cr, uid, context):
lang_obj=pooler.get_pool(cr.dbname).get('res.lang')
ids=lang_obj.search(cr, uid, ['&', ('active', '=', True), ('translatable', '=', True),])
langs=lang_obj.browse(cr, uid, ids)
return [(lang.code, lang.name) for lang in langs]
def act_cancel(self, cr, uid, ids, context=None):
#self.unlink(cr, uid, ids, context)
return {'type':'ir.actions.act_window_close' }
def act_destroy(self, *args):
return {'type':'ir.actions.act_window_close' }
lang_obj = self.pool.get('res.lang')
ids = lang_obj.search(cr, uid, [('translatable', '=', True)])
langs = lang_obj.browse(cr, uid, ids)
return [(NEW_LANG_KEY, _('New Language (Empty translation template)'))] + [(lang.code, lang.name) for lang in langs]
_columns = {
'name': fields.char('File Name', readonly=True),
'lang': fields.selection(_get_languages, 'Language', required=True),
'format': fields.selection([('csv','CSV File'),
('po','PO File'),
('tgz', 'TGZ Archive')], 'File Format', required=True),
'modules': fields.many2many('ir.module.module', 'rel_modules_langexport', 'wiz_id', 'module_id', 'Modules To Export', domain=[('state','=','installed')]),
'data': fields.binary('File', readonly=True),
'advice': fields.text('Note', readonly=True),
'state': fields.selection([('choose', 'choose'), # choose language
('get', 'get')]) # get the file
}
_defaults = {
'state': 'choose',
'name': 'lang.tar.gz',
'lang': NEW_LANG_KEY,
'format': 'csv',
}
def act_getfile(self, cr, uid, ids, context=None):
this = self.browse(cr, uid, ids)[0]
lang = this.lang if this.lang != NEW_LANG_KEY else False
mods = map(lambda m: m.name, this.modules) or ['all']
mods.sort()
buf=cStringIO.StringIO()
buf = cStringIO.StringIO()
tools.trans_export(this.lang, mods, buf, this.format, cr)
if this.format == 'csv':
this.advice = _("Save this document to a .CSV file and open it with your favourite spreadsheet software. The file encoding is UTF-8. You have to translate the latest column before reimporting it.")
this.advice = _("Save this document as a .CSV file and open it with your favourite spreadsheet software. The file encoding is UTF-8. You have to translate the last column before reimporting it.")
elif this.format == 'po':
if not this.lang:
if not lang:
this.format = 'pot'
this.advice = _("Save this document to a %s file and edit it with a specific software or a text editor. The file encoding is UTF-8.") % ('.'+this.format,)
this.advice = _("Save this document as a %s file and edit it with a PO editor or a text editor. The file encoding is UTF-8.") % ('.'+this.format,)
elif this.format == 'tgz':
ext = this.lang and '.po' or '.pot'
this.advice = _('Save this document to a .tgz file. This archive containt UTF-8 %s files and may be uploaded to launchpad.') % (ext,)
this.advice = _('Save this document as a .tgz file. This archive contains UTF-8 %s files and may be uploaded to launchpad.')
filename = _('new')
if not this.lang and len(mods) == 1:
filename = mods[0]
if this.lang:
if lang:
filename = get_iso_codes(this.lang)
elif len(mods) == 1:
filename = mods[0]
this.name = "%s.%s" % (filename, this.format)
out=base64.encodestring(buf.getvalue())
out = base64.encodestring(buf.getvalue())
buf.close()
return self.write(cr, uid, ids, {'state':'get', 'data':out, 'advice':this.advice, 'name':this.name}, context=context)
self.write(cr, uid, ids, {'state': 'get',
'data': out,
'advice': this.advice,
'name':this.name}, context=context)
return True
_name = "base.language.export"
_inherit = "ir.wizard.screen"
_columns = {
'name': fields.char('File Name', 16, readonly=True),
'lang': fields.selection(_get_languages, 'Language', help='To export a new language, do not select a language.'), # not required: unset = new language
'format': fields.selection( ( ('csv','CSV File'), ('po','PO File'), ('tgz', 'TGZ Archive')), 'File Format', required=True),
'modules': fields.many2many('ir.module.module', 'rel_modules_langexport', 'wiz_id', 'module_id', 'Modules', domain=[('state','=','installed')]),
'data': fields.binary('File', readonly=True),
'advice': fields.text('Advice', readonly=True),
'state': fields.selection( ( ('choose','choose'), # choose language
('get','get'), # get the file
) ),
}
_defaults = {
'state': lambda *a: 'choose',
'name': lambda *a: 'lang.tar.gz'
}
base_language_export()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
@@ -1,31 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="wizard_lang_export" model="ir.ui.view">
<field name="name">Export Translations</field>
<field name="name">Translations Export</field>
<field name="model">base.language.export</field>
<field name="arch" type="xml">
<form string="Export Translations" version="7.0">
<group colspan="4" states="choose">
<separator colspan="4" string="Export Translation"/>
<form string="Translations Export" version="7.0">
<field invisible="1" name="state"/>
<field name="name" invisible="1"/>
<group states="choose" string="Export Settings">
<field name="lang"/>
<field name="format" required="1"/>
<field name="modules" nolabel="1"/>
<field invisible="1" name="state"/>
</group>
<group colspan="4" states="get">
<separator string="Export done" colspan="4"/>
<field name="name" invisible="1" colspan="4"/>
<field name="data" nolabel="1" readonly="1" filename="name" colspan="4"/>
<field height="80" name="advice" nolabel="1" colspan="4"/>
<field name="format"/>
<field name="modules"/>
</group>
<div states="get">
<h2>Export Complete</h2>
<p>Here is the exported translation file: <field name="data" readonly="1" filename="name"/></p>
<p>This file was generated using the universal <strong>Unicode/UTF-8</strong> file encoding, please be sure to view and edit
using the same encoding.</p>
<p>The next step depends on the file format:
<ul>
<li>CSV format: you may edit it directly with your favorite spreadsheet software,
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 OpenERP's translation platform,
<a href="https://translations.launchpad.net/openobject-addons" target="_blank">Launchpad</a></li>
</ul>
</p>
<p>For more details about translating OpenERP 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>
</div>
<footer states="choose">
<button name="act_getfile" string="_Export" type="object" class="oe_highlight"/> or
<button name="act_cancel" special="cancel" string="_Cancel" type="object" class="oe_link"/>
<button name="act_getfile" string="Export" type="object" class="oe_highlight"/> or
<button special="cancel" string="Cancel" type="object" class="oe_link"/>
</footer>
<footer states="get">
<button name="act_cancel" special="cancel" string="_Close" type="object"/>
<button special="cancel" string="Close" type="object"/>
</footer>
</form>
</field>