Add formatLang function for the report

It formats the number for the defined lang using the locale settings.

bzr revid: ced-d00bbd91305d237e2bbdca471faf2a64feca68ab
This commit is contained in:
ced 2007-12-12 13:24:31 +00:00
parent c9a15982ac
commit 132b6e3762
1 changed files with 16 additions and 1 deletions

View File

@ -36,7 +36,7 @@ import tools
import pooler
import netsvc
import warnings
import locale
import copy
parents = {
@ -102,6 +102,7 @@ class rml_parse(object):
'setTag': self.setTag,
'removeParentNode': self.removeParentNode,
'format': self.format,
'formatLang': self.formatLang,
}
self.localcontext.update(context)
self.name = name
@ -152,6 +153,20 @@ class rml_parse(object):
def setLang(self, lang):
self.localcontext['lang'] = lang
def formatLang(self, value, digit=2):
lc, encoding = locale.getdefaultlocale()
if encoding == 'utf':
encoding = 'UTF-8'
try:
locale.setlocale(locale.LC_ALL,
(self.localcontext.get('lang', 'en_US') or 'en_US') + \
'.' + encoding)
except Exception:
netsvc.Logger().notifyChannel('report', netsvc.LOG_WARNING,
'report %s: unable to set locale "%s"' % (self.name,
self.localcontext.get('lang', 'en_US') or 'en_US'))
return locale.format('%.' + str(digit) + 'f', value, True)
def repeatIn(self, lst, name, nodes_parent=False):
self._node.data = ''
node = self._find_parent(self._node, nodes_parent or parents)