mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-30 09:23:50 +01:00
Locale: try detecting with locale command
in case $LC_* envs are not set ( macOS )
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
#include "common/properties.h"
|
||||
#include "common/printing.h"
|
||||
#include "common/caching.h"
|
||||
#include "common/processing.h"
|
||||
#include "common/parsing.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
@@ -21,6 +23,31 @@ static void getLocaleFromEnv(FFstrbuf* locale)
|
||||
ffStrbufAppendS(locale, getenv("LC_MESSAGES"));
|
||||
}
|
||||
|
||||
static void getLocaleFromCmd(FFstrbuf* locale)
|
||||
{
|
||||
FFstrbuf buffer;
|
||||
ffStrbufInitA(&buffer, 0);
|
||||
char* args[] = { "locale", NULL };
|
||||
if(ffProcessAppendStdOut(&buffer, args) == NULL)
|
||||
{
|
||||
ffParsePropLines(buffer.chars, "LANG=\"", locale);
|
||||
ffStrbufTrimRight(locale, '"');
|
||||
|
||||
if(locale->length == 0)
|
||||
{
|
||||
ffParsePropLines(buffer.chars, "LC_ALL=\"", locale);
|
||||
ffStrbufTrimRight(locale, '"');
|
||||
|
||||
if(locale->length == 0)
|
||||
{
|
||||
ffParsePropLines(buffer.chars, "LC_MESSAGES=\"", locale);
|
||||
ffStrbufTrimRight(locale, '"');
|
||||
}
|
||||
}
|
||||
}
|
||||
ffStrbufDestroy(&buffer);
|
||||
}
|
||||
|
||||
void ffPrintLocale(FFinstance* instance)
|
||||
{
|
||||
if(ffPrintFromCache(instance, FF_LOCALE_MODULE_NAME, &instance->config.locale, FF_LOCALE_NUM_FORMAT_ARGS))
|
||||
@@ -44,6 +71,11 @@ void ffPrintLocale(FFinstance* instance)
|
||||
getLocaleFromEnv(&locale);
|
||||
}
|
||||
|
||||
if(locale.length == 0)
|
||||
{
|
||||
getLocaleFromCmd(&locale);
|
||||
}
|
||||
|
||||
if(locale.length == 0)
|
||||
{
|
||||
ffPrintError(instance, FF_LOCALE_MODULE_NAME, 0, &instance->config.locale, "No locale found");
|
||||
|
||||
Reference in New Issue
Block a user