Get the available translations for anaconda and populate the welcome spoke with them. --- pyanaconda/localization.py | 54 +++++++++++++++++++++++++++++++++++ pyanaconda/ui/gui/spokes/welcome.py | 17 +++-------- 2 files changed, 59 insertions(+), 12 deletions(-) create mode 100644 pyanaconda/localization.py diff --git a/pyanaconda/localization.py b/pyanaconda/localization.py new file mode 100644 index 0000000..9f6a9d5 --- /dev/null +++ b/pyanaconda/localization.py @@ -0,0 +1,54 @@ +# Localization classes and functions +# +# Copyright (C) 2012 Red Hat, Inc. +# +# This copyrighted material is made available to anyone wishing to use, +# modify, copy, or redistribute it subject to the terms and conditions of +# the GNU General Public License v.2, or (at your option) any later version. +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY expressed or implied, including the implied warranties of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +# Public License for more details. You should have received a copy of the +# GNU General Public License along with this program; if not, write to the +# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the +# source code or documentation are not subject to the GNU General Public +# License and may only be used or replicated with the express permission of +# Red Hat, Inc. +# +# Red Hat Author(s): Martin Gracik <mgracik@xxxxxxxxxx> +# + +from collections import namedtuple +import gettext + +import babel + + +Lang = namedtuple('Lang', 'langcode, english_name, display_name') + + +def get_available_translations(domain=None, localedir=None): + domain = domain or gettext._current_domain + localedir = localedir or gettext._default_localedir + + langdict = babel.Locale('en', 'US').languages + messagefiles = gettext.find(domain, localedir, langdict.keys(), all=True) + languages = [path.split(os.path.sep)[-3] for path in messagefiles] + + # usually there are no message files for en_US + if 'en_US' not in languages: + languages.append('en_US') + + for langcode in languages: + try: + locale = babel.Locale.parse(langcode) + except babel.core.UnknownLocaleError: + continue + + # some languages don't have a display_name + display_name = locale.display_name or locale.english_name + # some start with lowercase + display_name = display_name.title() + + yield Lang(langcode, locale.english_name, display_name) diff --git a/pyanaconda/ui/gui/spokes/welcome.py b/pyanaconda/ui/gui/spokes/welcome.py index c5d0e1d..1ebef96 100644 --- a/pyanaconda/ui/gui/spokes/welcome.py +++ b/pyanaconda/ui/gui/spokes/welcome.py @@ -23,6 +23,8 @@ from gi.repository import AnacondaWidgets, Gtk from pyanaconda.ui.gui.hubs.summary import SummaryHub from pyanaconda.ui.gui.spokes import StandaloneSpoke +from pyanaconda.localization import get_available_translations + __all__ = ["WelcomeLanguageSpoke"] class WelcomeLanguageSpoke(StandaloneSpoke): @@ -47,18 +49,9 @@ class WelcomeLanguageSpoke(StandaloneSpoke): completion.set_text_column(1) store = self.builder.get_object("languageStore") - self._addLanguage(store, "English", "English", "en_US") - self._addLanguage(store, "Language A", "Language A", "C") - self._addLanguage(store, "Language B", "Language B", "C") - self._addLanguage(store, "Language C", "Language C", "C") - self._addLanguage(store, "Language D", "Language D", "C") - self._addLanguage(store, "Language E", "Language E", "C") - self._addLanguage(store, "Language F", "Language F", "C") - self._addLanguage(store, "Language G", "Language G", "C") - self._addLanguage(store, "Language H", "Language H", "C") - self._addLanguage(store, "Language I", "Language I", "C") - self._addLanguage(store, "Language J", "Language J", "C") - self._addLanguage(store, "Language K", "Language K", "C") + for trans in get_available_translations: + self._addLanguage(store, trans.display_name, + trans.english_name, trans.langcode) def setup(self): StandaloneSpoke.setup(self) -- 1.7.5.4 _______________________________________________ Anaconda-devel-list mailing list Anaconda-devel-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/anaconda-devel-list