Ejemplo n.º 1
0
    def initialize(self):
        store = self.builder.get_object("languageStore")
        self._languageStoreFilter = self.builder.get_object("languageStoreFilter")
        self._languageEntry = self.builder.get_object("languageEntry")
        self._selection = self.builder.get_object("languageViewSelection")
        self._view = self.builder.get_object("languageView")

        # We need to tell the view whether something is a separator or not.
        self._view.set_row_separator_func(self._row_is_separator, None)

        # We can use the territory from geolocation here
        # to preselect the translation, when it's available.
        territory = geoloc.get_territory_code()
        self.language = Language(LOCALE_PREFERENCES, territory=territory)

        # check if there is one and only one locale for the territory
        if len(self.language.preferred_locales) != 1:
            log.info("Didn't get a single locale from Geolocation,"
                        " falling back to default locale.")
            self.language = Language(LOCALE_PREFERENCES, territory=None)
            # Explanation:
            # Some territories have multiple locales,
            # for example, the Switzerland has:
            # de_CH, it_CH and fr_CH
            # As there is no clear order of preference for them,
            # it is safer to just fall back to the default locale

        # fill the list with available translations
        for _code, trans in sorted(self.language.translations.items()):
            self._addLanguage(store, trans.display_name,
                              trans.english_name, trans.short_name)

        # Move the default language (whatever was provided on the command line,
        # or by kickstart, or by geoip, or English if nothing else) to the top
        # of the list and select it by default.  People find it confusing to be
        # dropped into the middle of a scrollable list.
        (store, itr) = self._selection.get_selected()
        if not itr:
            # check if a language was set by kickstart
            # NOTE: seen means the language was "seen" in
            # kickstart or boot option, so it overrides
            # the language detected by geolocation
            if self.data.lang.lang and self.data.lang.seen:
                lang = self.data.lang.lang
            else:
                lang = self.language.preferred_translation.short_name

            itr = self._selectLanguage(lang)

        # store is the filtered store, and itr is an iter on it.  We need to
        # convert to an iter on the underlying store.
        itr = store.convert_iter_to_child_iter(itr)
        store = store.get_model()
        store.move_after(itr, None)

        # And then we add a separator after the default chosen language.
        newItr = store.insert(1)
        store.set(newItr, 0, "", 1, "", 2, "", 3, True)

        self._languageStoreFilter.set_visible_func(self._matchesEntry, None)
Ejemplo n.º 2
0
    def initialize(self):
        self._languageStore = self.builder.get_object("languageStore")
        self._languageStoreFilter = self.builder.get_object("languageStoreFilter")
        self._languageEntry = self.builder.get_object("languageEntry")
        self._langSelection = self.builder.get_object("languageViewSelection")
        self._langSelectedRenderer = self.builder.get_object("langSelectedRenderer")
        self._langSelectedColumn = self.builder.get_object("langSelectedColumn")
        self._langView = self.builder.get_object("languageView")
        self._localeView = self.builder.get_object("localeView")
        self._localeStore = self.builder.get_object("localeStore")
        self._localeSelection = self.builder.get_object("localeViewSelection")

        LangLocaleHandler.initialize(self)

        # We need to tell the view whether something is a separator or not.
        self._langView.set_row_separator_func(self._row_is_separator, None)

        # We can use the territory from geolocation here
        # to preselect the translation, when it's available.
        territory = geoloc.get_territory_code(wait=True)

        # bootopts and kickstart have priority over geoip
        if self.data.lang.lang and self.data.lang.seen:
            locales = [self.data.lang.lang]
        else:
            locales = localization.get_territory_locales(territory) or [DEFAULT_LANG]

        # get the data models
        filter_store = self._languageStoreFilter
        store = filter_store.get_model()

        # get language codes for the locales
        langs = [localization.parse_langcode(locale)['language'] for locale in locales]

        # check which of the geolocated languages have translations
        # and store the iterators for those languages in a dictionary
        langs_with_translations = {}
        itr = store.get_iter_first()
        while itr:
            row_lang = store[itr][2]
            if row_lang in langs:
                langs_with_translations[row_lang] = itr
            itr = store.iter_next(itr)

        # if there are no translations for the given locales,
        # use default
        if not langs_with_translations:
            localization.setup_locale(DEFAULT_LANG, self.data.lang)
            lang_itr, _locale_itr = self._select_locale(self.data.lang.lang)
            langs_with_translations[DEFAULT_LANG] = lang_itr
            locales = [DEFAULT_LANG]

        # go over all geolocated languages in reverse order
        # and move those we have translation for to the top of the
        # list, above the separator
        for lang in reversed(langs):
            itr = langs_with_translations.get(lang)
            if itr:
                store.move_after(itr, None)
            else:
                # we don't have translation for this language,
                # so dump all locales for it
                locales = [l for l in locales
                           if localization.parse_langcode(l)['language'] != lang]

        # And then we add a separator after the selected best language
        # and any additional languages (that have translations) from geoip
        newItr = store.insert(len(langs_with_translations))
        store.set(newItr, 0, "", 1, "", 2, "", 3, True)

        # setup the "best" locale
        localization.setup_locale(locales[0], self.data.lang)
        self._select_locale(self.data.lang.lang)
Ejemplo n.º 3
0
    def initialize(self):
        self._languageStore = self.builder.get_object("languageStore")
        self._languageStoreFilter = self.builder.get_object("languageStoreFilter")
        self._languageEntry = self.builder.get_object("languageEntry")
        self._langSelection = self.builder.get_object("languageViewSelection")
        self._langSelectedRenderer = self.builder.get_object("langSelectedRenderer")
        self._langSelectedColumn = self.builder.get_object("langSelectedColumn")
        self._langView = self.builder.get_object("languageView")
        self._localeView = self.builder.get_object("localeView")
        self._localeStore = self.builder.get_object("localeStore")
        self._localeSelection = self.builder.get_object("localeViewSelection")

        LangLocaleHandler.initialize(self)

        # We need to tell the view whether something is a separator or not.
        self._langView.set_row_separator_func(self._row_is_separator, None)

        # We can use the territory from geolocation here
        # to preselect the translation, when it's available.
        territory = geoloc.get_territory_code(wait=True)

        # bootopts and kickstart have priority over geoip
        if self.data.lang.lang and self.data.lang.seen:
            locales = [self.data.lang.lang]
        else:
            locales = localization.get_territory_locales(territory) or [DEFAULT_LANG]

        # get the data models
        filter_store = self._languageStoreFilter
        store = filter_store.get_model()

        # get language codes for the locales
        langs = [localization.parse_langcode(locale)['language'] for locale in locales]

        # check which of the geolocated languages have translations
        # and store the iterators for those languages in a dictionary
        langs_with_translations = {}
        itr = store.get_iter_first()
        while itr:
            row_lang = store[itr][2]
            if row_lang in langs:
                langs_with_translations[row_lang] = itr
            itr = store.iter_next(itr)

        # if there are no translations for the given locales,
        # use default
        if not langs_with_translations:
            self._set_lang(DEFAULT_LANG)
            localization.setup_locale(DEFAULT_LANG, self.data.lang, text_mode=False)
            lang_itr, _locale_itr = self._select_locale(self.data.lang.lang)
            langs_with_translations[DEFAULT_LANG] = lang_itr
            locales = [DEFAULT_LANG]

        # go over all geolocated languages in reverse order
        # and move those we have translation for to the top of the
        # list, above the separator
        for lang in reversed(langs):
            itr = langs_with_translations.get(lang)
            if itr:
                store.move_after(itr, None)
            else:
                # we don't have translation for this language,
                # so dump all locales for it
                locales = [l for l in locales
                           if localization.parse_langcode(l)['language'] != lang]

        # And then we add a separator after the selected best language
        # and any additional languages (that have translations) from geoip
        newItr = store.insert(len(langs_with_translations))
        store.set(newItr, 0, "", 1, "", 2, "", 3, True)

        # setup the "best" locale
        locale = localization.setup_locale(locales[0], self.data.lang)
        self._set_lang(locale)
        self._select_locale(self.data.lang.lang)