mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 10:52:08 +02:00
Locale: reports API failure messages
This commit is contained in:
@@ -2,4 +2,4 @@
|
||||
|
||||
#include "fastfetch.h"
|
||||
|
||||
void ffDetectLocale(FFstrbuf* result);
|
||||
const char* ffDetectLocale(FFstrbuf* result);
|
||||
|
||||
@@ -2,15 +2,19 @@
|
||||
|
||||
#include <locale.h>
|
||||
|
||||
void ffDetectLocale(FFstrbuf* result)
|
||||
const char* ffDetectLocale(FFstrbuf* result)
|
||||
{
|
||||
ffStrbufAppendS(result, getenv("LC_ALL"));
|
||||
if(result->length > 0)
|
||||
return;
|
||||
return NULL;
|
||||
|
||||
ffStrbufAppendS(result, getenv("LANG"));
|
||||
if(result->length > 0)
|
||||
return;
|
||||
return NULL;
|
||||
|
||||
ffStrbufAppendS(result, setlocale(LC_TIME, NULL));
|
||||
if(result->length > 0)
|
||||
return NULL;
|
||||
|
||||
return "Failed to detect locale";
|
||||
}
|
||||
|
||||
@@ -2,12 +2,15 @@
|
||||
#include "common/windows/unicode.h"
|
||||
|
||||
#include <windows.h>
|
||||
#include <locale.h>
|
||||
|
||||
void ffDetectLocale(FFstrbuf* result)
|
||||
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'
|
||||
ffStrbufSetNWS(result, (uint32_t)size - 1, name);
|
||||
if (size <= 1) // including '\0'
|
||||
return "GetUserDefaultLocaleName() failed";
|
||||
|
||||
ffStrbufSetNWS(result, (uint32_t)size - 1, name);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#include "common/printing.h"
|
||||
#include "common/jsonconfig.h"
|
||||
#include "common/stringUtils.h"
|
||||
#include "detection/locale/locale.h"
|
||||
#include "modules/locale/locale.h"
|
||||
|
||||
@@ -8,10 +7,10 @@ bool ffPrintLocale(FFLocaleOptions* options)
|
||||
{
|
||||
FF_STRBUF_AUTO_DESTROY locale = ffStrbufCreate();
|
||||
|
||||
ffDetectLocale(&locale);
|
||||
if(locale.length == 0)
|
||||
const char* error = ffDetectLocale(&locale);
|
||||
if(error)
|
||||
{
|
||||
ffPrintError(FF_LOCALE_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "No locale found");
|
||||
ffPrintError(FF_LOCALE_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -52,7 +51,14 @@ bool ffGenerateLocaleJsonResult(FF_MAYBE_UNUSED FFLocaleOptions* options, yyjson
|
||||
{
|
||||
FF_STRBUF_AUTO_DESTROY locale = ffStrbufCreate();
|
||||
|
||||
ffDetectLocale(&locale);
|
||||
const char* error = ffDetectLocale(&locale);
|
||||
|
||||
if(error)
|
||||
{
|
||||
yyjson_mut_obj_add_str(doc, module, "error", error);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(locale.length == 0)
|
||||
{
|
||||
yyjson_mut_obj_add_str(doc, module, "error", "No locale found");
|
||||
|
||||
Reference in New Issue
Block a user