Why does os.LookupEnv("LANG") pick the wrong language?

	s, _ := os.LookupEnv("LANG")
	fmt.Println(s)

This gives en_US.UTF-8 which is far from my computer language setting. How can I get accurate computer default language?

For Posix, a convention seems to be to use any of these environment variables, so maybe check for some other ones:

  • LANGUAGE
  • LC_ALL
  • LC_MESSAGES, LC_NUMERIC, LC_TIME, LC_COLLATE, and others
  • LANG

(Source)

On Windows, I see LC_CTYPE=“en_US.UTF-8”, but there’s also a Windows API function to get that information: GetSystemDefaultUILanguage. I’m not sure if there’s an equivalent for other OSes

1 Like

It turned out that the terminal in VS Code deliver another result than the raw terminal. So VS Code is to blame in this case. I assumed that VS Code gives a correct result. A special thank you to @hollowaykeanho for enlighten me about this.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.