func doSetLocale(locale string) error {
	lhelper, err := localehelper.NewLocaleHelper(
		"com.deepin.api.LocaleHelper",
		"/com/deepin/api/LocaleHelper",
	)
	if err != nil {
		return err
	}
	defer localehelper.DestroyLocaleHelper(lhelper)

	err = lhelper.GenerateLocale(locale)
	if err != nil {
		return err
	}

	var content = fmt.Sprintf("LANG=%s\nLANGUAGE=%s", locale,
		strings.Split(locale, ".")[0])
	return ioutil.WriteFile(defaultLocaleFile, []byte(content), 0644)
}
Exemple #2
0
func newLangSelector(l *log.Logger) *LangSelector {
	lang := LangSelector{LocaleState: LocaleStateChanged}

	if l != nil {
		lang.logger = l
	} else {
		lang.logger = log.NewLogger(dbusSender)
	}

	var err error
	lang.lhelper, err = localehelper.NewLocaleHelper(
		"com.deepin.api.LocaleHelper",
		"/com/deepin/api/LocaleHelper")
	if err != nil {
		lang.logger.Warning("New LocaleHelper Failed:", err)
		return nil
	}

	lang.setPropCurrentLocale(getLocale())

	return &lang
}