Skip to content

Commit af93927

Browse files
authored
fix: GRUB menu entries appear in English after system upgrade (#201)
Supplement locale-related environment variables when calling the deepin-immutable-ctl command. Log: 修复系统语言为汉语时,GRUB 菜单项在系统升级后变为英语 pms: Bug-316123, Bug-323697
1 parent 7c15bce commit af93927

3 files changed

Lines changed: 22 additions & 5 deletions

File tree

src/lastore-daemon/common.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"github.com/linuxdeepin/lastore-daemon/src/internal/config"
2626
"github.com/linuxdeepin/lastore-daemon/src/internal/system"
2727
"github.com/linuxdeepin/lastore-daemon/src/internal/system/apt"
28+
"github.com/linuxdeepin/lastore-daemon/src/internal/utils"
2829

2930
"github.com/godbus/dbus/v5"
3031
"github.com/linuxdeepin/go-lib/dbusutil"
@@ -143,6 +144,24 @@ func getLang(envVars procfs.EnvVars) string {
143144
return ""
144145
}
145146

147+
var originalLocaleEnvs []string
148+
149+
// collectAndClearLocaleEnvs collects current locale environment variables,
150+
// clears them from the environment, and stores the original values for later use
151+
func collectAndClearLocaleEnvs() {
152+
originalLocaleEnvs = nil
153+
// Iterate over the list of environment variable names related to locale settings
154+
for _, localeEnvName := range []string{"LC_ALL", "LANGUAGE",
155+
"LC_MESSAGES", "LANG"} {
156+
localeEnvValue, exists := os.LookupEnv(localeEnvName)
157+
if exists {
158+
// Store the original locale environment variables for later use
159+
originalLocaleEnvs = append(originalLocaleEnvs, localeEnvName+"="+localeEnvValue)
160+
}
161+
_ = utils.UnsetEnv(localeEnvName)
162+
}
163+
}
164+
146165
func listPackageDesktopFiles(pkg string) []string {
147166
var result []string
148167
filenames := system.ListPackageFile(pkg)

src/lastore-daemon/immutable.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ func (i *immutableManager) osTreeCmd(args []string) (out string, err error) {
1616
args = append(args, "-v")
1717
cmd := exec.Command(DEEPIN_IMMUTABLE_CTL, args...) // #nosec G204
1818
cmd.Env = append(os.Environ(), "IMMUTABLE_DISABLE_REMOUNT=false")
19+
cmd.Env = append(cmd.Env, originalLocaleEnvs...)
1920
logger.Info("run command:", cmd.Args)
2021
var stdout, stderr bytes.Buffer
2122
cmd.Stdout = &stdout

src/lastore-daemon/main.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
. "github.com/linuxdeepin/lastore-daemon/src/internal/config"
1515
"github.com/linuxdeepin/lastore-daemon/src/internal/system"
1616
"github.com/linuxdeepin/lastore-daemon/src/internal/system/dut"
17-
"github.com/linuxdeepin/lastore-daemon/src/internal/utils"
1817

1918
"github.com/godbus/dbus/v5"
2019
"github.com/linuxdeepin/dde-api/inhibit_hint"
@@ -61,10 +60,8 @@ func main() {
6160
return
6261
}
6362

64-
_ = utils.UnsetEnv("LC_ALL")
65-
_ = utils.UnsetEnv("LANGUAGE")
66-
_ = utils.UnsetEnv("LC_MESSAGES")
67-
_ = utils.UnsetEnv("LANG")
63+
// Collect and clear locale environment variables
64+
collectAndClearLocaleEnvs()
6865

6966
gettext.InitI18n()
7067
gettext.Textdomain("lastore-daemon")

0 commit comments

Comments
 (0)