|
6 | 6 | import pytz |
7 | 7 | import gi |
8 | 8 | import datetime |
| 9 | +import locale |
| 10 | +try: |
| 11 | + from babel import Locale as BabelLocale |
| 12 | +except: |
| 13 | + pass |
9 | 14 | import os |
10 | 15 | gi.require_version('TimezoneMap', '1.0') |
11 | 16 | from gi.repository import TimezoneMap |
@@ -241,18 +246,49 @@ def __init__(self): |
241 | 246 | self.city_combo.add_attribute(renderer_text, "text", 1) |
242 | 247 | self.city_combo.set_id_column(0) |
243 | 248 |
|
| 249 | + REGION_NAMES = { |
| 250 | + "Africa": _("Africa"), |
| 251 | + "America": _("America"), |
| 252 | + "Antarctica": _("Antarctica"), |
| 253 | + "Arctic": _("Arctic"), |
| 254 | + "Asia": _("Asia"), |
| 255 | + "Atlantic": _("Atlantic Ocean"), |
| 256 | + "Australia": _("Australia"), |
| 257 | + "Canada": _("Canada"), |
| 258 | + "Europe": _("Europe"), |
| 259 | + "Indian": _("Indian Ocean"), |
| 260 | + "Pacific": _("Pacific Ocean"), |
| 261 | + "US": _("USA"), |
| 262 | + } |
| 263 | + |
244 | 264 | self.region_map = {} |
245 | 265 | for tz in pytz.common_timezones: |
| 266 | + city_display_name = tz |
| 267 | + region_display_name = tz |
246 | 268 | try: |
247 | 269 | region, city = tz.split('/', maxsplit=1) |
248 | 270 | city_display_name = city.replace("_"," ") |
| 271 | + region_display_name = region |
249 | 272 | except: |
250 | 273 | continue |
251 | 274 |
|
| 275 | + try: |
| 276 | + # localize city names (best effort, ignore exceptions) |
| 277 | + loc = BabelLocale(locale.getlocale()[0]) |
| 278 | + city_display_name = loc.time_zones[tz]["city"] |
| 279 | + except: |
| 280 | + pass |
| 281 | + |
| 282 | + try: |
| 283 | + # localize the region name (best effort, ignore exceptions) |
| 284 | + region_display_name = REGION_NAMES[region_display_name] |
| 285 | + except: |
| 286 | + pass |
| 287 | + |
252 | 288 | if region not in self.region_map: |
253 | 289 | self.region_map[region] = Gtk.ListStore(str, str) |
254 | | - self.region_list.append([region, _(region)]) |
255 | | - self.region_map[region].append([city, _(city_display_name)]) |
| 290 | + self.region_list.append([region, region_display_name]) |
| 291 | + self.region_map[region].append([city, city_display_name]) |
256 | 292 |
|
257 | 293 | def set_timezone(self, timezone): |
258 | 294 | if timezone == "Etc/UTC" or timezone == "Universal": |
|
0 commit comments