4e33dbeb344d17848e779591f6d6a8fe348bcb0e
[odoo/odoo.git] / openerp / addons / base / module / wizard / base_language_install.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
6 #
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.
11 #
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.
16 #
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/>.
19 #
20 ##############################################################################
21
22 from openerp import tools
23 from openerp.osv import osv, fields
24 from openerp.tools.translate import _
25
26 class base_language_install(osv.osv_memory):
27     """ Install Language"""
28
29     _name = "base.language.install"
30     _description = "Install Language"
31     _columns = {
32         'lang': fields.selection(tools.scan_languages(),'Language', required=True),
33         'overwrite': fields.boolean('Overwrite Existing Terms', help="If you check this box, your customized translations will be overwritten and replaced by the official ones."),
34         'state':fields.selection([('init','init'),('done','done')], 'Status', readonly=True),
35     }
36     _defaults = {
37         'state': 'init',
38         'overwrite': False
39     }
40     def lang_install(self, cr, uid, ids, context=None):
41         if context is None:
42             context = {}
43         language_obj = self.browse(cr, uid, ids)[0]
44         lang = language_obj.lang
45         if lang:
46             modobj = self.pool.get('ir.module.module')
47             mids = modobj.search(cr, uid, [('state', '=', 'installed')])
48             if language_obj.overwrite:
49                 context = {'overwrite': True}
50             modobj.update_translations(cr, uid, mids, lang, context or {})
51             self.write(cr, uid, ids, {'state': 'done'}, context=context)
52         return {
53             'name': _('Language Pack'),
54             'view_type': 'form',
55             'view_mode': 'form',
56             'view_id': False,
57             'res_model': 'base.language.install',
58             'domain': [],
59             'context': dict(context, active_ids=ids),
60             'type': 'ir.actions.act_window',
61             'target': 'new',
62             'res_id': ids and ids[0] or False,
63         }
64
65 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: