Remove deprecated functions locale.getdefaultlocale and locale.format.

Remove also GrampsLocale.format because it was there only to mirror
locale's API, and update GrampsLocale.format_string's signature to
match locale.format_string's post-python3.7.
This commit is contained in:
John Ralls 2023-07-14 13:13:13 -07:00 committed by Nick Hall
parent 7f8455c867
commit d5dd8d698c
4 changed files with 8 additions and 18 deletions

View File

@ -275,7 +275,7 @@ class GrampsLocale:
self.lang = loc[0]
self.encoding = loc[1]
else:
(lang, loc) = _check_mswin_locale(locale.getdefaultlocale()[0])
(lang, loc) = _check_mswin_locale(locale.getlocale()[0])
if lang:
self.lang = lang
self.encoding = loc[1]
@ -356,9 +356,7 @@ class GrampsLocale:
_failure = False
try:
locale.setlocale(locale.LC_ALL, '')
if not _check_locale(locale.getdefaultlocale(envvars=('LC_ALL',
'LANG',
'LANGUAGE'))):
if not _check_locale(locale.getlocale(category=locale.LC_MESSAGES)):
LOG.debug("Usable locale not found, localization "
"settings ignored.")
self.lang = 'C'
@ -987,22 +985,14 @@ class GrampsLocale:
from ..lib.grampstype import GrampsType
return GrampsType.xml_str(name)
def format(self, format, val, grouping=False, monetary=False):
"""
Format a number in the current numeric locale. See python's
locale.format for details. ICU's formatting codes are
incompatible with locale's, so just use locale.format for now.
"""
return locale.format(format, val, grouping, monetary)
def format_string(self, format, val, grouping=False):
def format_string(self, fmt, val, grouping=False, monetary=False):
"""
Format a string in the current numeric locale. See python's
locale.format_string for details. ICU's message formatting codes are
incompatible with locale's, so just use locale.format_string
for now.
"""
return locale.format_string(format, val, grouping)
return locale.format_string(fmt, val, grouping, monetary)
def float(self, val):
"""

View File

@ -178,7 +178,7 @@ class Histogram(Gtk.DrawingArea):
total = sum(self.data)
for i in range(len(self.data)):
if total > 0:
percent = glocale.format('%.2f', self.data[i] / total * 100)
percent = glocale.format_string('%.2f', self.data[i] / total * 100)
else:
percent = ''
layout = self.create_pango_layout(percent)

View File

@ -260,13 +260,13 @@ class PedigreeGramplet(Gramplet):
if g == 0:
self.link(_("Generation 1"), 'PersonList', handles,
tooltip=_("Double-click to see people in generation"))
percent = glocale.format('%.2f', 100) + percent_sign
percent = glocale.format_string('%.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 = glocale.format('%.2f', float(count)/2**(g-1) * 100) + percent_sign
percent = glocale.format_string('%.2f', float(count)/2**(g-1) * 100) + percent_sign
self.append_text(
# Translators: leave all/any {...} untranslated
ngettext(" has {count_person} of {max_count_person} "

View File

@ -115,7 +115,7 @@ class NumberOfAncestorsReport(Report):
gen += 1
theoretical = math.pow(2, (gen - 1))
total_theoretical += theoretical
percent = '(%s%%)' % self._locale.format(
percent = '(%s%%)' % self._locale.format_string(
'%3.2f', ((sum(thisgen.values()) / theoretical) * 100))
# TC # English return something like: