raiseosv.except_osv(_('Error!'), _('Error Message.'))
注意:方法osv.except_osv()需要兩個參數,把參數放在_()中是實現了參數的國際化,可以不加_() Eg:
def __assistant_depmanager_prove(self, cr, uid, ids, context=None):
for qjd in self.browse(cr, uid, ids, context=context):
if qjd.shenqr.user_id.id == uid:
raise osv.except_osv(_('Warning!'), _('you cannot prove yourself'))
return False
elif qjd.tians > 1:
raise osv.except_osv(_('Warning!'), _('There are not enough access '))
return False
else:
return True
翻譯提示語
#. module: qingjia
#: code:addons/qingjia/qingjia.py:0
#, python-formatmsgid "Warning!"msgstr "提示!"
#. module: qingjia#: code:addons/qingjia/qingjia.py:0
#, python-formatmsgid "you cannot prove yourself"
msgstr "您不能審批您自己的請假單"
3) 在提示語中可以含有變量,以及對變量的中文翻譯
def assistant_depmanager_proved_new(self, cr, uid, ids, context=None):
res = self.browse(cr, uid, ids, context=context)
result = res[0]
raise osv.except_osv(_(' Error! '), _('Your uid is "%s" ,name is "%s",the state is "%s"')%(_(uid),_('王小波'),_(result.state)))
result = self.__assistant_depmanager_prove(cr, uid, ids, context=context)
if result:
self.write(cr, uid, ids, {'state': 'proved'})
說明:這裏的狀態翻譯後是對應的英文狀態名,如果還需要翻譯成中文,必須使用_()
#. module: qingjia#: code:addons/qingjia/qingjia.py:0
#, python-format
msgid "Your uid is \"%s\" ,name is \"%s\",the state is \"%s\""
msgstr "你的用戶id是:'%s',姓名是:'%s',請假單狀態是:'%s'"
對定義的所有狀態進行翻譯,最後狀態也將是中文的
#. module: qingjia
#: code:addons/qingjia/qingjia.py:0
#, python-format
msgid "wait_prove"msgstr "待批的"
效果圖如下