2008-07-23 15:01:27 +00:00
# -*- encoding: utf-8 -*-
2006-12-07 13:41:40 +00:00
##############################################################################
2009-10-14 12:32:15 +00:00
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
2008-06-16 11:00:21 +00:00
#
2008-11-03 18:27:16 +00:00
# This program is free software: you can redistribute it and/or modify
2009-10-14 12:32:15 +00:00
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
2006-12-07 13:41:40 +00:00
#
2008-11-03 18:27:16 +00:00
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2009-10-14 12:32:15 +00:00
# GNU Affero General Public License for more details.
2006-12-07 13:41:40 +00:00
#
2009-10-14 12:32:15 +00:00
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
2006-12-07 13:41:40 +00:00
#
##############################################################################
import wizard
import tools
import base64
2009-01-05 21:02:40 +00:00
import cStringIO
2006-12-07 13:41:40 +00:00
import csv
import pooler
2008-07-09 11:38:36 +00:00
from osv import fields , osv
2009-03-06 15:14:02 +00:00
from tools . translate import _
2008-07-09 11:38:36 +00:00
class wizard_export_lang ( osv . osv_memory ) :
2008-07-22 14:24:36 +00:00
def _get_languages ( self , cr , uid , context ) :
lang_obj = pooler . get_pool ( cr . dbname ) . get ( ' res.lang ' )
2008-08-19 13:10:16 +00:00
ids = lang_obj . search ( cr , uid , [ ' & ' , ( ' active ' , ' = ' , True ) , ( ' translatable ' , ' = ' , True ) , ] )
2008-07-22 14:24:36 +00:00
langs = lang_obj . browse ( cr , uid , ids )
2008-09-02 11:49:22 +00:00
return [ ( lang . code , lang . name ) for lang in langs ]
2008-07-22 14:24:36 +00:00
2008-07-09 11:38:36 +00:00
2008-07-22 14:24:36 +00:00
def act_cancel ( self , cr , uid , ids , context = None ) :
#self.unlink(cr, uid, ids, context)
return { ' type ' : ' ir.actions.act_window_close ' }
2008-07-09 11:38:36 +00:00
2008-07-22 14:24:36 +00:00
def act_destroy ( self , * args ) :
return { ' type ' : ' ir.actions.act_window_close ' }
2008-07-09 11:38:36 +00:00
2008-07-22 14:24:36 +00:00
def act_getfile ( self , cr , uid , ids , context = None ) :
this = self . browse ( cr , uid , ids ) [ 0 ]
2008-09-02 11:49:22 +00:00
mods = map ( lambda m : m . name , this . modules ) or [ ' all ' ]
2008-07-22 14:24:36 +00:00
mods . sort ( )
2009-01-05 21:02:40 +00:00
buf = cStringIO . StringIO ( )
2008-07-22 14:24:36 +00:00
tools . trans_export ( this . lang , mods , buf , this . format , dbname = cr . dbname )
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. " )
elif this . format == ' po ' :
2008-09-02 11:49:22 +00:00
if not this . 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 , )
2008-08-19 13:10:16 +00:00
elif this . format == ' tgz ' :
ext = this . lang and ' .po ' or ' .pot '
2008-09-02 11:49:22 +00:00
this . advice = _ ( ' Save this document to a .tgz file. This archive containt UTF-8 %s files and may be uploaded to launchpad. ' ) % ( ext , )
2009-03-06 15:14:02 +00:00
filename = _ ( ' new ' )
if not this . lang and len ( mods ) == 1 :
filename = mods [ 0 ]
this . name = " %s . %s " % ( this . lang or filename , this . format )
2008-12-16 16:21:12 +00:00
out = base64 . encodestring ( buf . getvalue ( ) )
2008-07-22 14:24:36 +00:00
buf . close ( )
2008-09-02 11:49:22 +00:00
return self . write ( cr , uid , ids , { ' state ' : ' get ' , ' data ' : out , ' advice ' : this . advice , ' name ' : this . name } , context = context )
2008-07-09 11:38:36 +00:00
2008-07-22 14:24:36 +00:00
_name = " wizard.module.lang.export "
_columns = {
2008-09-02 11:49:22 +00:00
' name ' : fields . char ( ' Filename ' , 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
2008-08-19 13:10:16 +00:00
' format ' : fields . selection ( ( ( ' csv ' , ' CSV File ' ) , ( ' po ' , ' PO File ' ) , ( ' tgz ' , ' TGZ Archive ' ) ) , ' File Format ' , required = True ) ,
2008-07-22 14:24:36 +00:00
' modules ' : fields . many2many ( ' ir.module.module ' , ' rel_modules_langexport ' , ' wiz_id ' , ' module_id ' , ' Modules ' , domain = [ ( ' state ' , ' = ' , ' installed ' ) ] ) ,
' data ' : fields . binary ( ' File ' , readonly = True ) ,
2009-01-26 11:57:42 +00:00
' advice ' : fields . text ( ' Advice ' , readonly = True ) ,
2008-07-22 14:24:36 +00:00
' state ' : fields . selection ( ( ( ' choose ' , ' choose ' ) , # choose language
( ' get ' , ' get ' ) , # get the file
) ) ,
}
2008-09-02 11:49:22 +00:00
_defaults = { ' state ' : lambda * a : ' choose ' ,
}
2008-07-09 11:38:36 +00:00
wizard_export_lang ( )
2008-07-23 15:01:27 +00:00
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: