Skip to content

Commit

Permalink
Replace locale.format() with locale.format_string()
Browse files Browse the repository at this point in the history
The former was deprecated in Python 3.7 and removed in Python 3.12
(see [1] and [2]).

[1] https://docs.python.org/3/whatsnew/3.7.html#id7
[2] python/cpython#94226
  • Loading branch information
frougon committed Nov 23, 2024
1 parent f5624be commit 68131fc
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
10 changes: 5 additions & 5 deletions ffgo/fgdata/airport.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ def tooltipText(self):
_("Latitude: {latitude}").format(latitude=self.lat),
_("Longitude: {longitude}").format(longitude=self.lon),
_("Elevation: {elev_feet} ft ({elev_meters} m)").format(
elev_feet=locale.format("%d", round(self.elevation)),
elev_meters=locale.format("%.01f", self.elevation*0.3048))]
elev_feet=locale.format_string("%d", round(self.elevation)),
elev_meters=locale.format_string("%.01f", self.elevation*0.3048))]

if magField is not None:
magVar = locale.format("%.01f", magField.decl(self.lat, self.lon))
magVar = locale.format_string("%.01f", magField.decl(self.lat, self.lon))
l.append(_("Magnetic variation: {}°").format(magVar))

return '\n'.join(l + rl)
Expand Down Expand Up @@ -370,7 +370,7 @@ def __str__(self):
return "{} ({})".format(self.name, self.type)

def formatLength(self, val):
return locale.format("%d", round(val))
return locale.format_string("%d", round(val))

def _addLatitude(self, l):
if self.lat is not None:
Expand Down Expand Up @@ -428,7 +428,7 @@ def _addRunwayMarkings(self, l):
def _addSmoothness(self, l):
if self.smoothness is not None:
l.append(_("Smoothness: {}").format(
locale.format("%.02f", self.smoothness)))
locale.format_string("%.02f", self.smoothness)))


class LandRunway(RunwayBase):
Expand Down
4 changes: 2 additions & 2 deletions ffgo/fgdata/parking.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@ def tooltipText(self):
l = []

if abs(self.radius - round(self.radius)) < 0.01:
radiusStr = locale.format("%d", round(self.radius))
radiusStr = locale.format_string("%d", round(self.radius))
else:
radiusStr = locale.format("%.02f", self.radius)
radiusStr = locale.format_string("%.02f", self.radius)
l.append(
pgettext('parking position', 'Radius: {} m').format(radiusStr))

Expand Down
12 changes: 6 additions & 6 deletions ffgo/gui/gps_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ def __init__(self, master, config, app):
ToolTip(flightDurationPostfixLabel,
_("Decomposition using Julian years\n"
"(1 Julian year = {days} days)").format(
days=locale.format("%.02f", 365.25, grouping=True)))
days=locale.format_string("%.02f", 365.25, grouping=True)))

# This causes the initialization of the various fields of the dialog
# because of the TreeviewSelect event generated by the initial airport
Expand Down Expand Up @@ -739,22 +739,22 @@ def decomposeMinutes(self, nMin):

if years:
l.append(_("{nYears} {years}").format(
nYears=locale.format("%d", years, grouping=True),
nYears=locale.format_string("%d", years, grouping=True),
years=ngettext("year", "years", years)))

if days:
l.append(_("{nDays} {days}").format(
nDays=locale.format("%d", days, grouping=True),
nDays=locale.format_string("%d", days, grouping=True),
days=ngettext("day", "days", days)))

if hours:
l.append(_("{nHours} {hours}").format(
nHours=locale.format("%d", hours, grouping=True),
nHours=locale.format_string("%d", hours, grouping=True),
hours=ngettext("hour", "hours", hours)))

if minutes:
l.append(_("{nMinutes} {minutes}").format(
nMinutes=locale.format("%d", minutes, grouping=True),
nMinutes=locale.format_string("%d", minutes, grouping=True),
minutes=ngettext("minute", "minutes", minutes)))

if len(l) >= 2:
Expand All @@ -766,7 +766,7 @@ def decomposeMinutes(self, nMin):
# Use the same expression as above for uniformity and to avoid
# creating useless work for translations
res = _("{nMinutes} {minutes}").format(
nMinutes=locale.format("%d", 0, grouping=True),
nMinutes=locale.format_string("%d", 0, grouping=True),
minutes=ngettext("minute", "minutes", minutes))

return res
Expand Down
10 changes: 5 additions & 5 deletions ffgo/gui/pressure_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ def addVertSpacer(container, rowNum, colNum=0,
ToolTip(stdButton,
_("Set the standard pressure\n"
"({std_hPa} hPa = {std_inHg} inHg)").format(
std_hPa=locale.format("%.02f", 1013.25),
std_inHg=locale.format("%.02f", 29.92)))
std_hPa=locale.format_string("%.02f", 1013.25),
std_inHg=locale.format_string("%.02f", 29.92)))

# ----- Close button ----------------------------------------------------------
self.buttonFrame = self._newWidget(
Expand Down Expand Up @@ -220,7 +220,7 @@ def updateHPaValue(self, *args):
if not inHg.strip():
self.hPa.set('')
else:
self.hPa.set(locale.format("%.02f", locale.atof(inHg)*33.8639))
self.hPa.set(locale.format_string("%.02f", locale.atof(inHg)*33.8639))

# Accept any arguments to allow safe use as a Tkinter variable observer
def updateRoundedHPa(self, *args):
Expand All @@ -247,12 +247,12 @@ def updateInHg(self, *args):
if not hPa.strip():
self.inHg.set('')
else:
self.inHg.set(locale.format("%.02f", locale.atof(hPa)*0.02953))
self.inHg.set(locale.format_string("%.02f", locale.atof(hPa)*0.02953))

def setStandardValues(self):
# This will cause the value in inHg as well as the rounded hPa
# value to be updated.
self.hPa.set(locale.format("%.02f", 1013.25))
self.hPa.set(locale.format_string("%.02f", 1013.25))

def show(self):
"""Make sure the Pressure Converter dialog is visible."""
Expand Down
2 changes: 1 addition & 1 deletion ffgo/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class DecimalCoord(float):
def __str__(self):
# 8 decimal places, as recommended for latitudes and longitudes in
# the apt.dat v1000 spec
return locale.format("%.08f", self)
return locale.format_string("%.08f", self)

def __repr__(self):
return "{}.{}({!r})".format(__name__, type(self).__name__, float(self))
Expand Down

0 comments on commit 68131fc

Please sign in to comment.