1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 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 ##############################################################################
24 from tempfile import TemporaryFile
25 from osv import osv, fields
27 class base_language_import(osv.osv_memory):
28 """ Language Import """
30 _name = "base.language.import"
31 _description = "Language Import"
32 _inherit = "ir.wizard.screen"
35 'name': fields.char('Language Name',size=64 , required=True),
36 'code': fields.char('Code (eg:en__US)',size=5 , required=True),
37 'data': fields.binary('File', required=True),
38 'overwrite': fields.boolean('Overwrite Existing Terms',
39 help="If you enable this option, existing translations (including custom ones) "
40 "will be overwritten and replaced by those in this file"),
43 def import_lang(self, cr, uid, ids, context=None):
46 @param cr: the current row, from the database cursor.
47 @param uid: the current user’s ID for security checks.
48 @param ids: the ID or list of IDs
49 @param context: A standard dictionary
53 import_data = self.browse(cr, uid, ids)[0]
54 if import_data.overwrite:
55 context.update(overwrite=True)
56 fileobj = TemporaryFile('w+')
57 fileobj.write(base64.decodestring(import_data.data))
59 # now we determine the file format
61 first_line = fileobj.readline().strip().replace('"', '').replace(' ', '')
62 fileformat = first_line.endswith("type,name,res_id,src,value") and 'csv' or 'po'
65 tools.trans_load_data(cr, fileobj, fileformat, import_data.code, lang_name=import_data.name, context=context)
69 base_language_import()
71 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: