如何在Go中获取计算机的当前语言?

How do I get the computer's current language in Go?

e.g. en-US for USA or es-es for Spain.

On *nix based systems you can simply use os.Getenv("LANG"), I'm not sure if that applies to windows.

//edit

@JimB mentioned that there are other variables to check too, for more details check gettext

on my system:

➜ locale
LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=

Note: Windows doesn't not rely on LANG environment variable (or LC_* variables: none are defined on my Windows 8)

The locale is stored in HKCU/ControlPanel/International/LocalName (as mentioned in this thread)

localname

So you are better off using a project accessing the registry, like: