weather-indicator-team team mailing list archive
-
weather-indicator-team team
-
Mailing list archive
-
Message #00080
[Merge] lp:~marcelstimberg/weather-indicator/locale_number_format into lp:weather-indicator
Marcel Stimberg has proposed merging lp:~marcelstimberg/weather-indicator/locale_number_format into lp:weather-indicator.
Requested reviews:
Weather Indicator Team (weather-indicator-team)
Related bugs:
Bug #756704 in Weather Indicator: "Numbers (temperature etc.) do not use local number format"
https://bugs.launchpad.net/weather-indicator/+bug/756704
For more details, see:
https://code.launchpad.net/~marcelstimberg/weather-indicator/locale_number_format/+merge/57081
Sorry, about that... New merge request without the "refactoring". This should fix 756704 by formatting numbers according to the current locale.
--
https://code.launchpad.net/~marcelstimberg/weather-indicator/locale_number_format/+merge/57081
Your team Weather Indicator Team is requested to review the proposed merge of lp:~marcelstimberg/weather-indicator/locale_number_format into lp:weather-indicator.
=== modified file 'bin/indicator-weather'
--- bin/indicator-weather 2011-04-10 13:18:53 +0000
+++ bin/indicator-weather 2011-04-10 18:23:24 +0000
@@ -632,16 +632,17 @@
_unit = "ËF"
if self.__weather_datasource == WeatherDataSource.YAHOO:
if (self.__metric_system == MetricSystem.SI):
- _value = "%.1f" % ((float(self.__report['condition']['temp']) - 32) * 5/9)
+ _value = NumberFormatter.format("%.1f", (float(self.__report['condition']['temp']) - 32) * 5/9, remove_zero=True)
_unit = "ËC"
else:
_value = self.__report['condition']['temp']
_unit = "ËF"
# round the value if required
if needs_rounding:
- _value = round(float(_value))
- # Removing unnecessary '.0' in the end, if exists
- return ("%s %s" % (_value, _unit)).replace(".0", "")
+ _rounded = round(locale.atof(_value))
+ _value = NumberFormatter.format("%.1f", _rounded, remove_zero=True)
+
+ return ("%s %s" % (_value, _unit))
# Get temperature label
def get_temperature_label(self):
@@ -694,7 +695,7 @@
# Join wind_info data in a label
localized_wind_info[len(localized_wind_info)-1] = _unit
- localized_wind_info[len(localized_wind_info)-2] = ("%0.1f" % _value).replace(".0", "")
+ localized_wind_info[len(localized_wind_info)-2] = NumberFormatter.format("%0.1f", _value, remove_zero=True)
return ' '.join(localized_wind_info)
# Get sunrise label
@@ -1716,7 +1717,7 @@
ProxyMonitor.monitor_proxy(log)
# Use date-time format as in indicator-datetime
TimeFormatter.monitor_indicator_datetime(log)
-
+
# not running, safe to continue...
gtk.gdk.threads_init()
gtk.gdk.threads_enter()
=== modified file 'etc/xdg/autostart/indicator-weather.desktop' (properties changed: +x to -x)
=== modified file 'indicator_weather/helpers.py'
--- indicator_weather/helpers.py 2011-04-10 07:11:55 +0000
+++ indicator_weather/helpers.py 2011-04-10 18:23:24 +0000
@@ -22,6 +22,7 @@
'monitor_upower',
'ProxyMonitor',
'TimeFormatter',
+ 'NumberFormatter'
]
from gi.repository import Gio
@@ -32,6 +33,7 @@
import gtk
import urllib2
import dbus
+import locale
from dbus.mainloop.glib import DBusGMainLoop
from indicator_weather.indicator_weatherconfig import get_data_file
@@ -219,3 +221,30 @@
# ignore this as it might contain date params
#TimeFormatter.format = gsettings.get_string("custom-time-format")
TimeFormatter.format = "%X"
+
+class NumberFormatter:
+ """
+ Formats a number with respect to the locale settings
+ """
+
+ decimal_point = None
+
+ @staticmethod
+ def format(format, number, remove_zero=False):
+ """
+ Formats a number according to the current locale. If remove_zero is True, a trailing ".0"
+ (again, according to the locale) will be removed. Note that this assumes that there is never
+ more than one decimal after the decimal point.
+ """
+
+ formatted = locale.format(format, number)
+
+ if remove_zero:
+ #get decimal point character if not yet known
+ if NumberFormatter.decimal_point is None:
+ conventions = locale.localeconv()
+ NumberFormatter.decimal_point = conventions['decimal_point']
+
+ return formatted.rstrip("0").rstrip(NumberFormatter.decimal_point)
+ else:
+ return formatted
Follow ups