1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
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 ##############################################################################
22 from osv import osv, fields
26 from tools.translate import _
28 class base_update_translations(osv.osv_memory):
29 def _get_languages(self, cr, uid, context):
30 lang_obj=pooler.get_pool(cr.dbname).get('res.lang')
31 ids=lang_obj.search(cr, uid, ['&', ('active', '=', True), ('translatable', '=', True),])
32 langs=lang_obj.browse(cr, uid, ids)
33 return [(lang.code, lang.name) for lang in langs]
35 def _get_lang_name(self, cr, uid, lang_code):
36 lang_obj=pooler.get_pool(cr.dbname).get('res.lang')
37 ids=lang_obj.search(cr, uid, [('code', '=', lang_code)])
39 raise osv.except_osv(_('Error!'), _('No language with code "%s" exists') % lang_code)
40 lang = lang_obj.browse(cr, uid, ids[0])
42 def act_cancel(self, cr, uid, ids, context=None):
43 return {'type': 'ir.actions.act_window_close'}
45 def act_update(self, cr, uid, ids, context=None):
46 this = self.browse(cr, uid, ids)[0]
47 lang_name = self._get_lang_name(cr, uid, this.lang)
48 buf=cStringIO.StringIO()
49 tools.trans_export(this.lang, ['all'], buf, 'csv', cr)
50 tools.trans_load_data(cr, buf, 'csv', this.lang, lang_name=lang_name)
52 return {'type': 'ir.actions.act_window_close'}
54 def default_get(self, cr, uid, fields, context=None):
57 res = super(base_update_translations, self).default_get(cr, uid, fields, context=context)
59 if context.get('active_model') != "res.lang":
62 record_id = context.get('active_id', False) or False
64 lang = self.pool.get('res.lang').browse(cr, uid, record_id).code
68 _name = 'base.update.translations'
69 _inherit = "ir.wizard.screen"
71 'lang': fields.selection(_get_languages, 'Language', required=True),
74 base_update_translations()
76 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: