Is there a function for getting the user's system language I can't find it anywhere on the Go site.
To clarify my question i want the current user's system language that means when everything is for example dutch on the system i want to get "dutch" or "nl"
note: the program is made to run on linux, mac and windows
One of the main things that make Go compile fast is its dependency management. To say simply, Go imports only those packages that are directly required for the program other than C/C++ compilers. There are also no templates which amounts to less preprocessing overhead.
Golang was formerly written in C but is now written in Go itself. As of December 2013, the Go team announced their transitioning of the compiler to Go. Since February 2015 the implementation of C has been deleted and the compiler is now self-hosting, with the new compiler first introduced in Go 1.5.
What is Golang Useful for? Golang is useful for carrying out programming for scalable servers and large software systems. The Golang programming language was built to fill in the gaps of C++ and Java that Google came across while working with its servers and distributed systems.
Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.
There is a nice cross-platform library called
jibber_jabber
which looks up for $LC_ALL
or $LANG
env variables in Unix systems and, for Windows, loads Kernel32 and calls some procedures like GetUserDefaultLocaleName
or GetSystemDefaultLocaleName
inside.
For Windows, all is done in the
getWindowsLocale()
function.
Be advised that Kernel32 library comes built-in in Windows OS kernel.
By the way, should you need to convert locale-format'd language strings like en_US
and fr_FR
, you can utilize the
x/text/language and x/text/language/display
packages to get fully qualified name of the language.
lang := "ru_RU"
tag := language.MustParse(lang)
inEng := display.English.Languages()
inTur := display.Turkish.Languages()
inSelf := display.Self
fmt.Println(inEng.Name(tag))
fmt.Println(inSelf.Name(tag))
fmt.Println(inTur.Name(tag))
// Output:
// Russian
// русский
// Rusça
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With