def apply(self): (store, itr) = self._localeSelection.get_selected() locale = store[itr][1] self._set_lang(locale) localization.setup_locale(locale, self.data.lang) # Skip timezone and keyboard default setting for kickstart installs. # The user may have provided these values via kickstart and if not, we # need to prompt for them. if flags.flags.automatedInstall: return geoloc_timezone = geoloc.get_timezone() loc_timezones = localization.get_locale_timezones(self.data.lang.lang) if geoloc_timezone: # (the geolocation module makes sure that the returned timezone is # either a valid timezone or None) self.data.timezone.timezone = geoloc_timezone elif loc_timezones and not self.data.timezone.timezone: # no data is provided by Geolocation, try to get timezone from the # current language self.data.timezone.timezone = loc_timezones[0] self._set_keyboard_defaults(self.data.lang.lang)
def apply(self): (store, itr) = self._localeSelection.get_selected() locale = store[itr][1] localization.setup_locale(locale, self.data.lang) # Skip timezone and keyboard default setting for kickstart installs. # The user may have provided these values via kickstart and if not, we # need to prompt for them. if flags.flags.automatedInstall: return geoloc_timezone = geoloc.get_timezone() loc_timezones = localization.get_locale_timezones(self.data.lang.lang) if geoloc_timezone: # (the geolocation module makes sure that the returned timezone is # either a valid timezone or None) self.data.timezone.timezone = geoloc_timezone elif loc_timezones and not self.data.timezone.timezone: # no data is provided by Geolocation, try to get timezone from the # current language self.data.timezone.timezone = loc_timezones[0] # setup Gtk direction (RTL/LTR) now that we have the language # configuration applied setup_gtk_direction() self._set_keyboard_defaults(self.data.lang.lang)
def initialize_locale(opts, text_mode): """Initialize locale. :param opts: the command line/boot options :param text_mode: is the locale being set up for the text mode? """ from pyanaconda import localization locale_option = None localization_proxy = None if is_module_available(LOCALIZATION): localization_proxy = LOCALIZATION.get_proxy() # If the language was set on the command line, copy that to kickstart if opts.lang: localization_proxy.SetLanguage(opts.lang) localization_proxy.SetLanguageKickstarted(True) # Setup the locale environment if localization_proxy.LanguageKickstarted: locale_option = localization_proxy.Language localization.setup_locale_environment(locale_option, text_mode=text_mode) # Now that LANG is set, do something with it localization.setup_locale(os.environ["LANG"], localization_proxy, text_mode=text_mode)
def _setup_locale(self): log.debug("setting up locale") # Normalize the locale environment variables if self.data.lang.seen: locale_arg = self.data.lang.lang else: locale_arg = None setup_locale_environment(locale_arg, prefer_environment=True) setup_locale(os.environ['LANG'], text_mode=not self.gui_mode)
def on_locale_selection_changed(self, selection): (store, selected) = selection.get_selected_rows() if hasattr(self.window, "set_may_continue"): self.window.set_may_continue(len(selected) > 0) if selected: lang = store[selected[0]][1] localization.setup_locale(lang) self.retranslate(lang)
def _setup_locale(self): log.debug("setting up locale") localization_proxy = LOCALIZATION.get_proxy() # Normalize the locale environment variables if localization_proxy.Kickstarted: locale_arg = localization_proxy.Language else: locale_arg = None setup_locale_environment(locale_arg, prefer_environment=True) setup_locale(os.environ['LANG'], text_mode=not self.gui_mode)
def on_locale_selection_changed(self, selection): (store, selected) = selection.get_selected_rows() if hasattr(self.window, "set_may_continue"): self.window.set_may_continue(len(selected) > 0) if selected: lang = store[selected[0]][1] self._set_lang(lang) localization.setup_locale(lang) self.retranslate() # Reset the text direction setup_gtk_direction() # Redraw the window to reset the sidebar to where it needs to be self.window.queue_draw()
def apply(self): (store, itr) = self._localeSelection.get_selected() locale = store[itr][1] locale = localization.setup_locale(locale, self._l12_module.proxy, text_mode=False) self._set_lang(locale) # Skip timezone and keyboard default setting for kickstart installs. # The user may have provided these values via kickstart and if not, we # need to prompt for them. But do continue if geolocation-with-kickstart # is enabled. if flags.flags.automatedInstall and not geoloc.geoloc.enabled: return timezone_proxy = TIMEZONE.get_proxy() loc_timezones = localization.get_locale_timezones(self._l12_module.proxy.Language) if geoloc.geoloc.result.timezone: # (the geolocation module makes sure that the returned timezone is # either a valid timezone or None) log.info("using timezone determined by geolocation") timezone_proxy.SetTimezone(geoloc.geoloc.result.timezone) # Either this is an interactive install and timezone.seen propagates # from the interactive default kickstart, or this is a kickstart # install where the user explicitly requested geolocation to be used. # So set timezone.seen to True, so that the user isn't forced to # enter the Date & Time spoke to acknowledge the timezone detected # by geolocation before continuing the installation. timezone_proxy.SetKickstarted(True) elif loc_timezones and not timezone_proxy.Timezone: # no data is provided by Geolocation, try to get timezone from the # current language log.info("geolocation not finished in time, using default timezone") timezone_proxy.SetTimezone(loc_timezones[0])
def apply(self): (store, itr) = self._localeSelection.get_selected() locale = store[itr][1] locale = localization.setup_locale(locale, self.data.lang, text_mode=False) self._set_lang(locale) # Skip timezone and keyboard default setting for kickstart installs. # The user may have provided these values via kickstart and if not, we # need to prompt for them. But do continue if geolocation-with-kickstart # is enabled. if flags.flags.automatedInstall and not geoloc.geoloc.enabled: return loc_timezones = localization.get_locale_timezones(self.data.lang.lang) if geoloc.geoloc.result.timezone: # (the geolocation module makes sure that the returned timezone is # either a valid timezone or None) log.info("using timezone determined by geolocation") self.data.timezone.timezone = geoloc.geoloc.result.timezone # Either this is an interactive install and timezone.seen propagates # from the interactive default kickstart, or this is a kickstart # install where the user explicitly requested geolocation to be used. # So set timezone.seen to True, so that the user isn't forced to # enter the Date & Time spoke to acknowledge the timezone detected # by geolocation before continuing the installation. self.data.timezone.seen = True elif loc_timezones and not self.data.timezone.timezone: # no data is provided by Geolocation, try to get timezone from the # current language log.info("geolocation not finished in time, using default timezone") self.data.timezone.timezone = loc_timezones[0]
def reinitialize_locale(opts, text_mode): """Reinitialize locale. We need to reinitialize the locale if GUI startup failed. The text mode might not be able to display the characters from our current locale. :param opts: the command line/boot options :param text_mode: is the locale being set up for the text mode? """ from pyanaconda import localization localization_proxy = None if is_module_available(LOCALIZATION): localization_proxy = LOCALIZATION.get_proxy() log.warning("reinitializing locale due to failed attempt to start the GUI") localization.setup_locale(os.environ["LANG"], localization_proxy, text_mode=text_mode)
def test_setup_locale_notext(self, set_modules_locale_mock, setlocale_mock, setenv_mock): """Test setup_locale in GUI mode""" loc_proxy = MagicMock() locale = localization.setup_locale("sk", localization_proxy=loc_proxy) loc_proxy.SetLanguage.assert_called_once_with("sk") setenv_mock.assert_called_once_with("LANG", "sk") setlocale_mock.assert_called_once_with(locale_mod.LC_ALL, "sk") set_modules_locale_mock.assert_called_once_with("sk") self.assertEqual(locale, "sk")
def test_setup_locale_text(self, set_modules_locale_mock, setlocale_mock, setenv_mock, locale_supported_in_console_mock): """Test setup_locale in TUI mode""" # note: to eliminate unpredictable support in console, mocking such that it always fails locale = localization.setup_locale("ja_JP", text_mode=True) locale_supported_in_console_mock.assert_called_once_with("ja_JP") self.assertEqual(localization.os.environ["LANG"], DEFAULT_LANG) setenv_mock.assert_called_once_with("LANG", DEFAULT_LANG) setlocale_mock.assert_called_once_with(locale_mod.LC_ALL, DEFAULT_LANG) set_modules_locale_mock.assert_called_once_with(DEFAULT_LANG) self.assertEqual(locale, DEFAULT_LANG)
def test_setup_locale_setlocale_fail(self, set_modules_locale_mock, setlocale_mock, setenv_mock): """Test setup_locale with failure in setlocale""" locale = localization.setup_locale("es_ES") setenv_mock.assert_has_calls([ call("LANG", "es_ES"), call("LANG", DEFAULT_LANG) ]) setlocale_mock.assert_has_calls([ call(locale_mod.LC_ALL, "es_ES"), call(locale_mod.LC_ALL, DEFAULT_LANG) ]) setlocale_mock.assert_called_with(locale_mod.LC_ALL, DEFAULT_LANG) set_modules_locale_mock.assert_called_once_with(DEFAULT_LANG) self.assertEqual(locale, DEFAULT_LANG)
# If the language was set on the command line, copy that to kickstart if opts.lang: localization_proxy.SetLanguage(opts.lang) localization_proxy.SetLanguageKickstarted(True) # Setup the locale environment if localization_proxy.LanguageKickstarted: locale_option = localization_proxy.Language else: locale_option = None localization.setup_locale_environment(locale_option, text_mode=anaconda.tui_mode) # Now that LANG is set, do something with it localization.setup_locale(os.environ["LANG"], localization_proxy, text_mode=anaconda.tui_mode) from pyanaconda.storage.initialization import enable_installer_mode, reset_storage enable_installer_mode() # Initialize the network now, in case the display needs it from pyanaconda.network import initialize_network, wait_for_connecting_NM_thread, wait_for_connected_NM initialize_network() # If required by user, wait for connection before starting the installation. if opts.waitfornet: log.info( "network: waiting for connectivity requested by inst.waitfornet=%d", opts.waitfornet) wait_for_connected_NM(timeout=opts.waitfornet)
def initialize(self): self.initialize_start() 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. # # But as the lookup might still be in progress we need to make sure # to wait for it to finish. If the lookup has already finished # the wait function is basically a noop. geoloc.geoloc.wait_for_refresh_to_finish() # the lookup should be done now, get the teorritory territory = geoloc.geoloc.result.territory_code # bootopts and kickstart have priority over geoip language = self._l12_module.proxy.Language if language and self._l12_module.proxy.LanguageKickstarted: locales = [language] 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._l12_module.proxy, text_mode=False) lang_itr, _locale_itr = self._select_locale( self._l12_module.proxy.Language) 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._l12_module.proxy) self._set_lang(locale) self._select_locale(self._l12_module.proxy.Language) # report that we are done self.initialize_done()
# Set the language before loading an interface, when it may be too late. # If the language was set on the command line, copy that to kickstart if opts.lang: ksdata.lang.lang = opts.lang ksdata.lang.seen = True # Setup the locale environment if ksdata.lang.seen: locale_option = ksdata.lang.lang else: locale_option = None localization.setup_locale_environment(locale_option, text_mode=anaconda.tui_mode) # Now that LANG is set, do something with it localization.setup_locale(os.environ["LANG"], ksdata.lang, text_mode=anaconda.tui_mode) from pyanaconda.storage.osinstall import storage_initialize, enable_installer_mode enable_installer_mode() # Initialize the network now, in case the display needs it from pyanaconda.network import networkInitialize, wait_for_connecting_NM_thread, wait_for_connected_NM networkInitialize(ksdata) # If required by user, wait for connection before starting the installation. if opts.waitfornet: log.info("network: waiting for connectivity requested by inst.waitfornet=%d", opts.waitfornet) wait_for_connected_NM(timeout=opts.waitfornet) # In any case do some actions only after NM finishes its connecting. threadMgr.add(AnacondaThread(name=constants.THREAD_WAIT_FOR_CONNECTING_NM, target=wait_for_connecting_NM_thread, args=(ksdata,)))
def _apply_selected_locale(self, locale): """Apply the selected locale.""" locale = localization.setup_locale(locale, self._l12_module, text_mode=False) self._set_lang(locale)
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)
localization_proxy = LOCALIZATION.get_proxy() # If the language was set on the command line, copy that to kickstart if opts.lang: localization_proxy.SetLanguage(opts.lang) localization_proxy.SetLanguageKickstarted(True) # Setup the locale environment if localization_proxy.LanguageKickstarted: locale_option = localization_proxy.Language else: locale_option = None localization.setup_locale_environment(locale_option, text_mode=anaconda.tui_mode) # Now that LANG is set, do something with it localization.setup_locale(os.environ["LANG"], localization_proxy, text_mode=anaconda.tui_mode) from pyanaconda.storage.osinstall import storage_initialize, enable_installer_mode enable_installer_mode() # Initialize the network now, in case the display needs it from pyanaconda.network import networkInitialize, wait_for_connecting_NM_thread, wait_for_connected_NM networkInitialize(ksdata) # If required by user, wait for connection before starting the installation. if opts.waitfornet: log.info("network: waiting for connectivity requested by inst.waitfornet=%d", opts.waitfornet) wait_for_connected_NM(timeout=opts.waitfornet) # In any case do some actions only after NM finishes its connecting. threadMgr.add(AnacondaThread(name=constants.THREAD_WAIT_FOR_CONNECTING_NM,
def initialize(self): self.initialize_start() 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. # # But as the lookup might still be in progress we need to make sure # to wait for it to finish. If the lookup has already finished # the wait function is basically a noop. geoloc.geoloc.wait_for_refresh_to_finish() # the lookup should be done now, get the teorritory territory = geoloc.geoloc.result.territory_code # bootopts and kickstart have priority over geoip language = self._l12_module.proxy.Language if language and self._l12_module.proxy.LanguageKickstarted: locales = [language] 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._l12_module.proxy, text_mode=False) lang_itr, _locale_itr = self._select_locale(self._l12_module.proxy.Language) 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._l12_module.proxy) self._set_lang(locale) self._select_locale(self._l12_module.proxy.Language) # report that we are done self.initialize_done()
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)
except pykickstart.errors.KickstartError as kserr: log.exception("kickstart parsing failed: %s" % kserr) sys.exit(1) if external_reconfig: # set the reconfig flag in kickstart so that # relevant spokes show up data.firstboot.firstboot = FIRSTBOOT_RECONFIG # Normalize the locale environment variables if data.lang.seen: locale_arg = data.lang.lang else: locale_arg = None setup_locale_environment(locale_arg, prefer_environment=True) setup_locale(os.environ['LANG'], text_mode=mode != "gui") if mode == "gui": try: # Try to import IS gui specifics log.debug("trying to import GUI") import initial_setup.gui except ImportError: log.exception("GUI import failed, falling back to TUI") mode = "tui" if mode == "gui": # gui already imported (see above) # Add addons to search paths initial_setup.gui.InitialSetupGraphicalUserInterface.update_paths(addon_module_paths)
# Set the language before loading an interface, when it may be too late. # If the language was set on the command line, copy that to kickstart if opts.lang: ksdata.lang.lang = opts.lang ksdata.lang.seen = True # Setup the locale environment if ksdata.lang.seen: locale_option = ksdata.lang.lang else: locale_option = None localization.setup_locale_environment(locale_option, opts.display_mode != "g") # Now that LANG is set, do something with it localization.setup_locale(os.environ["LANG"], ksdata.lang, opts.display_mode != "g") import blivet blivet.enable_installer_mode() # Initialize the network now, in case the display needs it from pyanaconda.network import networkInitialize, wait_for_connecting_NM_thread networkInitialize(ksdata) threadMgr.add(AnacondaThread(name=constants.THREAD_WAIT_FOR_CONNECTING_NM, target=wait_for_connecting_NM_thread, args=(ksdata,))) # now start the interface setupDisplay(anaconda, opts, addon_paths) if anaconda.gui_startup_failed: # we need to reinitialize the locale if GUI startup failed, # as we might now be in text mode, which might not be able to display
def initialize(self): self.initialize_start() 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. locales = self._get_starting_locales() # get the data models filter_store = self._languageStoreFilter store = filter_store.get_model() # get language codes for the locales langs = [localization.get_language_id(locale) for locale in locales] # get common languages and append them here common_langs = localization.get_common_languages() common_langs_len = len(set(common_langs).difference(set(langs))) langs += common_langs # check which of the geolocated or common 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._l12_module, text_mode=False) lang_itr, _locale_itr = self._select_locale( self._l12_module.Language) langs_with_translations[DEFAULT_LANG] = lang_itr locales = [DEFAULT_LANG] # go over all geolocated and common 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.get_language_id(l) != lang ] # And then we add a separator after the selected best language # and any additional languages (that have translations) from geoip langs_with_translations_len = len(langs_with_translations) newItr = store.insert(langs_with_translations_len) store.set(newItr, 0, "", 1, "", 2, "", 3, True) # add a separator before common languages as well commonLangsItr = store.insert(langs_with_translations_len - common_langs_len) store.set(commonLangsItr, 0, "", 1, "", 2, "", 3, True) # setup the "best" locale best_locale = locales[0] if locales else DEFAULT_LANG locale = localization.setup_locale(best_locale, self._l12_module) self._set_lang(locale) self._select_locale(self._l12_module.Language) # report that we are done self.initialize_done()
# If the language was set on the command line, copy that to kickstart if opts.lang: ksdata.lang.lang = opts.lang ksdata.lang.seen = True # Setup the locale environment if ksdata.lang.seen: locale_option = ksdata.lang.lang else: locale_option = None localization.setup_locale_environment(locale_option, opts.display_mode != "g") # Now that LANG is set, do something with it localization.setup_locale(os.environ["LANG"], ksdata.lang, opts.display_mode != "g") import blivet blivet.enable_installer_mode() # Initialize the network now, in case the display needs it from pyanaconda.network import networkInitialize, wait_for_connecting_NM_thread networkInitialize(ksdata) threadMgr.add( AnacondaThread(name=constants.THREAD_WAIT_FOR_CONNECTING_NM, target=wait_for_connecting_NM_thread, args=(ksdata, ))) # initialize the screen access manager before launching the UI from pyanaconda import screen_access