From 76424950e373d3b04ac3dd13019151bfba3e8423 Mon Sep 17 00:00:00 2001 From: sumuel Date: Mon, 17 Aug 2026 20:44:55 +0000 Subject: Add the files --- src/detection/locale/locale.h | 5 +++++ src/detection/locale/locale_linux.c | 22 ++++++++++++++++++++++ src/detection/locale/locale_windows.c | 16 ++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 src/detection/locale/locale.h create mode 100644 src/detection/locale/locale_linux.c create mode 100644 src/detection/locale/locale_windows.c (limited to 'src/detection/locale') diff --git a/src/detection/locale/locale.h b/src/detection/locale/locale.h new file mode 100644 index 0000000..50f0bad --- /dev/null +++ b/src/detection/locale/locale.h @@ -0,0 +1,5 @@ +#pragma once + +#include "fastfetch.h" + +const char* ffDetectLocale(FFstrbuf* result); diff --git a/src/detection/locale/locale_linux.c b/src/detection/locale/locale_linux.c new file mode 100644 index 0000000..4c04f26 --- /dev/null +++ b/src/detection/locale/locale_linux.c @@ -0,0 +1,22 @@ +#include "detection/locale/locale.h" + +#include + +const char* ffDetectLocale(FFstrbuf* result) { + ffStrbufAppendS(result, getenv("LC_ALL")); + if (result->length > 0) { + return NULL; + } + + ffStrbufAppendS(result, getenv("LANG")); + if (result->length > 0) { + return NULL; + } + + ffStrbufAppendS(result, setlocale(LC_TIME, NULL)); + if (result->length > 0) { + return NULL; + } + + return "Failed to detect locale"; +} diff --git a/src/detection/locale/locale_windows.c b/src/detection/locale/locale_windows.c new file mode 100644 index 0000000..b247365 --- /dev/null +++ b/src/detection/locale/locale_windows.c @@ -0,0 +1,16 @@ +#include "detection/locale/locale.h" +#include "common/windows/unicode.h" + +#include + +const char* ffDetectLocale(FFstrbuf* result) { + wchar_t name[LOCALE_NAME_MAX_LENGTH]; + int size = GetUserDefaultLocaleName(name, LOCALE_NAME_MAX_LENGTH); + if (size <= 1) { // including '\0' + return "GetUserDefaultLocaleName() failed"; + } + + ffStrbufSetNWS(result, (uint32_t) size - 1, name); + + return NULL; +} -- cgit v1.2.3