Better localization support for decimal separator.

svn: r11999
This commit is contained in:
Luigi Toscano 2009-02-15 21:50:27 +00:00
parent 00a667a54e
commit ce8b02c9f6
3 changed files with 9 additions and 8 deletions

View File

@ -21,6 +21,8 @@
This Gramplet shows textual distributions of age breakdowns of various types.
"""
import locale
from DataViews import register, Gramplet
import gen.lib
@ -214,7 +216,7 @@ class AgeStatsGramplet(Gramplet):
retval = _("Statistics") + ":\n"
retval += " " + _("Total") + ": %d\n" % count
retval += " " + _("Minimum") + ": %d\n" % minval
retval += " " + _("Average") + ": %.1f\n" % average
retval += " " + _("Average") + locale.format_string(": %.1f\n", average)
retval += " " + _("Median") + ": %d\n" % median
retval += " " + _("Maximum") + ": %d\n" % maxval
return retval
@ -253,10 +255,7 @@ class AgeStatsGramplet(Gramplet):
selected,
tooltip=_("Double-click to see %d people") % len(selected))
procent = float(len(selected))/(float(sum(hash.values())))*100
if procent > 10.0:
self.append_text("%2.2f" % procent)
else:
self.append_text("% 1.2f" % procent)
self.append_text(locale.format("%#5.2f", procent))
self.append_text("\n")
i += 1
self.append_text("--------" + self.format("", graph_width-4, fill = "-", borders="++") + "-----\n")

View File

@ -24,6 +24,7 @@
#
#------------------------------------------------------------------------
import cgi
import locale
#------------------------------------------------------------------------
#
@ -247,13 +248,13 @@ class PedigreeGramplet(Gramplet):
if g == 0:
self.link(_("Generation 1"), 'PersonList', handles,
tooltip=_("Double-click to see people in generation"))
percent = '%.2f%s' % ( 100, percent_sign)
percent = locale.format( '%.2f', 100) + percent_sign
self.append_text(_(" has 1 of 1 individual (%(percent)s complete)\n") % {'percent': percent})
else:
all.extend(handles)
self.link(_("Generation %d") % g, 'PersonList', handles,
tooltip=_("Double-click to see people in generation %d") % g)
percent = '%.2f%s' % ( float(count)/2**(g-1) * 100, percent_sign)
percent = locale.format('%.2f', float(count)/2**(g-1) * 100) + percent_sign
self.append_text(ngettext(
" has %(count_person)d of %(max_count_person)d individuals (%(percent)s complete)\n",
" has %(count_person)d of %(max_count_person)d individuals (%(percent)s complete)\n",

View File

@ -32,6 +32,7 @@
#------------------------------------------------------------------------
from gettext import gettext as _
from gettext import ngettext
import locale
import math
#------------------------------------------------------------------------
@ -95,7 +96,7 @@ class NumberOfAncestorsReport(Report):
gen += 1
theoretical = math.pow(2, ( gen - 1 ) )
total_theoretical += theoretical
percent = '(%3.2f%%)' % ((sum(thisgen.values()) / theoretical ) * 100)
percent = '(%s%%)' % locale.format('%3.2f', ((sum(thisgen.values()) / theoretical ) * 100))
# TC # English return something like:
# Generation 3 has 2 individuals. (50.00%)