22#include "common/properties.h"
33#include "common/printing.h"
44#include "common/caching.h"
5+ #include "common/processing.h"
6+ #include "common/parsing.h"
57
68#include <stdlib.h>
79
@@ -21,6 +23,31 @@ static void getLocaleFromEnv(FFstrbuf* locale)
2123 ffStrbufAppendS (locale , getenv ("LC_MESSAGES" ));
2224}
2325
26+ static void getLocaleFromCmd (FFstrbuf * locale )
27+ {
28+ FFstrbuf buffer ;
29+ ffStrbufInitA (& buffer , 0 );
30+ char * args [] = { "locale" , NULL };
31+ if (ffProcessAppendStdOut (& buffer , args ) == NULL )
32+ {
33+ ffParsePropLines (buffer .chars , "LANG=\"" , locale );
34+ ffStrbufTrimRight (locale , '"' );
35+
36+ if (locale -> length == 0 )
37+ {
38+ ffParsePropLines (buffer .chars , "LC_ALL=\"" , locale );
39+ ffStrbufTrimRight (locale , '"' );
40+
41+ if (locale -> length == 0 )
42+ {
43+ ffParsePropLines (buffer .chars , "LC_MESSAGES=\"" , locale );
44+ ffStrbufTrimRight (locale , '"' );
45+ }
46+ }
47+ }
48+ ffStrbufDestroy (& buffer );
49+ }
50+
2451void ffPrintLocale (FFinstance * instance )
2552{
2653 if (ffPrintFromCache (instance , FF_LOCALE_MODULE_NAME , & instance -> config .locale , FF_LOCALE_NUM_FORMAT_ARGS ))
@@ -44,6 +71,11 @@ void ffPrintLocale(FFinstance* instance)
4471 getLocaleFromEnv (& locale );
4572 }
4673
74+ if (locale .length == 0 )
75+ {
76+ getLocaleFromCmd (& locale );
77+ }
78+
4779 if (locale .length == 0 )
4880 {
4981 ffPrintError (instance , FF_LOCALE_MODULE_NAME , 0 , & instance -> config .locale , "No locale found" );
0 commit comments