How do I get the current computer language in Go?
2 answers
On * nix based systems you can just use os.Getenv("LANG")
, I'm not sure if this applies to windows.
//edit
@JimB mentioned there are other variables to check, check gettext for more details
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=
+1
source to share
Note: Windows doesn't rely on environment variableLANG
(or LC_*
variables: none are defined on my Windows 8)
The locale is stored in HKCU/ControlPanel/International/LocalName
(as mentioned in this thread )
So, you're better off using a project, registry access like:
+2
source to share