1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Business Applications
5 # Copyright (c) 2004-2012 OpenERP S.A. <http://openerp.com>
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as
9 # published by the Free Software Foundation, either version 3 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ##############################################################################
26 from openerp import tools
27 from openerp.osv import fields,osv
28 from openerp.tools.translate import _
29 from openerp.tools.misc import get_iso_codes
31 NEW_LANG_KEY = '__new__'
33 class base_language_export(osv.osv_memory):
34 _name = "base.language.export"
36 def _get_languages(self, cr, uid, context):
37 lang_obj = self.pool.get('res.lang')
38 ids = lang_obj.search(cr, uid, [('translatable', '=', True)])
39 langs = lang_obj.browse(cr, uid, ids)
40 return [(NEW_LANG_KEY, _('New Language (Empty translation template)'))] + [(lang.code, lang.name) for lang in langs]
43 'name': fields.char('File Name', readonly=True),
44 'lang': fields.selection(_get_languages, 'Language', required=True),
45 'format': fields.selection([('csv','CSV File'),
47 ('tgz', 'TGZ Archive')], 'File Format', required=True),
48 'modules': fields.many2many('ir.module.module', 'rel_modules_langexport', 'wiz_id', 'module_id', 'Modules To Export', domain=[('state','=','installed')]),
49 'data': fields.binary('File', readonly=True),
50 'state': fields.selection([('choose', 'choose'), # choose language
51 ('get', 'get')]) # get the file
59 def act_getfile(self, cr, uid, ids, context=None):
60 this = self.browse(cr, uid, ids, context=context)[0]
61 lang = this.lang if this.lang != NEW_LANG_KEY else False
62 mods = sorted(map(lambda m: m.name, this.modules)) or ['all']
64 with contextlib.closing(cStringIO.StringIO()) as buf:
65 tools.trans_export(lang, mods, buf, this.format, cr)
66 out = base64.encodestring(buf.getvalue())
70 filename = get_iso_codes(lang)
73 name = "%s.%s" % (filename, this.format)
74 this.write({ 'state': 'get', 'data': out, 'name': name })
76 'type': 'ir.actions.act_window',
77 'res_model': 'base.language.export',
81 'views': [(False, 'form')],
86 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: