Files
Reims-Go/internal/i18n/detect_windows.go
T

28 lines
589 B
Go

//go:build windows
package i18n
import (
"syscall"
"unsafe"
)
var (
modKernel32 = syscall.NewLazyDLL("kernel32.dll")
procGetUserDefaultLocale = modKernel32.NewProc("GetUserDefaultLocaleName")
)
// detectOSLocale queries the current Windows user's UI/display locale (e.g. "zh-CN", "en-US").
func detectOSLocale() string {
// LOCALE_NAME_MAX_LENGTH is 85 UTF-16 code units.
buf := make([]uint16, 85)
r, _, _ := procGetUserDefaultLocale.Call(
uintptr(unsafe.Pointer(&buf[0])),
uintptr(len(buf)),
)
if r == 0 {
return ""
}
return syscall.UTF16ToString(buf)
}