From 0b1dfd702fd5b087f0e1be81ccf3ed77f0dcf3da Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Tue, 8 Jul 2008 08:13:12 +0000 Subject: * translation of nearly all exceptions * the export of translations per module take only the files of these modules bzr revid: chs@tinyerp.com-52cb3686b17250df7bc23bf90d18397c7888e6f2 --- bin/addons/base/ir/ir_model.py | 11 ++++++----- bin/addons/base/ir/ir_report_custom.py | 15 ++++++++------- bin/addons/base/ir/ir_translation.py | 5 ++--- bin/addons/base/ir/ir_values.py | 1 + bin/addons/base/module/module.py | 18 ++++++++---------- bin/addons/base/module/wizard/wizard_export_lang.py | 4 ++-- bin/addons/base/module/wizard/wizard_import_lang.py | 8 ++++++-- bin/addons/base/module/wizard/wizard_module_import.py | 2 +- bin/addons/base/res/partner/partner.py | 2 +- bin/addons/base/res/res_currency.py | 5 +++-- bin/addons/base/res/res_user.py | 10 +++++----- 11 files changed, 43 insertions(+), 38 deletions(-) (limited to 'bin/addons/base') diff --git a/bin/addons/base/ir/ir_model.py b/bin/addons/base/ir/ir_model.py index 15c3224e784..0c6bfc7edb1 100644 --- a/bin/addons/base/ir/ir_model.py +++ b/bin/addons/base/ir/ir_model.py @@ -71,7 +71,7 @@ class ir_model(osv.osv): def unlink(self, cr, user, ids, context=None): for model in self.browse(cr, user, ids, context): if model.state <> 'manual': - raise except_orm('Error', "You can not remove the model '%s' !" %(field.name,)) + raise except_orm(_('Error'), _("You can not remove the model '%s' !") %(field.name,)) res = super(ir_model, self).unlink(cr, user, ids, context) pooler.restart_pool(cr.dbname) return res @@ -138,7 +138,7 @@ class ir_model_fields(osv.osv): def unlink(self, cr, user, ids, context=None): for field in self.browse(cr, user, ids, context): if field.state <> 'manual': - raise except_orm('Error', "You can not remove the field '%s' !" %(field.name,)) + raise except_orm(_('Error'), _("You can not remove the field '%s' !") %(field.name,)) # # MAY BE ADD A ALTER TABLE DROP ? # @@ -153,7 +153,7 @@ class ir_model_fields(osv.osv): res = super(ir_model_fields,self).create(cr, user, vals, context) if vals.get('state','base')=='manual': if not vals['name'].startswith('x_'): - raise except_orm('Error', "Custom fields must have a name that starts with 'x_' !") + raise except_orm(_('Error'), _("Custom fields must have a name that starts with 'x_' !")) if self.pool.get(vals['model']): self.pool.get(vals['model']).__init__(self.pool, cr) self.pool.get(vals['model'])._auto_init(cr,{}) @@ -207,7 +207,7 @@ class ir_model_access(osv.osv): 'WHERE a.group_id IS NULL AND m.model = %s', (model_name,)) r= cr.fetchall() if r[0][0] == None: - return True + return False # by default, the user had no access if not r[0][0]: if raise_exception: @@ -282,8 +282,9 @@ class ir_model_data(osv.osv): def _update(self,cr, uid, model, module, values, xml_id=False, store=True, noupdate=False, mode='init', res_id=False): warning = True model_obj = self.pool.get(model) + context = {} if xml_id and ('.' in xml_id): - assert len(xml_id.split('.'))==2, '"%s" contains too many dots. XML ids should not contain dots ! These are used to refer to other modules data, as in module.reference_id' % (xml_id) + assert len(xml_id.split('.'))==2, _('"%s" contains too many dots. XML ids should not contain dots ! These are used to refer to other modules data, as in module.reference_id') % (xml_id) warning = False module, xml_id = xml_id.split('.') if (not xml_id) and (not self.doinit): diff --git a/bin/addons/base/ir/ir_report_custom.py b/bin/addons/base/ir/ir_report_custom.py index b962684035e..af413f54e41 100644 --- a/bin/addons/base/ir/ir_report_custom.py +++ b/bin/addons/base/ir/ir_report_custom.py @@ -31,6 +31,7 @@ from osv import fields,osv from osv.orm import browse_null import ir import report.custom +from tools.translate import _ class report_custom(osv.osv): _name = 'ir.report.custom' @@ -75,10 +76,10 @@ class report_custom(osv.osv): # required on field0 does not seem to work( cause we use o2m_l ?) if not report.fields_child0: - raise osv.except_osv('Invalid operation :', 'Enter at least one field !') + raise osv.except_osv(_('Invalid operation'), _('Enter at least one field !')) if report.type in ['pie', 'bar', 'line'] and report.field_parent: - raise osv.except_osv('Invalid operation :', 'Tree can only be used in tabular reports') + raise osv.except_osv(_('Invalid operation'), _('Tree can only be used in tabular reports')) # Otherwise it won't build a good tree. See level.pop in custom.py. if report.type == 'table' and report.field_parent and report.fields_child0 and not report.fields_child0[0].groupby: @@ -86,7 +87,7 @@ class report_custom(osv.osv): if report.type == 'pie': if len(report.fields_child0) != 2: - raise osv.except_osv('Invalid operation :', 'Pie charts need exactly two fields') + raise osv.except_osv(_('Invalid operation'), _('Pie charts need exactly two fields')) else: c_f = {} for i in range(2): @@ -95,11 +96,11 @@ class report_custom(osv.osv): for j in range(3): c_f[i].append((not isinstance(eval('tmp.field_child'+str(j)), browse_null) and eval('tmp.field_child'+str(j)+'.ttype')) or None) if not reduce(lambda x,y : x or y, map(lambda x: x in ['integer', 'float'], c_f[1])): - raise osv.except_osv('Invalid operation : ','Second field should be figures') + raise osv.except_osv(_('Invalid operation'), _('Second field should be figures')) if report.type == 'bar': if len(report.fields_child0) < 2: - raise osv.except_osv('Invalid operation : ','Bar charts need at least two fields') + raise osv.except_osv(_('Invalid operation'), _('Bar charts need at least two fields')) else: c_f = {} for i in range(len(report.fields_child0)): @@ -112,7 +113,7 @@ class report_custom(osv.osv): pass else: if not reduce(lambda x,y : x or y, map(lambda x: x in ['integer', 'float'], c_f[i])): - raise osv.except_osv('Invalid operation : ','Field %d should be a figure' %(i,)) + raise osv.except_osv(_('Invalid operation'), _('Field %d should be a figure') %(i,)) if report.state=='subscribed': continue @@ -193,7 +194,7 @@ class report_custom_fields(osv.osv): } } else: - print "Warning: using a relation field which uses an unknown object" + print _("Warning: using a relation field which uses an unknown object") #TODO use the logger return {'required': {next_level_field_name: True}} else: return {'domain': {next_level_field_name: []}} diff --git a/bin/addons/base/ir/ir_translation.py b/bin/addons/base/ir/ir_translation.py index 20d2b383405..211f9dbaf45 100644 --- a/bin/addons/base/ir/ir_translation.py +++ b/bin/addons/base/ir/ir_translation.py @@ -121,9 +121,8 @@ class ir_translation(osv.osv, Cacheable): return trans if source: - source = source.strip().replace('\n',' ') - if isinstance(source, unicode): - source = source.encode('utf8') + #if isinstance(source, unicode): + # source = source.encode('utf8') cr.execute('select value ' \ 'from ir_translation ' \ 'where lang=%s ' \ diff --git a/bin/addons/base/ir/ir_values.py b/bin/addons/base/ir/ir_values.py index 8940cc8521b..84fafefa3f4 100644 --- a/bin/addons/base/ir/ir_values.py +++ b/bin/addons/base/ir/ir_values.py @@ -29,6 +29,7 @@ from osv import osv,fields import pickle +from tools.translate import _ class ir_values(osv.osv): _name = 'ir.values' diff --git a/bin/addons/base/module/module.py b/bin/addons/base/module/module.py index d124fbc4cdd..8442628a2e3 100644 --- a/bin/addons/base/module/module.py +++ b/bin/addons/base/module/module.py @@ -264,13 +264,13 @@ class module(osv.osv): ids = [ids] for mod in self.read(cr, uid, ids, ['state'], context): if mod['state'] in ('installed', 'to upgrade', 'to remove', 'to install'): - raise orm.except_orm('Error', - 'You try to remove a module that is installed or will be installed') + raise orm.except_orm(_('Error'), + _('You try to remove a module that is installed or will be installed')) return super(module, self).unlink(cr, uid, ids, context=context) def state_change(self, cr, uid, ids, newstate, context={}, level=50): if level<1: - raise Exception, 'Recursion error in modules dependencies !' + raise Exception, _('Recursion error in modules dependencies !') demo = True for module in self.browse(cr, uid, ids): mdemo = True @@ -288,7 +288,7 @@ class module(osv.osv): def state_upgrade(self, cr, uid, ids, newstate, context=None, level=50): dep_obj = self.pool.get('ir.module.module.dependency') if level<1: - raise Exception, 'Recursion error in modules dependencies !' + raise Exception, _('Recursion error in modules dependencies !') for module in self.browse(cr, uid, ids): dep_ids = dep_obj.search(cr, uid, [('name', '=', module.name)]) if dep_ids: @@ -320,7 +320,7 @@ class module(osv.osv): m.state not in ('uninstalled','uninstallable','to remove')''', (module.name,)) res = cr.fetchall() if res: - raise orm.except_orm('Error', 'The module you are trying to remove depends on installed modules :\n' + '\n'.join(map(lambda x: '\t%s: %s' % (x[0], x[1]), res))) + raise orm.except_orm(_('Error'), _('The module you are trying to remove depends on installed modules :\n %s') % '\n'.join(map(lambda x: '\t%s: %s' % (x[0], x[1]), res))) self.write(cr, uid, ids, {'state': 'to remove'}) return True @@ -420,9 +420,8 @@ class module(osv.osv): index_page = urllib.urlopen(repository.url).read() except IOError, e: if e.errno == 21: - raise orm.except_orm('Error', - 'This url \'%s\' must provide an html file ' - 'with links to zip modules' % (repository.url)) + raise orm.except_orm(_('Error'), + _("This url '%s' must provide an html file with links to zip modules") % (repository.url)) else: raise modules = re.findall(repository.filter, index_page, re.I+re.M) @@ -493,8 +492,7 @@ class module(osv.osv): fp.write(zipfile) fp.close() except IOError, e: - raise orm.except_orm('Error', 'Can not create the module file:\n %s' - % (fname,)) + raise orm.except_orm(_('Error'), _('Can not create the module file:\n %s') % (fname,)) terp = self.get_module_info(mod.name) self.write(cr, uid, mod.id, { 'description': terp.get('description', ''), diff --git a/bin/addons/base/module/wizard/wizard_export_lang.py b/bin/addons/base/module/wizard/wizard_export_lang.py index a42e3ec430e..a855ad503c8 100644 --- a/bin/addons/base/module/wizard/wizard_export_lang.py +++ b/bin/addons/base/module/wizard/wizard_export_lang.py @@ -60,12 +60,12 @@ class wizard_export_lang(wizard.interface): lang_obj=pooler.get_pool(cr.dbname).get('res.lang') ids=lang_obj.search(cr, uid, [('active', '=', True),]) langs=lang_obj.browse(cr, uid, ids) - return [(lang.code, lang.translatable and lang.name or 'New language') for lang in langs] + return [(lang.code, lang.translatable and lang.name or _('New language')) for lang in langs] def _get_file(self, cr, uid, data, context): file=tools.trans_generate(data['form']['lang'], 'all', dbname=cr.dbname) buf=StringIO.StringIO() - writer=csv.writer(buf, 'TINY') + writer=csv.writer(buf, 'UNIX') for row in file: writer.writerow(row) del file diff --git a/bin/addons/base/module/wizard/wizard_import_lang.py b/bin/addons/base/module/wizard/wizard_import_lang.py index d9543b7f851..a6516bb24df 100644 --- a/bin/addons/base/module/wizard/wizard_import_lang.py +++ b/bin/addons/base/module/wizard/wizard_import_lang.py @@ -32,6 +32,7 @@ import wizard import tools import base64 import pooler +from tempfile import TemporaryFile view_form="""
@@ -56,8 +57,11 @@ class wizard_import_lang(wizard.interface): def _import_lang(self, cr, uid, data, context): form=data['form'] - buf=base64.decodestring(data['form']['data']).split('\n') - tools.trans_load_data(cr.dbname, buf, form['code'], lang_name=form['name']) + #buf=base64.decodestring(form['data']).split('\n') + fileobj = TemporaryFile('w+') + fileobj.write( base64.decodestring(form['data']) ) + tools.trans_load_data(cr.dbname, fileobj, form['code'], lang_name=form['name']) + fileobj.close() return {} states={ diff --git a/bin/addons/base/module/wizard/wizard_module_import.py b/bin/addons/base/module/wizard/wizard_module_import.py index acaf7e3a7cf..d59c635cd30 100644 --- a/bin/addons/base/module/wizard/wizard_module_import.py +++ b/bin/addons/base/module/wizard/wizard_module_import.py @@ -75,7 +75,7 @@ class move_module_wizard(wizard.interface): fp.write(val) fp.close() except IOError, e: - raise wizard.except_wizard('Error !', 'Can not create the module file:\n'+' '+fname+'!') + raise wizard.except_wizard(_('Error !'), _('Can not create the module file: %s !') % (fname,) ) pooler.get_pool(cr.dbname).get('ir.module.module').update_list(cr, uid) return {'module_name': module_name} diff --git a/bin/addons/base/res/partner/partner.py b/bin/addons/base/res/partner/partner.py index 7061f46baed..220b6aabd78 100644 --- a/bin/addons/base/res/partner/partner.py +++ b/bin/addons/base/res/partner/partner.py @@ -252,7 +252,7 @@ class res_partner(osv.osv): try: nextref = int(ref)+1 except e: - raise osv.except_osv('Warning', "Couldn't generate the next id because some partners have an alphabetic id !") + raise osv.except_osv(_('Warning'), _("Couldn't generate the next id because some partners have an alphabetic id !")) # update the current partner cr.execute("update res_partner set ref=%d where id=%d", (nextref, ids[0])) diff --git a/bin/addons/base/res/res_currency.py b/bin/addons/base/res/res_currency.py index 8b419100f83..30b61e0f0ac 100644 --- a/bin/addons/base/res/res_currency.py +++ b/bin/addons/base/res/res_currency.py @@ -33,6 +33,7 @@ from osv import fields, osv import ir from tools.misc import currency +from tools.translate import _ import mx.DateTime from mx.DateTime import RelativeDateTime, now, DateTime, localtime @@ -87,9 +88,9 @@ class res_currency(osv.osv): code = from_currency.code else: code = to_currency.code - raise osv.except_osv('Error', 'No rate found \n' \ + raise osv.except_osv(_('Error'), _('No rate found \n' \ 'for the currency: %s \n' \ - 'at the date: %s' % (code, date)) + 'at the date: %s') % (code, date)) if to_currency_id==from_currency_id: if round: return self.round(cr, uid, to_currency, from_amount) diff --git a/bin/addons/base/res/res_user.py b/bin/addons/base/res/res_user.py index 8ce752ebcd7..24e16e6a03a 100644 --- a/bin/addons/base/res/res_user.py +++ b/bin/addons/base/res/res_user.py @@ -48,8 +48,8 @@ class groups(osv.osv): def write(self, cr, uid, ids, vals, context=None): if 'name' in vals: if vals['name'].startswith('-'): - raise osv.except_osv('Error', - 'The name of the group can not start with "-"') + raise osv.except_osv(_('Error'), + _('The name of the group can not start with "-"')) res = super(groups, self).write(cr, uid, ids, vals, context=context) # Restart the cache on the company_get method self.pool.get('ir.rule').domain_get() @@ -58,8 +58,8 @@ class groups(osv.osv): def create(self, cr, uid, vals, context=None): if 'name' in vals: if vals['name'].startswith('-'): - raise osv.except_osv('Error', - 'The name of the group can not start with "-"') + raise osv.except_osv(_('Error'), + _('The name of the group can not start with "-"')) return super(groups, self).create(cr, uid, vals, context=context) groups() @@ -163,7 +163,7 @@ class users(osv.osv): def unlink(self, cr, uid, ids): if 1 in ids: - raise osv.except_osv('Can not remove root user !', 'You can not remove the root user as it is used internally for resources created by Tiny ERP (updates, module installation, ...)') + raise osv.except_osv(_('Can not remove root user!'), _('You can not remove the root user as it is used internally for resources created by Tiny ERP (updates, module installation, ...)')) return super(users, self).unlink(cr, uid, ids) def name_search(self, cr, user, name='', args=None, operator='ilike', context=None, limit=80): -- cgit v1.2.3