[PATCH 1/3] Translate timezones in GUI
Vratislav Podzimek
vpodzime at redhat.com
Mon Nov 4 13:57:16 UTC 2013
Related: rhbz#1015209
Signed-off-by: Vratislav Podzimek <vpodzime at redhat.com>
---
anaconda.spec.in | 2 +-
pyanaconda/localization.py | 24 ++++++++++++++++++++++++
pyanaconda/ui/gui/spokes/datetime_spoke.glade | 8 ++++++--
pyanaconda/ui/gui/spokes/datetime_spoke.py | 16 +++++++++++-----
4 files changed, 42 insertions(+), 8 deletions(-)
diff --git a/anaconda.spec.in b/anaconda.spec.in
index 2a1ff7a..fcf2d71 100644
--- a/anaconda.spec.in
+++ b/anaconda.spec.in
@@ -41,7 +41,7 @@ Source0: %{name}-%{version}.tar.bz2
%define iscsiver 6.2.0.870-3
%define rpmver 4.10.0
%define libarchivever 3.0.4
-%define langtablever 0.0.7-1
+%define langtablever 0.0.18-1
BuildRequires: audit-libs-devel
BuildRequires: gettext >= %{gettextver}
diff --git a/pyanaconda/localization.py b/pyanaconda/localization.py
index c3f845a..a07f1fe 100644
--- a/pyanaconda/localization.py
+++ b/pyanaconda/localization.py
@@ -26,6 +26,7 @@ import re
import langtable
import glob
+from pyanaconda import constants
from pyanaconda.iutil import upcase_first_letter
import logging
@@ -370,6 +371,29 @@ def get_locale_territory(locale):
return parts.get("territory", None)
+def get_xlated_timezone(tz_spec_part):
+ """
+ Function returning translated name of a region, city or complete timezone
+ name according to the current value of the $LANG variable.
+
+ :param tz_spec_part: a region, city or complete timezone name
+ :type tz_spec_part: str
+ :return: translated name of the given region, city or timezone
+ :rtype: str
+
+ """
+
+ locale = os.environ.get("LANG", constants.DEFAULT_LANG)
+ parts = parse_langcode(locale)
+ if "language" not in parts:
+ raise InvalidLocaleSpec("'%s' is not a valid locale" % locale)
+
+ xlated = langtable.timezone_name(tz_spec_part, languageIdQuery=parts["language"],
+ territoryIdQuery=parts.get("territory", ""),
+ scriptIdQuery=parts.get("script", ""))
+
+ return xlated.encode("utf-8")
+
def write_language_configuration(lang, root):
"""
Write language configuration to the $root/etc/locale.conf file.
diff --git a/pyanaconda/ui/gui/spokes/datetime_spoke.glade b/pyanaconda/ui/gui/spokes/datetime_spoke.glade
index 228e3cf..6f935e7 100644
--- a/pyanaconda/ui/gui/spokes/datetime_spoke.glade
+++ b/pyanaconda/ui/gui/spokes/datetime_spoke.glade
@@ -12,6 +12,8 @@
<columns>
<!-- column-name name -->
<column type="gchararray"/>
+ <!-- column-name xlated -->
+ <column type="gchararray"/>
</columns>
</object>
<object class="GtkTreeModelFilter" id="citiesFilter">
@@ -65,6 +67,8 @@
<columns>
<!-- column-name name -->
<column type="gchararray"/>
+ <!-- column-name xlated -->
+ <column type="gchararray"/>
</columns>
</object>
<object class="GtkEntryCompletion" id="regionCompletion">
@@ -144,7 +148,7 @@
<property name="can_focus">False</property>
<property name="model">regions</property>
<property name="has_entry">True</property>
- <property name="entry_text_column">0</property>
+ <property name="entry_text_column">1</property>
<signal name="changed" handler="on_region_changed" object="regionsEntry" swapped="no"/>
<child internal-child="entry">
<object class="GtkEntry" id="regionsEntry">
@@ -186,7 +190,7 @@
<property name="can_focus">False</property>
<property name="model">citiesSort</property>
<property name="has_entry">True</property>
- <property name="entry_text_column">0</property>
+ <property name="entry_text_column">1</property>
<signal name="changed" handler="on_city_changed" object="citiesEntry" swapped="no"/>
<child internal-child="entry">
<object class="GtkEntry" id="citiesEntry">
diff --git a/pyanaconda/ui/gui/spokes/datetime_spoke.py b/pyanaconda/ui/gui/spokes/datetime_spoke.py
index 04c62b8..da33246 100644
--- a/pyanaconda/ui/gui/spokes/datetime_spoke.py
+++ b/pyanaconda/ui/gui/spokes/datetime_spoke.py
@@ -40,6 +40,7 @@ from pyanaconda import nm
from pyanaconda import ntp
from pyanaconda import flags
from pyanaconda import constants
+from pyanaconda import localization
from pyanaconda.threads import threadMgr, AnacondaThread
import datetime
@@ -326,7 +327,7 @@ class DatetimeSpoke(FirstbootSpokeMixIn, NormalSpoke):
self._citiesFilter.set_visible_func(self.city_in_region, None)
self._citiesSort = self.builder.get_object("citiesSort")
- self._citiesSort.set_sort_column_id(0, Gtk.SortType.ASCENDING)
+ self._citiesSort.set_sort_column_id(1, Gtk.SortType.ASCENDING)
self._hoursLabel = self.builder.get_object("hoursLabel")
self._minutesLabel = self.builder.get_object("minutesLabel")
@@ -359,9 +360,9 @@ class DatetimeSpoke(FirstbootSpokeMixIn, NormalSpoke):
self.add_to_store(self._yearsStore, year)
for region in self._regions_zones.keys():
- self.add_to_store(self._regionsStore, region)
+ self.add_to_store_xlated(self._regionsStore, region)
for city in self._regions_zones[region]:
- self.add_to_store(self._citiesStore, city)
+ self.add_to_store_xlated(self._citiesStore, city)
if self._radioButton24h.get_active():
self._set_amPm_part_sensitive(False)
@@ -393,11 +394,11 @@ class DatetimeSpoke(FirstbootSpokeMixIn, NormalSpoke):
def status(self):
if self.data.timezone.timezone:
if is_valid_timezone(self.data.timezone.timezone):
- return _("%s timezone") % self.data.timezone.timezone
+ return _("%s timezone") % localization.get_xlated_timezone(self.data.timezone.timezone)
else:
return _("Invalid timezone")
elif self._tzmap.get_timezone():
- return _("%s timezone") % self._tzmap.get_timezone()
+ return _("%s timezone") % localization.get_xlated_timezone(self._tzmap.get_timezone())
else:
return _("Nothing selected")
@@ -493,6 +494,11 @@ class DatetimeSpoke(FirstbootSpokeMixIn, NormalSpoke):
return True
@gtk_action_nowait
+ def add_to_store_xlated(self, store, item):
+ xlated = localization.get_xlated_timezone(item)
+ store.append([item, xlated])
+
+ @gtk_action_nowait
def add_to_store(self, store, item):
store.append([item])
--
1.7.11.7
More information about the anaconda-patches
mailing list