Exemplo n.º 1
0
func (lang *LangSelector) SetLocale(locale string) error {
	if lang.LocaleState == LocaleStateChanging {
		return nil
	}

	if len(locale) == 0 || !language_info.IsLocaleValid(locale,
		language_info.LanguageListFile) {
		return fmt.Errorf("Invalid locale: %v", locale)
	}
	if lang.lhelper == nil {
		return fmt.Errorf("LocaleHelper object is nil")
	}

	if lang.CurrentLocale == locale {
		return nil
	}

	go func() {
		lang.LocaleState = LocaleStateChanging
		lang.setPropCurrentLocale(locale)
		if ok, _ := isNetworkEnable(); !ok {
			err := sendNotify("", "",
				Tr("System language is being changed, please wait..."))
			if err != nil {
				lang.logger.Warning("sendNotify failed:", err)
			}
		} else {
			err := sendNotify("", "",
				Tr("System language is being changed with an installation of lacked language packages, please wait..."))
			if err != nil {
				lang.logger.Warning("sendNotify failed:", err)
			}
		}
		err := lang.lhelper.GenerateLocale(locale)
		if err != nil {
			lang.logger.Warning("GenerateLocale failed:", err)
			lang.LocaleState = LocaleStateChanged
		}
	}()

	return nil
}
Exemplo n.º 2
0
func getLocale() string {
	filename := path.Join(os.Getenv("HOME"), userLocaleFilePAM)
	locale, err := getLocaleFromFile(filename)
	if err != nil || len(locale) == 0 {
		locale, err = getLocaleFromFile(systemLocaleFile)
		if err != nil || len(locale) == 0 {
			locale = defaultLocale
		}

		writeUserLocale(locale)
	}

	if !language_info.IsLocaleValid(locale,
		language_info.LanguageListFile) {
		locale = defaultLocale
		writeUserLocale(locale)
	}

	return locale
}